3D Relative Angle Sum Calculation

3D relative angle sum calculation

One possible solution I found:

        (r2 * Quaternion.Inverse(r1)).eulerAngles.Y

Signed Rotation between two normals in 3D

you need to use atan2 (4-quadrant arc tangens)

3D
2D reference plane slice

  1. create reference plane basis vectors u,v

    • must be perpendicular to each other and lie inside plane
    • preferably unit vectors (or else you need to account for its size)
    • so let N=N_T x N_R; ... reference plane normal where the rotation will take place
    • U=N_T;
    • V= N x U; ... x means cross product
    • make them unit U/=|U|; V/=|V|; if they are not already
  2. compute plane coordinates of N_R

    • u=(N_R.U); ... . means dot product
    • v=(N_R.V);
  3. compute angle

    • ang=atan2(v,u);
    • if you do not have atan2 then use ang=atanxy(u,v);
    • this will give you angle in range ang=<0,2*M_PI>
    • if you want signed angle instead then add
    • if (ang>M_PI) ang-=2.0*M_PI; ... M_PI is well known constant Pi=3.1415...
    • now if you want the opposite sign direction then just use -ang

How to calculate an angle from three points?

If you mean the angle that P1 is the vertex of then using the Law of Cosines should work:

arccos((P122
+ P132 - P232) / (2 *
P12 * P13))

where P12 is the length of the segment from P1 to P2, calculated by

sqrt((P1x -
P2x)2 +
(P1y -
P2y)2)

3D Math: Calculate Bank (Roll) angle from Look and Up orthogonal vectors

I'm just doing this on paper. I hope it's right.

Let's assume Up and Look are normalized, that is, length 1. Let's say that plane P contains the origin, and L is its normal. Y is (0, 1, 0)

To project Y onto P, find its distance to P...

d = Y dot L = ly

...and then scale the normal by -d to get the Y1 (that is, the projection of Y on P)

Y1 = (lx * ly, ly * ly, lz * ly)

Now normalize Y1, that is, scale it by (1 / length). If its length was 0 then you're out of luck.

The dot product of Y1 and Up = the cosine of the angle. So

angle = acos(Y1 dot Up)

calculate angle from vector to coord

input

  • p1 = (x1,y1) point1 (vector origin)
  • p2 = (x2,y2) point2
  • a1 = 360 deg direction of vector
  • assuming your coodinate system is: X+ is right Y+ is up ang+ is CCW
  • your image suggest that you have X,Y mixed up (angle usually start from X axis not Y)
  • da=? change of a1 to match direction of p2-p1

solution 1:

  • da=a1-a2=a1-atanxy(x2-x1,y1-y1)
  • atanxy(dx,dy) is also called atan2 on some libs just make sure the order of operands is the right one
  • you can also use mine atanxy in C++
  • it is 4 quadrant arctangens

solution 2:

  • v1=(cos(a1),sin(a1))
  • v2=(x2-x1,y2-y1)
  • da=acos(dot(v1,v2)/(|v1|*|v2|))

or the same slightly different

  • v1=(cos(a1),sin(a1))
  • v2=(x2-x1,y2-y1)
  • v2/=|v2| // makes v2 unit vector, v1 is already unit
  • da=acos(dot(v1,v2))

so:

da=acos((cos(a1)*(x2-x1)+sin(a1)*(y2-y1)/sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));

[notes]

  • just change it to match your coordinate system (which you did not specify)
  • use radians or degrees according to your sin,cos,atan dependencies ...


Related Topics



Leave a reply



Submit