I have coordinates for 4 vertices/points that define a plane and the normal/perpendicular. The plane has an arbitrary rotation applied to it.
How can I 'un-rotate'/translate the points so that the plane has rotation 0 on x,y,z ?
I'm using atan2 on the normal's coordinates to get the rotations. Is this the right way to do it.
Also, I tried to rotate a matrix based on those angles and multiply it to the vertices, but I don't
think I'm doing it right. Any help ?
If I've got something like this:
How do I move the vertices to get something like this:
At the moment I wrote this:
I'm using atan2 on the normal's coordinates to get the rotations. Is this the right way to do it.
Also, I tried to rotate a matrix based on those angles and multiply it to the vertices, but I don't
think I'm doing it right. Any help ?
If I've got something like this:
How do I move the vertices to get something like this:
At the moment I wrote this:
float s = 50.0f;//scale/unit
PVector[] face = {new PVector(1.08335042,0.351914703846,0.839020013809),
new PVector(-0.886264681816,0.69921118021,0.839020371437),
new PVector(-1.05991327763,-0.285596489906,-0.893030643463),
new PVector(0.909702301025,-0.63289296627,-0.893030762672)};
PVector n = new PVector(0.150384, -0.500000, 0.852869);
PVector[] clone;
void setup(){
size(400,400,P3D);
smooth();
clone = unRotate(face,n,true);
}
void draw(){
background(255);
translate(width*.5,height*.5);
if(mousePressed){
rotateX(map(mouseY,0,height,0,TWO_PI));
rotateY(map(mouseX,0,width,0,TWO_PI));
}
stroke(128,0,0);
beginShape(QUADS);
for(int i = 0 ; i < 4; i++) vertex(face[i].x*s,face[i].y*s,face[i].z*s);
endShape();
stroke(0,128,0);
beginShape(QUADS);
for(int i = 0 ; i < 4; i++) vertex(clone[i].x*s,clone[i].y*s,clone[i].z*s);
endShape();
}
//get rotation from normal
PVector getRot(PVector loc,Boolean asRadians){
loc.normalize();
float rz = asRadians ? atan2(loc.y,loc.x) : degrees(atan2(loc.y,loc.x));
float ry = asRadians ? atan2(loc.z,loc.x) : degrees(atan2(loc.z,loc.x));
float rx = asRadians ? atan2(loc.z,loc.y) : degrees(atan2(loc.z,loc.y));
return new PVector(rx,ry,rz);
}
//translate vertices
PVector[] unRotate(PVector[] verts,PVector no,Boolean doClone){
int vl = verts.length;
PVector[] clone;
if(doClone) {
clone = new PVector[vl];
for(int i = 0; i<vl;i++) clone[i] = PVector.add(verts[i],new PVector());
}else clone = verts;
PVector rot = getRot(no,false);
PMatrix3D rMat = new PMatrix3D();
rMat.rotateX(-rot.x);rMat.rotateY(-rot.y);rMat.rotateZ(-rot.z);
for(int i = 0; i<vl;i++) rMat.mult(clone[i],clone[i]);
return clone;
}
1