[toxiclib] get rotation from a normal
in
Contributed Library Questions
•
1 year ago
hello i have an object (a mesh) and i want to orient it to be parallel to another terrain-mesh in a certain position (the position is a triangle).
so, something like that:
with given triangle in terrain,
get R the rotation of this triangle
rotate object of R.
i don't know how to get R. I tried getting the triangle normal and obtain R computing the angles between the normal and axis. But i don't get the expected values.
this code is a kind of unit test and i tried to keep it as easy as possible:
- // get a complex terrain
- TriangleMesh mesh = new TriangleMesh();
- mesh.addFace(new Vec3D(0,0,0), new Vec3D(10,0,0), new Vec3D(10,10,0));
- mesh.rotateX(PI/3);
- mesh.rotateY(0);
- mesh.rotateZ(0);
- // get the target position
- Face f = ((ArrayList<Face>)mesh.getFaces()).get(0);
- // get the rotaion of this triangle
- f.computeNormal();
- Vec3D v = f.normal;
- float angleX = (Vec3D.Axis.X.getVector().angleBetween(v));
- float angleY = (Vec3D.Axis.Y.getVector().angleBetween(v));
- float angleZ = (Vec3D.Axis.Z.getVector().angleBetween(v));
- // EXPECTED VALUES: angleX=PI/3, angleY=0, angleZ=0
- System.out.println(angleX);
- System.out.println(angleY);
- System.out.println(angleZ);
1