🔒 Locked
vectors
Advertisement
Original Post
ok i am having a little trouble with vectors, what i am trying to do is have 2 vectors one for the y axis and one for the x axis these 2 vectors will each be a force on its respective axis, this force will be as great as the vectors length, now i have 2 vectors lets say the Yaxis vectors length is 4 and the Xaxis vectors length is 3 then the resultant of the two is 5
pictured below, ok now what i want is the angle beween 4 and 5, now how i would do this is:
length = (x ^ 2 + y ^ 2) ^ 0.5
degree = cos-1(y / length);
problems i have found with this is 1:
i cant find this function cos-1 (opposit of cos) on the computer (c++) so i cant even do this, this must exist i just dont know the function name (any help?) and 2:
this method seems to suck because it only works correctly if x and y are positive, if one or both are negetive it goes haywire, so in essence what i need is either a better method of finding angles based on force or at least the function for finding cos-1 sin-1 tan-1 in c++
4 5
|---|
| / |
|/ |
|---| 3
what the hell do i need this for anyway? well i am trying to make a top down space shooter type thing and i need to rotate and make the ship travel by the user pressing the arrow keys and this is the only way i can think of how to do this, if anyone knows a better way by all means please let me know.
bcware@mediaone.net
Edited by - bcware on 11/5/00 9:45:22 AM
i have a book in which that exact statement was listed as well but i seem to be doing something wrong here
my vectors since they always come from the origin will always be something like (0, 4) and (3, 0) point being they always have zeros in them which when i do
Ux * Vx + Uy * Vy
0 * 3 + 4 * 0 = 0
and even if i replace the zeros with lets say 1...
1 * 3 + 4 * 1 = 7
then i do the same only get the absolute value ?
|7| in this case since it isnt negetive so it would just be 7
U*V / |U|*|V|
7 / 7 = 1
i appear to be doing this wrong since i am doing nothing but canceling myself out or just getting 1 every time
my vectors since they always come from the origin will always be something like (0, 4) and (3, 0) point being they always have zeros in them which when i do
Ux * Vx + Uy * Vy
0 * 3 + 4 * 0 = 0
and even if i replace the zeros with lets say 1...
1 * 3 + 4 * 1 = 7
then i do the same only get the absolute value ?
|7| in this case since it isnt negetive so it would just be 7
U*V / |U|*|V|
7 / 7 = 1
i appear to be doing this wrong since i am doing nothing but canceling myself out or just getting 1 every time
|
Here''s my Vector Angle calculation method. It basically does the same thing as Phobia pointed out but in code form.
Regards,
Jumpster
quote:
my vectors since they always come from the origin will always be something like (0, 4) and (3, 0) point being they always have zeros in them which when i do
Ux * Vx + Uy * Vy
0 * 3 + 4 * 0 = 0
If that is in-fact your vectors, then you will always be 90-degree angles.
Here''s why:
|
Y +
|
|-----+
X
Where the Y(+) = (0,4) and the X(+) = (3,0). Notice the angle between the two is a Right Angle. Following the formula, you get:
acos( Y(+) dot X(+) / Y(+).Lenght() * X(+).Length())
acos( 0 / ??? )
acos( 0 ) = 1.57079632679489661923132169163975 - radians.
1.57079632679489661923132169163975 * (180/PI) = 90. - degrees.
ok i can see i did that horribly wrong and the . meant dot product not multiply (duh) ok but what i need is just a straight forward way of getting a dot product, as i said before i have a book on this but its seems to be waaay past me it says the same thing that:
cos(theta) = V.W / |V|*|W|
would anyoen be kind enough to do this out the long way for me. because i am not sure exactly what goes in the places of this little formula, and will this work if the vectors have a zero in them?
cos(theta) = V.W / |V|*|W|
would anyoen be kind enough to do this out the long way for me. because i am not sure exactly what goes in the places of this little formula, and will this work if the vectors have a zero in them?
ok i seem to be going about doing this completely wrong here
well what i want to make is a top view of a space ship that will have the right and left arrow keys rotate the ship and the forward and back keys thrust in the givin direction so what i need to know is, based on the direction my space ship is pointing in if i thrust in that direction how much do i add or subtract to the x or y coordinate to get it to actually travel in this direction? i am sure there must be some sort of document that covers this, i have seem many games that use this same thing i just can't figure it out.
oh yeah and if anyone knows a thing or two about velocity and the like that would help too, like acceleration and decay and everything: a = f / m
oh yes a good example of exactly what i mean is like in asteroids i am trying to figure out basically this, based on what direction the space shit is pointing in when i fire my bullet which orinates at 0,0 how much do i add to the x and y coordinates to get the bullet to travel in the same direction as the ship is pointing
Edited by - bcware on November 5, 2000 11:54:54 AM
oh yeah and if anyone knows a thing or two about velocity and the like that would help too, like acceleration and decay and everything: a = f / m
oh yes a good example of exactly what i mean is like in asteroids i am trying to figure out basically this, based on what direction the space shit is pointing in when i fire my bullet which orinates at 0,0 how much do i add to the x and y coordinates to get the bullet to travel in the same direction as the ship is pointing
Edited by - bcware on November 5, 2000 11:54:54 AM
Ok, then you need a way to rotate the vector of the ship.
Check this out:
You would also need to take into consideration Velocity which is unfortunately not something I can explain very well except that it it dist/time.
Regards,
Jumpster
Perhaps you would benefit greatly from "Tricks of the Windows Game Programming Gurus" by Andre LaMothe. Virtually everybody in this forum uses it for various things and he covers a good deal of physics modeling in it.
Check this out:
|
You would also need to take into consideration Velocity which is unfortunately not something I can explain very well except that it it dist/time.
Regards,
Jumpster
Perhaps you would benefit greatly from "Tricks of the Windows Game Programming Gurus" by Andre LaMothe. Virtually everybody in this forum uses it for various things and he covers a good deal of physics modeling in it.
i have the book actually i just happen to have leant it out
great timing huh? your math functions are helpful except they assume you already know everything like getting the cross pruduct and the dot product already, which unfortunatly i do not, so i am screwed basically, what i need is a tutorial on this exact subject so i either have to wait to get my book back and find one online, i remeber in the book andré made the exact same game as i am trying to make only it was 2d, mine is 3d but your only allowed to move 2 dimensionally so the same math would work
Edited by - bcware on November 5, 2000 11:59:39 AM
Edited by - bcware on November 5, 2000 11:59:39 AM
|
Here is basically my entire VECTOR class implementation less extraneaous(sp?) comments. It''s not a tutorial but you should be able to figure out what it happening.
Regards,
Jumpster
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement