 |
|
| Computers Forum Index » Computer - Games Programming (Algorithms) » Rotating a point around another point... |
|
Page 1 of 1 |
|
| Author |
Message |
| Ethan... |
Posted: Mon Apr 20, 2009 12:13 am |
|
|
|
Guest
|
Hey everyone,
I've been trying to make a plane object for collision purposes. My
representation of that plane is a position, a pitch, and a roll (I
have exceptions for vertical planes so don't worry about that). The
way that I want to see if you cross a plane is by "rotating" the
points by the negative of the plane's pitch and roll leaving me with a
flat plane, and then seeing if the point I want to go to crosses that
flat plane. I then calculate the collision point in this rotated
plane of the two points, and the rerotate it by the pitch and roll to
give me that actual collision point.
The point is that I need a function to rotate a point around another
point by a pitch and a roll. I tried to make one, and here it is:
public Vector3 getRotatedVector(Vector3 toRotate, float yaw, float
pitch, float roll)
{
Vector3 fromOrigin = toRotate - position;
Quaternion rotation = Quaternion.CreateFromYawPitchRoll(yaw, pitch,
roll);
Vector3 rotatedVector = Vector3.Transform(fromOrigin, rotation);
return rotatedVector;
}
------------------------------------------------
Note that position is the position of my plane, so everything rotates
around that. For my test though I had it at Vector3.Zero, so it
didn't matter. I tested it like this:
Vector3 rotatedold = new Vector3(2.0f, 3.0f, 4.0f);
Console.WriteLine(rotatedold);
rotatedold = getRotatedVector(rotatedold, 0, MathHelper.ToRadians
(30.0f),
MathHelper.ToRadians(30.0f));
Console.WriteLine(rotatedold);
rotatedold = getRotatedVector(rotatedold, 0, -MathHelper.ToRadians
(30.0f),
-MathHelper.ToRadians(30.0f));
Console.WriteLine(rotatedold);
Console.WriteLine("--------");
---------------------------------------------------------------
Now, I would assume that since I'm rotating the negative of what I
just rotated, it would end up back were it started, right? Wrong.
Here was my output:
{X:2 Y:3 Z:4}
{X:0.2320509 Y:1.116025 Z:5.26314}
{X:0.7589747 Y:3.368108 Z:4.132772}
--------------------------------------------------------
Why is this happening? And how do I fix it. I would be eternally
grateful to anyone who could help! |
|
|
| Back to top |
|
|
|
| Paul E. Black... |
Posted: Mon Apr 27, 2009 8:50 pm |
|
|
|
Guest
|
On Sunday 19 April 2009 20:13, Ethan wrote:
Quote: ... by "rotating" the
points by the negative of the plane's pitch and roll leaving me with a
flat plane, and then seeing if the point I want to go to crosses that
flat plane. I then calculate the collision point in this rotated
plane of the two points, and the rerotate it by the pitch and roll to
give me that actual collision point.
...
Now, I would assume that since I'm rotating the negative of what I
just rotated, it would end up back were it started, right? Wrong.
My hypothesis is that your quaterion rotation is not commutative. If
you yaw first, then pitch, the inverse would be to (un)pitch, then
(un)yaw.
If that's not the problem, here are some debugging suggestions.
Quote: Here was my output:
{X:2 Y:3 Z:4}
{X:0.2320509 Y:1.116025 Z:5.26314}
Is this the right answer?
{X:0.7589747 Y:3.368108 Z:4.132772}
Try a pitch only, then negative pitch. Does that restore the point?
Another possibility is to check that
-MathHelper.ToRadians(30.0f) equals MathHelper.ToRadians(-30.0f)
-paul- |
|
|
| Back to top |
|
|
|
|
|
All times are GMT
The time now is Mon Nov 30, 2009 10:04 pm
|
|