Notebook - Welcome to Notebook

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












Simple vector matrix quaternion library for basic operations transforms Author Ben Kenwright b kenwright xbdev net function valid val if val undefined console log invalid value if isNaN val console log NaN value if val 9999999 console log number warning range if val 9999999 console log number warning range function vec3 x y z this x x this y y this z z valid this x valid this y valid this z return this vec3 prototype float32 function let r new Float32Array 3 r 0 this x r 1 this y r 2 this z return r vec3 add function v0 v1 return new vec3 v0 x v1 x v0 y v1 y v0 z v1 z vec3 sub function v0 v1 return new vec3 v0 x v1 x v0 y v1 y v0 z v1 z vec3 scale function v0 s return new vec3 v0 x s v0 y s v0 z s vec3 cross function v0 v1 return v0 x v1 y v0 y v1 x vec3 cross function v0 v1 return new vec3 v0 y v1 z v0 z v1 y v0 z v1 x v0 x v1 z v0 x v1 y v0 y v1 x vec3 dot function v0 v1 return v0 x v1 x v0 y v1 y v0 z v1 z note you can t use length word vec3 dist function v0 return Math sqrt v0 x v0 x v0 y v0 y v0 z v0 z vec3 norm function v0 let ln Math sqrt v0 x v0 x v0 y v0 y v0 z v0 z valid ln return vec3 scale v0 1 0 ln vec3 rotz function v theta let cs Math cos theta let sn Math sin theta return new vec3 v x cs v y sn v x sn v y cs v z vec3 lerp function a b t let ti 1 t let r new vec3 ti a x t b x ti a y t b y ti a z t b z return r function quat w x y z this x x valid x this y y valid y this z z valid z this w w valid w return this quat prototype float32 function let r new Float32Array 4 r 0 this x r 1 this y r 2 this z r 3 this w return r quat identity function return new quat 1 0 0 0 quat zero function return new quat 0 0 0 0 quat scale function q s return new quat q w s q x s q y s q z s quat conj function q return new quat q w q x q y q z quat dot function v0 v1 return v0 w v1 w v0 x v1 x v0 y v1 y v0 z v1 z quat add function a b return new quat a w b w a x b x a y b y a z b z quat norm function q let ln Math sqrt q w q w q x q x q y q y q z q z valid ln return quat scale q 1 0 ln quat mul function a b return new quat a w b w a x b x a y b y a z b z a w b x a x b w a y b z a z b y a w b y a y b w a z b x a x b z a w b z a z b w a x b y a y b x quat lerp function a b t let r quat identity let ti 1 t r w ti a w t b w r x ti a x t b x r y ti a y t b y r z ti a z t b z r quat norm r return r quat slerp function a b t let ti 1 t let theta Math acos a x b x a y b y a z b z a w b w let sn Math sin theta let Wa Math sin ti theta sn let Wb Math sin t theta sn let ret new quat Wa a w Wb b w Wa a x Wb b x Wa a y Wb b y Wa a z Wb b z ret quat norm ret return ret quat getAxisAngle function q let angle 2 Math acos q w let vec new vec3 0 0 0 let d Math sqrt 1 q w q w if d 0 0 vec new vec3 q x d q y d q z d return vec angle quat fromAxisAngle function v a return new quat Math cos a 2 v x Math sin a 2 v y Math sin a 2 v z Math sin a 2 quat fromVecW function v w return new quat w v x v y v z function mat4 this m 16 for var i 0 i arguments length i this m i arguments i valid this m i return this mat4 prototype float32 function let r new Float32Array 16 for let i 0 i 16 i r i this m i return r mat4 identity function return new mat4 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 mat4 scale function s return new mat4 s x 0 0 0 0 s y 0 0 0 0 s x 0 0 0 0 1 mat4 zero function return new mat4 new Array 16 fill 0 mat4 clone function m let res new mat4 m m return res mat4 translate function v return new mat4 1 0 0 0 0 1 0 0 0 0 1 0 v x v y v z 1 mat4 transform function m v let res new vec3 0 0 0 let w m m 3 v x m m 7 v y m m 11 v z m m 15 w w 1 0 res x m m 0 v x m m 4 v y m m 8 v z m m 12 w res y m m 1 v x m m 5 v y m m 9 v z m m 13 w res z m m 2 v x m m 6 v y m m 10 v z m m 14 w return res mat4 fromAxisAngle function v a let s Math sin a let c Math cos a let x v x let y v y let z v z return new mat4 x x 1 c c x y 1 c z s x z 1 c y s 0 y x 1 c z s y y 1 c c y z 1 c x s 0 x z 1 c y s y z 1 c x s z z 1 c c 0 0 0 0 1 mat4 mult function a b var a11 a m 0 var a12 a m 1 var a13 a m 2 var a14 a m 3 var a21 a m 4 var a22 a m 5 var a23 a m 6 var a24 a m 7 var a31 a m 8 var a32 a m 9 var a33 a m 10 var a34 a m 11 var a41 a m 12 var a42 a m 13 var a43 a m 14 var a44 a m 15 var b11 b m 0 var b12 b m 1 var b13 b m 2 var b14 b m 3 var b21 b m 4 var b22 b m 5 var b23 b m 6 var b24 b m 7 var b31 b m 8 var b32 b m 9 var b33 b m 10 var b34 b m 11 var b41 b m 12 var b42 b m 13 var b43 b m 14 var b44 b m 15 let res mat4 zero res m 0 a11 b11 a12 b21 a13 b31 a14 b41 res m 1 a11 b12 a12 b22 a13 b32 a14 b42 res m 2 a11 b13 a12 b23 a13 b33 a14 b43 res m 3 a11 b14 a12 b24 a13 b34 a14 b44 res m 4 a21 b11 a22 b21 a23 b31 a24 b41 res m 5 a21 b12 a22 b22 a23 b32 a24 b42 res m 6 a21 b13 a22 b23 a23 b33 a24 b43 res m 7 a21 b14 a22 b24 a23 b34 a24 b44 res m 8 a31 b11 a32 b21 a33 b31 a34 b41 res m 9 a31 b12 a32 b22 a33 b32 a34 b42 res m 10 a31 b13 a32 b23 a33 b33 a34 b43 res m 11 a31 b14 a32 b24 a33 b34 a34 b44 res m 12 a41 b11 a42 b21 a43 b31 a44 b41 res m 13 a41 b12 a42 b22 a43 b32 a44 b42 res m 14 a41 b13 a42 b23 a43 b33 a44 b43 res m 15 a41 b14 a42 b24 a43 b34 a44 b44 return res Testing let v new vec3 1 2 3 console log v v let q new quat 1 2 3 4 console log q q let m mat4 identity console log m m m v new vec3 0 5 0 m mat4 fromAxisAngle new vec3 0 0 1 Math PI let res mat4 transform m v console log res v new vec3 0 5 0 m mat4 translate new vec3 3 7 9 res mat4 transform m v console log res let b mat4 clone m console log b console log float32 v float32 console log mat4 zero console log mat4 identity console log ready script src https notebook xbdev net var scripts vector0 8 js script script console log typeof vec3 console log new vec3 1 2 3 script

