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

#### Uncle Ray

• int
•  • Posts: 81 ##### suggest and question?why calcAngle(SimpleVector vec) only less than 180°
« 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.

#### Uncle Ray

• int
•  • Posts: 81 ##### Re: suggest and question?why calcAngle(SimpleVector vec) only less than 180°
« Reply #1 on: July 31, 2014, 09:36:15 am »
btw ,except of this,the jpct is the perfect one #### EgonOlsen

•     • • Posts: 12065 ##### Re: suggest and question?why calcAngle(SimpleVector vec) only less than 180°
« Reply #2 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.

#### Uncle Ray

• int
•  • Posts: 81 ##### Re: suggest and question?why calcAngle(SimpleVector vec) only less than 180°
« Reply #3 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?

#### EgonOlsen

•     • • Posts: 12065 ##### Re: suggest and question?why calcAngle(SimpleVector vec) only less than 180°
« Reply #4 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.
« Last Edit: July 31, 2014, 08:08:24 pm by EgonOlsen »

#### Uncle Ray

• int
•  • Posts: 81 ##### Re: suggest and question?why calcAngle(SimpleVector vec) only less than 180°
« Reply #5 on: July 31, 2014, 04:28:15 pm »
THX,much appricated,My question have solved. 