Car relative vector to world relative vector

Member
Posts: 40
Joined: 2002.04
Post: #1
hi everyone

I'm trying to make a simple 3D racing game, and I need to convert a car-relative velocity vector into a world co-ordinate velocity vector.

For my car-relative velocity vector, the Z axis is in straight out the windsheild, the x-axis cuts across the car, and the y axis points up out of the car.
I need to convert this velocity vector into a world coordinate velocity vector.

Thanks
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
I remember this! It's a basis transformation!

Um...

Yeah.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
Oh boy, linear algebra!

Quote:Anton, "Elementary Linear Algebra", 7th ed.

Solution of the Change of Basis Problem. If we change the basis for a vector space V from some old basis B = {u1, u2, ..., un} to some new basis B' = {u'1, u'2, ..., u'n}, then the old coordinate matrix [v]B of a vector v is related to the new coordinate matrix [v]B' of the same vector v by the equation

[v]B = P[v]B'

where the columns of P are the coordinate matrices of the new basis vectors relative to the old basis; that is, the column vectors of P are

[u'1]B, [u'2]B, ..., [u'n]B
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
So (if I've got this right, and it's 12.45 AM so take it with a grain of salt), what you need to do is make a matrix with the vectors for the x direction of the car in world space, the y direction of the car in world space, and the z direction of the car in world space, and multiply that matrix by the car-relative velocity vector.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
I have no idea whether that's right though. I should really leave the math questions to the people who actually remember these things...
Quote this message in a reply
kainsin
Unregistered
 
Post: #6
Sounds just right to me.
Quote this message in a reply
Member
Posts: 40
Joined: 2002.04
Post: #7
thanks onesadcookie, that sounds easy enough, although I'd rather not use matrices.

although after playing around I came up with this for 2D transformation:

velwc.x=-sin(yawamount)*velocity.z+cos(yawamount)*velocity.x
velwc.z=-cos(yawamount)*velocity.z+sin(yawamount)*velocity.x



Is there a similar way for 3D transformation? I attempted to work it out, but now my brain hurts. I'd prefer to stay away from matrices as I really have no idea what i am doing.
Quote this message in a reply
ededed
Unregistered
 
Post: #8
Just a hint that may not help in your situation but It is worth noting.

DotProduct(x, y) = (Sin(theta), Cos(theta))
theta = the bearing of (x, y) to the origin

DotProduct(x, y){
d = sqrt(x*x + y*y)
x /= d
y /= d
}

Out of intrest why might you need to convert a relative velocity to a world velocity, why not just use a world velocity for a car?
Quote this message in a reply
Member
Posts: 40
Joined: 2002.04
Post: #9
I'm implementing some car physics, and some of these equations deal with the relative velocity of the car, and the wheel angle and such. These forces are acting on the car in relation to the car, not world coordinates, hence the need to convert.

Anyway, I'll see if I can get some of this matrix stuff workin. Even though I did matrices last semester in school, im still a bit rusty.. but it sounds easy enough.

Thanks everyone!
Quote this message in a reply
ededed
Unregistered
 
Post: #10
Just a second, you seem to be making this very complicated, using matrices and things. You must rotate the car to draw it properly... So cant you just to the opposite rotatation on the vector of the car.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #11
It's a 3x3 matrix multiplication. That's nine multiplies and six adds -- it's going to be easier and faster than some yucky trigonometric solution.
Quote this message in a reply
Member
Posts: 304
Joined: 2002.04
Post: #12
You have a car that is rotated and translated. How are you currently storing that rotation now? A quaternion? A 3x3 rotation matrix?

Quote:Originally posted by ededed
Just a second, you seem to be making this very complicated, using matrices and things.

I would argue he is making his life *harder* by avoiding using matricies and things.
Quote this message in a reply
Member
Posts: 164
Joined: 2002.04
Post: #13
Quote:Originally posted by Cookie
thanks onesadcookie, that sounds easy enough, although I'd rather not use matrices.

although after playing around I came up with this for 2D transformation:

velwc.x=-sin(yawamount)*velocity.z+cos(yawamount)*velocity.x
velwc.z=-cos(yawamount)*velocity.z+sin(yawamount)*velocity.x



Is there a similar way for 3D transformation? I attempted to work it out, but now my brain hurts. I'd prefer to stay away from matrices as I really have no idea what i am doing.

My dorotation method:
XYZ DoRotation(XYZ thePoint, float xang, float yang, float zang){
XYZ newpoint;
if(xang){
xang*=6.283185;
xang/=360;
}
if(yang){
yang*=6.283185;
yang/=360;
}
if(zang){
zang*=6.283185;
zang/=360;
}


if(yang){
newpoint.z=thePoint.z*cos(yang)-thePoint.x*sin(yang);
newpoint.x=thePoint.z*sin(yang)+thePoint.x*cos(yang);
thePoint.z=newpoint.z;
thePoint.x=newpoint.x;
}

if(zang){
newpoint.x=thePoint.x*cos(zang)-thePoint.y*sin(zang);
newpoint.y=thePoint.y*cos(zang)+thePoint.x*sin(zang);
thePoint.x=newpoint.x;
thePoint.y=newpoint.y;
}

if(xang){
newpoint.y=thePoint.y*cos(xang)-thePoint.z*sin(xang);
newpoint.z=thePoint.y*sin(xang)+thePoint.z*cos(xang);
thePoint.z=newpoint.z;
thePoint.y=newpoint.y;
}

return thePoint;
}

where xyz is a class of 3 floats, x,y and z
xang is rotation around x axis, etc.

I hope this helps.
Quote this message in a reply
Member
Posts: 40
Joined: 2002.04
Post: #14
Actually, I see what you mean now OSC and codemattic, so I'll go with matrices.

Currently i am storing the orientation of my car in a quarternion. How would I store it in a 3x3 matrix?

Thanks.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #15
Oh, if you're storing the orientation as a quaternion, there's probably an even simpler solution than we've proposed...

Unfortunately, I know nothing about quaternions, so I can't be of assistance.

If you can turn it into the three vectors that my matrix method needed, you could still go that route...
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  What to do with vector graphics? stevejohnson 4 6,788 May 6, 2005 01:27 PM
Last Post: stevejohnson
  top-down cameras. What to do with the up vector reubert 10 5,174 Apr 18, 2005 07:31 PM
Last Post: Leisure Suit Lurie