function mat4 this m 16 for var i 0 i arguments length i this m i arguments i valid this m i return this mat4 prototype float32 function let r new Float32Array 16 for let i 0 i 16 i r i this m i return r mat4 identity function return new mat4 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 mat4 scale function s return new mat4 s x 0 0 0 0 s y 0 0 0 0 s x 0 0 0 0 1 mat4 zero function return new mat4 new Array 16 fill 0 mat4 clone function m let res new mat4 m m return res mat4 translate function v return new mat4 1 0 0 0 0 1 0 0 0 0 1 0 v x v y v z 1 mat4 transform function m v let res new vec3 0 0 0 let w m m 3 v x m m 7 v y m m 11 v z m m 15 w w 1 0 res x m m 0 v x m m 4 v y m m 8 v z m m 12 w res y m m 1 v x m m 5 v y m m 9 v z m m 13 w res z m m 2 v x m m 6 v y m m 10 v z m m 14 w return res mat4 fromAxisAngle function v a let s Math sin a let c Math cos a let x v x let y v y let z v z return new mat4 x x 1 c c x y 1 c z s x z 1 c y s 0 y x 1 c z s y y 1 c c y z 1 c x s 0 x z 1 c y s y z 1 c x s z z 1 c c 0 0 0 0 1 mat4 mult function a b var a11 a m 0 var a12 a m 1 var a13 a m 2 var a14 a m 3 var a21 a m 4 var a22 a m 5 var a23 a m 6 var a24 a m 7 var a31 a m 8 var a32 a m 9 var a33 a m 10 var a34 a m 11 var a41 a m 12 var a42 a m 13 var a43 a m 14 var a44 a m 15 var b11 b m 0 var b12 b m 1 var b13 b m 2 var b14 b m 3 var b21 b m 4 var b22 b m 5 var b23 b m 6 var b24 b m 7 var b31 b m 8 var b32 b m 9 var b33 b m 10 var b34 b m 11 var b41 b m 12 var b42 b m 13 var b43 b m 14 var b44 b m 15 let res mat4 zero res m 0 a11 b11 a12 b21 a13 b31 a14 b41 res m 1 a11 b12 a12 b22 a13 b32 a14 b42 res m 2 a11 b13 a12 b23 a13 b33 a14 b43 res m 3 a11 b14 a12 b24 a13 b34 a14 b44 res m 4 a21 b11 a22 b21 a23 b31 a24 b41 res m 5 a21 b12 a22 b22 a23 b32 a24 b42 res m 6 a21 b13 a22 b23 a23 b33 a24 b43 res m 7 a21 b14 a22 b24 a23 b34 a24 b44 res m 8 a31 b11 a32 b21 a33 b31 a34 b41 res m 9 a31 b12 a32 b22 a33 b32 a34 b42 res m 10 a31 b13 a32 b23 a33 b33 a34 b43 res m 11 a31 b14 a32 b24 a33 b34 a34 b44 res m 12 a41 b11 a42 b21 a43 b31 a44 b41 res m 13 a41 b12 a42 b22 a43 b32 a44 b42 res m 14 a41 b13 a42 b23 a43 b33 a44 b43 res m 15 a41 b14 a42 b24 a43 b34 a44 b44 return res Testing let v new vec3 1 2 3 console log v v let q new quat 1 2 3 4 console log q q let m mat4 identity console log m m m v new vec3 0 5 0 m mat4 fromAxisAngle new vec3 0 0 1 Math PI let res mat4 transform m v console log res v new vec3 0 5 0 m mat4 translate new vec3 3 7 9 res mat4 transform m v console log res let b mat4 clone m console log b console log float32 v float32 console log mat4 zero console log mat4 identity console log ready script src https notebook xbdev net var scripts vector0 8 js script script console log typeof vec3 console log new vec3 1 2 3 script

