[Solved] Math Question on axis based dot product

OK I have a noob dot product question,

Here is the use case. I am building a space ship builder. You drag parts onto the ship and they attach based on the Normal direction of the mouse collision point of the part of the ship your mouse is on. My problem is that for some parts, I want to set a directional clamp based on X and Y rotation thresholds. For example, engines can only be attaches to other parts where the other part’s normal is within 10 and -10 degrees rotation of the Y rotational axis. (Engine Model Pointing forward)

My first approach was to get the Normal vector, set the Y to zero, and then get the angle between Vector3f.Unit_Z and the resulting normal. Well that does not work if the original normal is 0,1,0 or 0,-1,0 or anything in between.

Can someone help the noob out?

Edit: here is my poor man’s debug statement:
System.err.println(Vector3f.UNIT_Z.angleBetween(event.getCollision().getContactNormal().clone().setY(0)) * FastMath.RAD_TO_DEG + " " + event.getCollision().getContactNormal());

I am an idiot. Solved my own problem.

Quaternion quaternion = new Quaternion();
quaternion.lookAt(event.getCollision().getContactNormal().clone(), Vector3f.UNIT_Y);
float[] angles = quaternion.toAngles(null);
System.err.println(" Y = " + (angles[1] * FastMath.RAD_TO_DEG) + " degrees");
System.err.println(" Z = " + (angles[2] * FastMath.RAD_TO_DEG) + " degrees");
System.err.println(" X = " + (angles[0] * FastMath.RAD_TO_DEG) + " degrees");

Perhaps your solution will help someone else.

1 Like

So often in 3D math, if “angles” is the question you are asking then you ended up somewhere wrong… and almost always “dot product” is the answer (but sometimes “cross product”).