ending location from angle and speed

Nibbie
Posts: 1
Joined: 2009.03
Post: #1
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?
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
Seems like you'd want to add deltaX/Y to startingX/Y instead of multiplying them together.
Quote this message in a reply
Member
Posts: 260
Joined: 2005.05
Post: #3
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.
Quote this message in a reply
Member
Posts: 306
Joined: 2009.03
Post: #4
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.
Quote this message in a reply
Nibbie
Posts: 1
Joined: 2009.03
Post: #5
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)
Quote this message in a reply
Member
Posts: 73
Joined: 2009.03
Post: #6
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;
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Formula for converting angle to vector? komirad 2 9,831 Jul 29, 2011 07:29 AM
Last Post: ThemsAllTook
  Question Regarding the Reflect Angle of a Transition iBaby 3 3,503 Apr 27, 2010 03:15 PM
Last Post: JustinFic
  polling mouse location? alloca 1 2,474 Jan 22, 2009 04:14 PM
Last Post: ThemsAllTook
  Angle between two points? Graphic Ace 6 5,354 Nov 8, 2008 12:11 PM
Last Post: macnib
  calculating X and Y coordinates w/ an angle and distance ferum 13 14,886 Jun 25, 2008 10:53 PM
Last Post: rosenth