Notebook - Welcome to Notebook

Contact/Report Bugs
You can contact me at: bkenwright@xbdev.net












Ray Sphere Intersection Kenwright img style outline 0 box shadow none border 0 margin 0 padding 0 src https notebook xbdev net var images imgqrZhGY3enLBl jpg img document body style min height 300px let ww 300 let wh 300 let svg document createElementNS http www w3 org 2000 svg svg svg setAttributeNS null width ww svg setAttributeNS null height wh svg setAttributeNS null fill currentColor svg style border 1px solid blue document body appendChild svg function addCircle c r id col green var newCircle document createElementNS http www w3 org 2000 svg circle newCircle id id newCircle setAttribute cx c x newCircle setAttribute cy c y newCircle setAttribute r r newCircle setAttribute fill transparent newCircle setAttribute stroke width 2 newCircle setAttribute stroke col svg appendChild newCircle addCircle x 200 y 100 50 c0 let shapes shapes push c x 160 y 110 r 50 id c0 type circle shapes forEach s addCircle s c s r s id function setLine id s e opt let i0 document getElementById id if i0 null i0 document createElementNS http www w3 org 2000 svg line i0 id id var randomColor Math random 0xFFFFFF 0 toString 16 let rbyte return Math floor Math random 256 256 let randomColor rgb rbyte rbyte rbyte i0 setAttribute stroke randomColor svg appendChild i0 i0 setAttribute x1 s x i0 setAttribute y1 s y i0 setAttribute x2 e x i0 setAttribute y2 e y if typeof opt undefined Object entries opt forEach o const k v o i0 setAttribute k v function sub a b return x a x b x y a y b y function add a b return x a x b x y a y b y function dist a b return Math sqrt a x b x a x b x a y b y a y b y function norm a let d Math sqrt a x a x a y a y return x a x d y a y d function len a return Math sqrt a x a x a y a y function scale a s return x a x s y a y s function dot a b return a x b x a y b y function lineIntersectCircle line circle const s line s const e line e const r circle r const c circle c let tsc len sub s c let tec len sub e c if tsc r tec r inside sphere console log both s and e inside sphere return hit false let inside false if tec r inside true let d0 dist line s circle c let d1 dist line e circle c let d0inside d0 circle r let d1inside d1 circle r let nse norm sub e s let vsc sub c s let to dot nse vsc let th len vsc let ta Math sqrt th th to to if ta r missed sphere console log ray misses sphere return hit false let tpa Math sqrt r r ta ta let t to tpa if tsc r start inside the sphere t to tpa let tse len sub e s if t 0 t tse greater than length of line return hit false let p add s scale nse t let n norm sub p c return hit true normal n hitpoint p pen tse t dir nse inside inside id l0 s x 253 y 148 e x 338 y 160 let line id l0 s x 253 y 148 e x 338 y 160 setLine line id line s line e let res lineIntersectCircle line shapes 0 if res hit console log hit addCircle res hitpoint 5 c2 black console log ready document body style min height 300px let ww 300 let wh 300 let svg document createElementNS http www w3 org 2000 svg svg svg setAttributeNS null width ww svg setAttributeNS null height wh svg setAttributeNS null fill currentColor svg style border 1px solid blue document body appendChild svg function addCircle c r id col green let newCircle document getElementById id if newCircle null newCircle document createElementNS http www w3 org 2000 svg circle newCircle id id svg appendChild newCircle newCircle setAttribute cx c x newCircle setAttribute cy c y newCircle setAttribute r r newCircle setAttribute fill transparent newCircle setAttribute stroke width 2 newCircle setAttribute stroke col addCircle x 200 y 100 50 c0 let shapes shapes push c x 160 y 110 r 50 id c0 type circle shapes forEach s addCircle s c s r s id function setLine id s e opt let i0 document getElementById id if i0 null i0 document createElementNS http www w3 org 2000 svg line i0 id id var randomColor Math random 0xFFFFFF 0 toString 16 let rbyte return Math floor Math random 256 256 let randomColor rgb rbyte rbyte rbyte i0 setAttribute stroke randomColor svg appendChild i0 i0 setAttribute x1 s x i0 setAttribute y1 s y i0 setAttribute x2 e x i0 setAttribute y2 e y if typeof opt undefined Object entries opt forEach o const k v o i0 setAttribute k v function sub a b return x a x b x y a y b y function add a b return x a x b x y a y b y function dist a b return Math sqrt a x b x a x b x a y b y a y b y function norm a let d Math sqrt a x a x a y a y return x a x d y a y d function len a return Math sqrt a x a x a y a y function scale a s return x a x s y a y s function dot a b return a x b x a y b y function lineIntersectCircle line circle const s line s const e line e const r circle r const c circle c let tsc len sub s c let tec len sub e c if tsc r tec r inside sphere console log both s and e inside sphere return hit false let inside false if tec r inside true let d0 dist line s circle c let d1 dist line e circle c let d0inside d0 circle r let d1inside d1 circle r let nse norm sub e s let vsc sub c s let to dot nse vsc let th len vsc let ta Math sqrt th th to to if ta r missed sphere console log ray misses sphere return hit false let tpa Math sqrt r r ta ta let t to tpa if tsc r start inside the sphere t to tpa let tse len sub e s if t 0 t tse greater than length of line return hit false let p add s scale nse t let n norm sub p c return hit true normal n hitpoint p pen tse t dir nse inside inside let line id l0 s x 20 y 100 e x 200 y 100 setLine line id line s line e function check setLine line id line s line e let res lineIntersectCircle line shapes 0 if res hit console log line addCircle res hitpoint 5 c2 black else addCircle x 1000 y 1000 5 c2 black check onmousemove e let mp x e clientX y e clientY line e mp check onclick e let mp x e clientX y e clientY line s mp line e add mp x 10 y 10 check console log ready

