Can somebody explain me basics of vectors please a lot?
I know how to calculate lenght of vector (lenght=sqrt(x*x+y*y)). I want to explain angles and how to get the new x and y. Please show me how on some simple example with this picture.
I want to use left and right keys to set the angle and up nad down to move forward and backward. But I want only know how to calculate angle and new x, y. The best solution will be show it on some example picture. Thanks a lot everybody.
wikipedia to the rescue ?
ask google ?
x = length * cos(angle)
y = length * sin(angle)
I tried wikipedia and google but nothing please explain it to me yes I found new x and y as you but it did not work for me perhaps because I used wrong angle so can you show me it on some example in picture please?
edit
Is this right code?
Length. If I knew the answer to what you are asking then I would help with that, but I don't.
The best solution will be show it on some example picture.
Perhaps you should draw an illustration to let us know what you're trying to calculate. I can't understand what you're trying to say.
There's a Windows bitmap in the paperclip in the original post, but it looks like a simple transposition.
I am only asking that is my source code of calculating the new x and y right? that was my question
Yes, you are calculating the new x and y values correctly. Not too sure why you are calculating the length that way, however...
Basically, if you want to move distance 'lenght' in the direction 'angle' you do:
Which is exactly what you do anyway.
Thanks, that is it.
Do you know about better way to calculate length?
No, the way you calculate it is right if you want to calculate the length of the vector (10, 10). I'm not sure why you are calculating it.
Where are X and Y on your picture ?
What kind of data do you already know for computing X and Y ?
That is only example,the important thing is the way to do it
Thanks for all.
I tried this code but it doesn t work, where I am doing mistake please?
The length is in every case 10, the object move about 10 pixels. Can somebody fix me it?
I tried this code but it doesn t work, where I am doing mistake please?
In just using the hated phrase "doesn't work".
How does it not work?
Okey, it moves to opposite directions
Here is picture to show you how it works, up and down mean keys
{"name":"14scvi0.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/c\/8c0097e3ed90fff4b1188fc8d9745fc0.jpg","w":646,"h":512,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/c\/8c0097e3ed90fff4b1188fc8d9745fc0"}
Line of enquiry :-
You program says that when UP is pressed y gets incremented by
lenght*sin( 105 *PI/180);
which is a posiive value so the sprite should move down the screen.
Is this what's happening ?
Yes, that's right
Checklist:
use the right angle unit at every point
be sure of direction at zero angle value
be sure of direction of rotation when angle value increases
be sure of screen coordinates, where's origo, at what direction does x grow, at what direction does y grow
sin(0) == 0, cos(0) == 1, sin(π/2) == 1, cos(π/2) == 0
Your problems seem to relate to this checklist, not to your understanding of vectors. Someone continue my checklist. Or improve it.
Okey, but does anybody know how to fix my source code?
Follow Halméns checklist. It will tell you exactly what's wrong with your code.
Okey, but does anybody know how to fix my source code?
People here don't make a habit of writing other people's source code for them, but we'll happily give you the tools to do it yourself (which has already been done in this case).
When I rotate my image in own image file it works good and all int are float
rotated about 90 deegres to right
Why hasn't anyone linked to this?
http://pixwiki.bafsoft.com/mags/5/articles/circle/sincos.htm
Read that article, it explains about all of the basics you need to know.
A quick summery for once you know what you're doing:
theta - the angle of your vector
Polar to Cartesian Coordinents
x=magnitude * cosine(theta)
y=magnitude * sine(theta)
Cartesian to Polar Coordinents
magnitude_of_x_y = sqrt(x^2 + y^2)
theta = atan2(x,y) *it's atan2(y,x) in MATLAB and some other languages.
Thank you for that link and explain of it