|
AnnMarie Otoole
Addicted scripter
Join date: 6 Jan 2007
Posts: 162
|
10-19-2008 18:27
I have two rotation vectors. Vehicle is facing vector A. vehicle needs to change rotation around Z axis to face vector B. If it is a 180 degree turn it doesn't matter but if it is less than 180 how do I determine if the shortest turn is LEFT or RIGHT? All the AngleBetween functions give the positive difference, I need the unsigned difference.
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
10-19-2008 19:17
if you aren't doing incremental steps to change the vehicles rotation, then simply applying the new rotation will take the shortest path in the viewer
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
AnnMarie Otoole
Addicted scripter
Join date: 6 Jan 2007
Posts: 162
|
10-19-2008 19:19
Thanks but it is a vehicle. I don't want it turning 350 degrees right if 10 degrees left is all that is needed.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
10-19-2008 21:30
if (theta > 180.0) { theta -= 360.0; }
Or if you are using radians: if (theta > PI) { theta -= TWO_PI; }
|
|
AnnMarie Otoole
Addicted scripter
Join date: 6 Jan 2007
Posts: 162
|
10-21-2008 22:04
I must be missing something but that answer has nothing to do with the question. I have two rotation vectors, not rotations. As I understand it, a rotation vector is the location (x,y,z) of the end of a 1 meter vector originating at the prim location. In my case, z is always zero. So I'm moving toward vector A and want to rotate in the horizontal plane to vector B.
If, for example, there is 30 degrees between these two vectors, how do I know to turn 30 degrees LEFT or 30 degrees RIGHT? I am going to rotate it until the current object vector is the same as the new intended vector. I don't want to go the wrong way and rotate 330 degrees to get there.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
10-22-2008 01:57
Ah. So you have two vectors and you want to know the angle between them essentially. Well, it turns out that the dot product and cross product are quite useful for that, and if the vectors are unit vectors ("one" in length), it looks quite simple: float angleBetween = llAcos(v1*v2); // dot product vector axisOfRotation = llVecNorm(v1%v2); // cross product
Note that 'angleBetween' will always be between 0 and pi, and 'axisOfRotation' will be the axis about which to rotate v1 by 'angleBetween' to get v2. In your case, the sign of 'axisOfRotation.z' will tell you whether it is a rotation about the +z or -z axes (alternately, a positive or negative rotation about the z-axis). The llRotBetween(), llRot2Angle(), and llRot2Axis() functions might also be helpful if you don't want to normalize the vectors yourself or something. http://www.lslwiki.net/lslwiki/wakka.php?wakka=llRotBetweenhttp://www.lslwiki.net/lslwiki/wakka.php?wakka=llRot2Anglehttp://www.lslwiki.net/lslwiki/wakka.php?wakka=llRot2Axis
|
|
AnnMarie Otoole
Addicted scripter
Join date: 6 Jan 2007
Posts: 162
|
10-23-2008 23:59
Cool, thanks Hewee, that should do it.
I did do trigonometry in college but that was nearly 50 years ago now and although we did cover vectors it was in the analog days when the idea of multiplying vectors was totally foreign.
|