angle between 3d points

Hi, I’ve been having fun trying to do random stuff on panda3d, iam still a noob at it but this forum as been very helpful.

Anyways my latest problem is getting an angle between 2 3d points, so I can rotate the car in the right way acording to the field.

At this point, I dont know what to do, maybe panda has some fancy function that does this for me, maybe not. What would you do if you had this problem? Is there any function to get an angle between 2 3d points?


You can get the angle between 3 points say A, B, C (where A is the apex of the other two points) by first finding the vecotrs AB and AC (by subtraction) and then:

angle = arccos( (AB dot AC) / ( length(AB) * length(AC) ) )

Panda may have a better way of doing it, but that’s how I would do it.

However, in the case of your car, you may be better off finding collision points for the front wheels and back wheels separately and go from there.

iam going to give that a try

thanks :slight_smile:

ok, this worked >>>

BB =math.asin(dz/math.sqrt(dxdx+dydy+dz*dz));
angle = ((BB/math.pi)*180);

thx again guys :slight_smile:

Uhm, this is probably much better (and faster!)

angle = someVector.angleDeg(otherVector)
angleRad = someVector.angleRad(otherVector)

Well I did say that there was probably a better way in Panda :unamused:

Hello, I know this post is too old, but I faced the same problem.
I have 3d model and I want to know the angle between two 3D points in order to rotate that model with a correct angle.

I just didn’t get what are the someVector andotherVector ? and how I can get them from these two 3D points

I think that those are just arbitrary example vectors, intended to show a means by which one can get the angle between two vectors.

I don’t think that two points do inherently define a single angle.

Two points define a line or a vector; from that, one can then calculate an angle between that vector and some other, reference vector.

In your case, I’d imagine that this reference vector might be either the world-space “up” vector (i.e. a vector pointing directly upwards), or the vehicle’s “forward” vector with the vertical component removed (i.e. the direction in which it would be pointing if it were on flat ground).