3dplot
a4print
about
acejs
acejs2
acejs3
aessecurity
angularjs
animbackgroundimage
aseformat
assert
asteroidsjs
backgrounds01
backgrounds02
backgrounds03
barnsleyfern
base26
base64
bib
binary
bodypix
bouncy
box2dweb
breakoutjs
browserversion
buslanes
busybutton
bvhreader
calendar
canvas
canvas2
canvas3
canvasmandelbrot
canvasmandelbrot2
canvasnumbers
canvaszoom
capsule
changingimages
chatgptusingopenai
chatgptusingopenai2
chatgptusingopenai3
checkboxtoggle
chinesetiles
classes
classfeatures
clipboardbutton
clonenode
codedropdown
codemirror
codemirror2
collada
colorpick
columnresizer
contextmenu
convnet
cookiebanner
countdown
countdown2
countdown3
crop
css3dbarchart
css3dbarchart2
css3dbook
css3dscene
csscube
csscube2
csscube3
csscubevideos
cssfilelist
csshas
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
dragdroplistitems
dragrotateresizediv
dragrotateresizediv2
dragrotateresizediv3
dragrotateresizediv4
dragrotateresizefontsize
dragselectbrush
drawlinesdiv
dropdown
dualquaternionimages
dynamicgrid
easefunctions
easeinterpolate3dplots
echart
echart2
echart3
encapsulation
epubviewer
errorstack
excalidraw
excalidraw2
excalidraw3
excalidraw5
expandable
faker
fetchplus
fileupload
fixedtopbar
fonts
fonts2
footerbar
fractalmaze
fractalmaze2
fractalnoiseimage
fractals
fractals2
fractaltree
freesvg
fresnel
froggerjs
gantt
gifgiphyapi
gifhex
gltffromscratch
gradients
griditems
griditems2
griditems3
griditems4
gridworms
heat
hexview
hexview2
highlight
icons
icons2
iframes
ik
imagetracertosvg
imgur
inputfile
invadersjs
ipynb
ipynb2
ipynb3
ipynb4
isbn13
isbn2
jpghex
jquery
jquery2
jqueryui
jqueryui2
jsdraganddrop
jslint
jsobfuscate
jsraytracer
jstree
jstree2
jszip
jszipimages
jszipread
keyframes
l2dwidget
lda
leftmenu
less
less2
lineargradientimage
linenumbers
loadimagefromfile
makepdf
maps
markdown
markdown2
markdownalerts
markdownalerts2
markdownbookmarks
markovimage
markovpixelblocks
mathjax
matrices
matsandvects
mazegamejs
md2tex
metrotiles
metrowindows
milestones
misc
misc2
modules
myipdetails
neataptic
networkstructures
networkstructures2
number
obj
objtojson
openaiimages
opencv
opencv2
opencv3
opencv4
opencv5
outline
p2
p5fractalleaf
p5fractalshape
p5js
p5js2
p5js3
p5jsanimatedcover
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
plyloader
plyloader2
pngtxtencoder
pongjs
pptxgenjs
prettycode
prism
prn
problems
progress
pseudorandom
px2svg
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
sankey
scrappingsvg
scrolltext
scrolltext2
scrollwidth
sdfboxinboxtwist
sdfhollowbox
setintervalexception
shareurl
shuffle
sidecomment
similarity
simplehighlighter
simpleplatformgamejs
sinecanvas
sliderpopout
slides
smileys
snowfall
snowman
sound
soundsignal
sphererayintersection
springs
sqljs
steganography
stereogram
stringmatching
svg
svgchaos
svgdragresize
svgdragresize2
svgdragresize3
svgdragrotate
svgdrawing
svglines
svglines2
svglines3
svglines4
svglines5
svglinesmandelbrot
svgpathsdragrotate
svgpathsdragrotateresize
svgpie
svgpie2
svgpie3
svgpiepath
svgpiepath2
svgrandomfaces
symbols
synaptic
synaptic2
synonyms
tablerotatecells
tablerotatecells2
tablerotatecells3
tablerotatecells3b
tablerotatecells4
tables
tablezebra
tabularjs
tabularjs2
tabulatordownload
tagcanvas
tensorflowgan
tensorflowjs
tensorflowjsbasic
tensorflowjscnn
tensorflowjssinewave
tensorflowjssound
tensorflowmobilenet
tetrahedronfractal
tetrahedronfractalfolding
tetris
textarea
textareaauto
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
urlblob2
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