Created
January 9, 2020 23:32
-
-
Save RH2/b857bcf3697875a99df7d48434ac7a89 to your computer and use it in GitHub Desktop.
rotate points
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
matrixA = [[3,2,1],[5,8,3],[2,4,7]] | |
matrixB = [[3,2,1],[5,8,3],[2,4,7]] | |
box = {x:3,y:4} | |
initialangle= Math.atan2(box.y,box.x) | |
function findh(x,y){return(Math.sqrt(Math.pow(x/2,2)+Math.pow(y/2,2)))} | |
function radtodeg(input){return((input/(Math.PI*2))*360)} | |
function degtorad(input){return((input/180)*Math.PI)} | |
angle = degtorad(30) | |
matrixRotateX = [[1,0,0],[0,Math.cos(angle),-Math.sin(angle)],[0,Math.sin(angle),Math.cos(angle)]] | |
matrixRotateY = [[Math.cos(angle),0,Math.sin(angle)],[0,1,0],[-Math.sin(angle),0,Math.cos(angle)]] | |
matrixRotateZ = [[Math.cos(angle),-Math.sin(angle),0],[Math.sin(angle),Math.cos(angle),0],[0,0,1]] | |
function createRotationX(angle){ | |
return [[1,0,0],[0,Math.cos(angle),-Math.sin(angle)],[0,Math.sin(angle),Math.cos(angle)]] | |
} | |
function createRotationY(angle){ | |
return [[Math.cos(angle),0,Math.sin(angle)],[0,1,0],[-Math.sin(angle),0,Math.cos(angle)]] | |
} | |
function createRotationZ(angle){ | |
return [[Math.cos(angle),-Math.sin(angle),0],[Math.sin(angle),Math.cos(angle),0],[0,0,1]] | |
} | |
function sumMatrix(mA,mB){ | |
result = []; | |
result = new Array(mA.length) | |
for (var i = 0; i < result.length; i++) { | |
result[i] = new Array(mA[i].length) | |
for (var j = 0; j < result[i].length; j++) { | |
result[i][j]= mA[i][j]+mB[i][j] | |
} | |
} | |
return(result) | |
} | |
function multiplyMatrix(mA,mB){ | |
var result = new Array(mA.length) | |
for (var i = 0; i < result.length; i++) { | |
result[i]=new Array(mB[i].length) | |
for(var j = 0; j<mA.length;j++){ | |
result[i][j] = 0 | |
for(var k = 0; k< mB.length; k++){ | |
result[i][j] += mA[i][k] * mB[k][j] | |
} | |
} | |
} | |
return result | |
} | |
function toColumn(mA){ | |
return([[mA[0],mA[1],mA[2]]]) | |
} | |
function computeRotation(tuple,mat){ | |
cx=tuple[0] | |
cy=tuple[1] | |
cz=tuple[2] | |
cxresult= cx*mat[0][0] + cx*mat[0][1] + cx*mat[0][2] | |
cyresult= cy*mat[1][0] + cy*mat[1][1] + cy*mat[1][2] | |
czresult= cz*mat[2][0] + cz*mat[2][1] + cz*mat[2][2] | |
return([cxresult,cyresult,czresult]) | |
} | |
function createbox(x,y,z){//creates box with dimensions, centered over the origin. | |
return( | |
{points: | |
[ | |
[x/2,y/2,z/2], | |
[x/2,y/2,-z/2], | |
[x/2,-y/2,z/2], | |
[x/2,-y/2,-z/2], | |
[-x/2,y/2,z/2], | |
[-x/2,y/2,-z/2], | |
[-x/2,-y/2,z/2], | |
[-x/2,-y/2,-z/2] | |
] | |
} | |
) | |
} | |
function rotate(box,rx,ry,rz){ | |
//rotate xy axis | |
//rotate xz axis | |
//rotate yz axis | |
} | |
function axisalignedboundingbox(){ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment