Author Topic: suggest and question?why calcAngle(SimpleVector vec) only less than 180°  (Read 2259 times)

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
i know the most important feature of simplevector is that,every simplevector have a direction.
for example ,if i want cal the angle of a:(0,0,-1),b(0,0,1).
if use a.calcAngle(b),
the result is 0.
in fact the result is wrong,in the reality,the result is pi/2.

may be i can use other math method,but it is not convenient.

Any suggest?i just want cal the more correcter angle of simplevector,which has a direction.


 
 

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
btw ,except of this,the jpct is the perfect one ;D

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
if i want cal the angle of a:(0,0,-1),b(0,0,1).
if use a.calcAngle(b),
the result is 0.
in fact the result is wrong,in the reality,the result is pi/2.
No, actually the result whould by PI, not PI/2. And that's what the method returns. I'm not sure where you are getting this 0 from. This little test case:

Code: [Select]
SimpleVector s1 = new SimpleVector(0, 0, 1);
SimpleVector s2 = new SimpleVector(0, 0, -1);
System.out.println(s1.calcAngle(s2));
System.out.println(s2.calcAngle(s1));

prints out PI in both cases.

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
it is my fault,i made a mistake,pi=180 actually,but i  thought it is 360,before..
the question is,i want cal the angle of two SimpleVector.which is 270.
but use calAngle,it is only,90.
how can i cal?whose angle more than 180?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
That's because the calculation makes no assumptions about the relation between the two vectors and the history of their rotations. It calculates the angle between the two vectors without any sign or order. That's not always what one wants, but that's out of the scope of this method. In your case, it depends on your use case. For example: If your vectors lie in the xz-plane and only rotate around the y-axis, you can simply do a check if the x value of vector 2 is smaller than the x value of vector 1 and if it is, you can subtract the returned value from 2*PI to get the angle that you want.
« Last Edit: July 31, 2014, 08:08:24 pm by EgonOlsen »

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
THX,much appricated,My question have solved. :)