0

Given a plane(in my case a triangle) normal N_T and a reference Normal N_R, both have the length 1.

I calculated the rotation_normal

N = N_T x N_R

and now i need to calculate the angle around this rotation_normal, which i get with the following calculation:

angle = acos(<N_T, N_R>), with <x,y> is the dotproduct of x and y

This angle is in the interval of [0°, 180°] and is the smallest angle between both normals. So my problem is that if i want to rotate my triangle in a manner that its normal is equal to the reference normal, i need to know in which direction (positive or negative) the calculated angle is.

Does anybody know how to get this direction or how to solve this problem in general?

m47h
  • 1,611
  • 2
  • 18
  • 26

1 Answers1

2

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
Community
  • 1
  • 1
Spektre
  • 49,595
  • 11
  • 110
  • 380