www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Uncle Ray on July 31, 2014, 09:34:35 am

Title: suggest and question?why calcAngle(SimpleVector vec) only less than 180°
Post by: Uncle Ray on July 31, 2014, 09:34:35 am
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.

 
 
Title: Re: suggest and question?why calcAngle(SimpleVector vec) only less than 180°
Post by: Uncle Ray on July 31, 2014, 09:36:15 am
btw ,except of this,the jpct is the perfect one ;D
Title: Re: suggest and question?why calcAngle(SimpleVector vec) only less than 180°
Post by: EgonOlsen on July 31, 2014, 10:01:38 am
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.
Title: Re: suggest and question?why calcAngle(SimpleVector vec) only less than 180°
Post by: Uncle Ray on July 31, 2014, 11:11:52 am
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?
Title: Re: suggest and question?why calcAngle(SimpleVector vec) only less than 180°
Post by: EgonOlsen on July 31, 2014, 12:30:32 pm
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.
Title: Re: suggest and question?why calcAngle(SimpleVector vec) only less than 180°
Post by: Uncle Ray on July 31, 2014, 04:28:15 pm
THX,much appricated,My question have solved. :)