ending location from angle and speed
I'm trying to calculate the ending x,y of my object. I have the starting x,y and the angle in radians and the speed
this is what I'm trying:
the result is almost as if everything is wildly exagerated.
does anyone know how to calculate this correctly?
this is what I'm trying:
Code:
deltaX = cos( rotation ) * speed;
deltaX = startingX * deltaX;
deltaY = sin( rotation ) * speed;
deltaX = startingY * deltaY;
the result is almost as if everything is wildly exagerated.
does anyone know how to calculate this correctly?
Seems like you'd want to add deltaX/Y to startingX/Y instead of multiplying them together.
Also, why multiply the *speed* by cos and sin of the angle? What are you trying to do there? Should the translation be affected by rotation?
I usually express this kind of things by matrix multiplication. It scales better to more complex situations.
I usually express this kind of things by matrix multiplication. It scales better to more complex situations.
I have a facing vector instead of a facing angle. The plus side is you don't need to cos and sin constantly, only when they turn. Then when you want to move somebody you just do
movement=[facing scale:speed];
[position add:movement];
I just made up arbitrary function names but you can probably get the point.
When you want to turn all you need to do is rotate the facing vector by X radians negative for a left turn, positive for a right turn. You can rotate a vector using CGAffineTransform functions.
movement=[facing scale:speed];
[position add:movement];
I just made up arbitrary function names but you can probably get the point.
When you want to turn all you need to do is rotate the facing vector by X radians negative for a left turn, positive for a right turn. You can rotate a vector using CGAffineTransform functions.
Kazooless Wrote:I'm trying to calculate the ending x,y of my object. I have the starting x,y and the angle in radians and the speed
this is what I'm trying:
Code:
deltaX = cos( rotation ) * speed;
deltaX = startingX * deltaX;
deltaY = sin( rotation ) * speed;
deltaX = startingY * deltaY;
the result is almost as if everything is wildly exagerated.
does anyone know how to calculate this correctly?
I assume this is so that you can move an object on an angle? if so you can use the following code
Code:
deltaY = sin (rotation) * speed; //this finds the y travel distance
finalY = startingY + deltaY; // this is the location of object on the y plane
deltaX = cos (rotation) * speed; //this finds the x travel distance
finalX = startingY + deltaY;
It's basic trigonometry where the speed is the hypoteneuse and the y is "Opposite" and x is "Adjacent".
looking at a clock 3 o'clock would be 0 (or 360) degree, 12  90 (or 270) degrees, 9  180 (or 180) degrees, 6  270 (or 90) degrees.
speed * cos (rotation)
masdest Wrote:I assume this is so that you can move an object on an angle? if so you can use the following code
Code:
deltaY = sin (rotation) * speed; //this finds the y travel distance
finalY = startingY + deltaY; // this is the location of object on the y plane
deltaX = cos (rotation) * speed; //this finds the x travel distance
finalX = startingY + deltaY;
It's basic trigonometry where the speed is the hypoteneuse and the y is "Opposite" and x is "Adjacent".
looking at a clock 3 o'clock would be 0 (or 360) degree, 12  90 (or 270) degrees, 9  180 (or 180) degrees, 6  270 (or 90) degrees.
speed * cos (rotation)
That last line should read:
Code:
finalX = startingX + deltaX;
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
Formula for converting angle to vector?  komirad  2  12,980 
Jul 29, 2011 07:29 AM Last Post: ThemsAllTook 

Question Regarding the Reflect Angle of a Transition  iBaby  3  4,609 
Apr 27, 2010 03:15 PM Last Post: JustinFic 

polling mouse location?  alloca  1  3,136 
Jan 22, 2009 04:14 PM Last Post: ThemsAllTook 

Angle between two points?  Graphic Ace  6  6,742 
Nov 8, 2008 12:11 PM Last Post: macnib 

calculating X and Y coordinates w/ an angle and distance  ferum  13  18,844 
Jun 25, 2008 10:53 PM Last Post: rosenth 