00 svg svg svg setAttributeNS null width ww svg setAttributeNS null height wh svg setAttributeNS null fill currentColor svg style border 1px solid blue document body appendChild svg function addCircle c r id col green let newCircle document getElementById id if newCircle null newCircle document createElementNS http www w3 org 2000 svg circle newCircle id id svg appendChild newCircle newCircle setAttribute cx c x newCircle setAttribute cy c y newCircle setAttribute r r newCircle setAttribute fill transparent newCircle setAttribute stroke width 2 newCircle setAttribute stroke col addCircle x 200 y 100 50 c0 let shapes shapes push c x 160 y 110 r 50 id c0 type circle shapes forEach s addCircle s c s r s id function setLine id s e opt let i0 document getElementById id if i0 null i0 document createElementNS http www w3 org 2000 svg line i0 id id var randomColor Math random 0xFFFFFF 0 toString 16 let rbyte return Math floor Math random 256 256 let randomColor rgb rbyte rbyte rbyte i0 setAttribute stroke randomColor svg appendChild i0 i0 setAttribute x1 s x i0 setAttribute y1 s y i0 setAttribute x2 e x i0 setAttribute y2 e y if typeof opt undefined Object entries opt forEach o const k v o i0 setAttribute k v function sub a b return x a x b x y a y b y function add a b return x a x b x y a y b y function dist a b return Math sqrt a x b x a x b x a y b y a y b y function norm a let d Math sqrt a x a x a y a y return x a x d y a y d function len a return Math sqrt a x a x a y a y function scale a s return x a x s y a y s function dot a b return a x b x a y b y function lineIntersectCircle line circle const s line s const e line e const r circle r const c circle c let tsc len sub s c let tec len sub e c if tsc r tec r inside sphere console log both s and e inside sphere return hit false let inside false if tec r inside true let d0 dist line s circle c let d1 dist line e circle c let d0inside d0 circle r let d1inside d1 circle r let nse norm sub e s let vsc sub c s let to dot nse vsc let th len vsc let ta Math sqrt th th to to if ta r missed sphere console log ray misses sphere return hit false let tpa Math sqrt r r ta ta let t to tpa if tsc r start inside the sphere t to tpa let tse len sub e s if t 0 t tse greater than length of line return hit false let p add s scale nse t let n norm sub p c return hit true normal n hitpoint p pen tse t dir nse inside inside let line id l0 s x 20 y 100 e x 200 y 100 setLine line id line s line e function check setLine line id line s line e let res lineIntersectCircle line shapes 0 if res hit console log line addCircle res hitpoint 5 c2 black else addCircle x 1000 y 1000 5 c2 black check onmousemove e let mp x e clientX y e clientY line e mp check onclick e let mp x e clientX y e clientY line s mp line e add mp x 10 y 10 check console log ready

3dplot
a4print
about
acejs
acejs2
acejs3
aessecurity
angularjs
assert
backgrounds01
backgrounds02
backgrounds03
base26
base64
bib
binary
bodypix
bouncy
box2dweb
browserversion
buslanes
bvhreader
calendar
canvas
canvas2
canvas3
canvasmandelbrot
canvasmandelbrot2
canvaszoom
capsule
changingimages
checkboxtoggle
chinesetiles
classes
classfeatures
clonenode
codemirror
collada
colorpick
columnresizer
contextmenu
convnet
cookiebanner
countdown
countdown2
countdown3
crop
css3dbarchart
css3dbarchart2
css3dbook
css3dscene
csscube
csscube2
csscube3
csscubevideos
cssfilelist
csspulse
cssresizeaspect
cssspin
csszooming
csvtoarray
customcheckbox
d3datamap
d3js
d3js10
d3js11
d3js2
d3js3
d3js4
d3js5
d3js6
d3js7
d3js8
d3js9
d3jsanimatedgrid
d3jsarctransition
d3jsarctransition2
d3jsaxis
d3jsaxischanging
d3jsbars
d3jsbrushing
d3jsbuslanes
d3jsbuslanes2
d3jscalendar
d3jscheat
d3jsclock
d3jscloudmap
d3jscogs
d3jscolors
d3jscovid
d3jscovid2
d3jscovid3
d3jsdashboard
d3jsdashboard2
d3jsdashboard3
d3jsdatakeyfunction
d3jsdensity
d3jsdragresizing
d3jsdragresizing2
d3jseach
d3jsease
d3jsevents
d3jsflower
d3jsforcegroups
d3jsforces
d3jsforces2
d3jsfractaltree
d3jsgeo
d3jsgroupbars
d3jsgroups
d3jsheatmap
d3jshex
d3jshierarchies
d3jshierarchies2
d3jshistogram
d3jshistogram2
d3jshistogram3
d3jshistogram4
d3jsinterpolate
d3jsjoin
d3jskmean
d3jskmean2
d3jsline
d3jsline2
d3jsline3
d3jsline4
d3jslinetransition
d3jslinetransition0
d3jslinetransition2
d3jsmaplocations
d3jsmaps
d3jsmaps2
d3jsmaps3
d3jsmisc
d3jsmisc2
d3jsmodule
d3jsmodulecolor
d3jsmultistyles
d3jsnobel
d3jsoverlappinggraphs
d3jspanel
d3jspie
d3jspieinterpolate
d3jssankey
d3jssankey2
d3jsscatter
d3jsshapes
d3jsslider
d3jsspending
d3jsspending2
d3jsspiralplot
d3jsspirograph
d3jssquare
d3jsstack
d3jsstackedbar
d3jsstackedbar2
d3jssunburst
d3jssunmoon
d3jssvglines
d3jssymbols
d3jstimelines
d3jsuk
d3jsvoronoi
d3scatterplot
d3timeline
d3timeline2
datalist
datamuse
date
dblclickhighlight
deviceorientation
dictionaryapi
dockermenu
doodlepad
downloadgif
dragrotateresizediv
dragrotateresizediv2
dragrotateresizediv3
dragrotateresizediv4
dragselectbrush
drawlinesdiv
dropdown
dynamicgrid
easefunctions
easeinterpolate3dplots
echart
echart2
echart3
encapsulation
epubviewer
errorstack
expandable
faker
fetchplus
fileupload
fixedtopbar
fonts
fonts2
footerbar
fractals
fractals2
fractaltree
freesvg
fresnel
gantt
gifgiphyapi
gltffromscratch
gradients
griditems
griditems2
griditems3
griditems4
gridworms
heat
highlight
icons
icons2
iframes
ik
imagetracertosvg
imgur
inputfile
isbn13
isbn2
jquery
jqueryui
jqueryui2
jsdraganddrop
jslint
jsobfuscate
jsraytracer
jszip
jszipimages
jszipread
keyframes
l2dwidget
lda
leftmenu
less
lineargradientimage
linenumbers
loadimagefromfile
makepdf
maps
markdown
markdown2
markdownalerts
markdownalerts2
markdownbookmarks
mathjax
matrices
matsandvects
md2tex
metrotiles
metrowindows
milestones
misc
misc2
modules
myipdetails
neataptic
number
obj
objtojson
opencv
opencv2
opencv3
opencv4
opencv5
outline
p2
p5fractalleaf
p5fractalshape
p5js
p5js2
p5js3
p5mengercube
p5snowflakes
palindrome
panel
parallax
paste
paste2
pasteimgfromurl
pdfjs
pdfjs2
pdfkit
pdfkit2
pdfkit3
pdfkit4
pdfkit5
pdfkit6
pdfmake
pdfmake2
pdfmake3
pdfmake4
pdfmake5
pdfmake6
perlin
perlin2
perlin3
perspective
pexels
playground
plotly
plotlynoise
plotlyranddist
pngtxtencoder
pptxgenjs
prism
prn
problems
progress
python
quotes
racergame
random
randomprofilepatterns
randomstring
rating
rayambient
raymonte
raymonteprogressive
raymonteprogressive2
raymontewarmstart
reexpcross
reexpcross2
regex
regexbib
regexpfixbib
regexpmultiline
repeatwordsregexp
resizabletable
resizabletable2
revealjs
revealjs2
revealjsmulti
ritalanguage
ritalanguage2
ritalanguage3
rotateimg
rough
rsapublicprivatekeys
rss
rss2
scrappingsvg
scrolltext
scrolltext2
scrollwidth
setintervalexception
shareurl
shuffle
sidecomment
similarity
sinecanvas
sliderpopout
slides
smileys
snowman
sound
soundsignal
sphererayintersection
springs
sqljs
steganography
stringmatching
svg
svgdragresize
svgdragresize2
svgdragresize3
svgdragrotate
svgdrawing
svglines
svglines2
svglines3
svglines4
svglines5
svglinesmandelbrot
svgpathsdragrotate
svgpathsdragrotateresize
svgpie
svgpie2
svgpie3
svgpiepath
svgpiepath2
symbols
synaptic
synaptic2
synonyms
tablerotatecells
tablerotatecells2
tablerotatecells3
tablerotatecells3b
tablerotatecells4
tables
tablezebra
tagcanvas
tetris
textarea
textareadiv
textareadiv2
textmaskimage
theirorthere
thesaurus
threejs
threejs2
threejs3
threejs4
threejsgltf
threejstokyo
tiles
toaster
tooltip
transition
transitionexpandabledropdown
treeview
treeview2
tricks
tshirt
tshirt2
tshirt3
turningpages
unsplash
urlblob
userdefinepoints
vector
videos
videos2
visualsort
vue
w2ui
w2uientertextdialog
webcam
webgl
webgl2
webgl3
webgl4
webgl5
webglbasic1
webglbasic2
webglcube
webglfov
webglfrustum
webgljson
webglleaves
webgllighting
webglorthographic
webglpoints1
webglpoints2
webglpoints3
webglsquare
webgltexture1
webgltexture2
webgltexture3
webgltransforms
webgltriangle
webgpu
webgpu10
webgpu11
webgpu12
webgpu13
webgpu14
webgpu15
webgpu16
webgpu17
webgpu2
webgpu3
webgpu4
webgpu5
webgpu6
webgpu7
webgpu8
webgpu9
webgpubars
webgpubuffers
webgpubuffers2
webgpucellnoise
webgpuclouds
webgpuclydescope
webgpucompute
webgpucubemap
webgpucubemap2
webgpudeferred
webgpudepth
webgpudof
webgpudrops
webgpuetha
webgpufire
webgpufractalcubes
webgpuglassrain
webgpugltf
webgpugltf2
webgpugrass
webgpugrid
webgpukernel
webgpukleinian
webgpulabupdates
webgpulighting
webgpumandelbrot
webgpumeta3d
webgpumetaballs
webgpumouse
webgpunoise
webgpunormalmapping
webgpuobj
webgpuparallax
webgpuparallax2
webgpuparallax3
webgpuparallaxshadow
webgpuparallaxshadow2
webgpupixel
webgpuquad
webgpuray1
webgpuraytracing
webgpuraytracing2
webgpushadowmaps
webgpushadowmaps2
webgpusierpinski2d
webgpusierpinski3d
webgpusinusoid
webgpussao
webgpustadiumobj
webgpuswirl
webgputestpipe3
webgputoon
webgputopology
webgputt
webgpuvolcloud
webgpuwater
webgpuwireframe
webgpuwireframe2
webpcanvas
webworkers
webxr
webxr2
wiggly
wikipedia