Coordinate change algorithm

This is a discussion on Coordinate change algorithm within the C++ Programming forums, part of the General Programming Boards category; Is there any way to calculate how the coordinates of an object changed if it is travelling in a certain ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    79

    Coordinate change algorithm

    Is there any way to calculate how the coordinates of an object changed if it is travelling in a certain diretion?
    For instance, say I have a circle moving upwards to the left at an angle of 110 degrees. How can I then calculate how to change its coordinates in the next update of the screen?

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    This isn't really an algorithm... its simple vector math .

    You have a circle moving upwards to the left at an angle of 110 degrees, or you have an object moving in a circle to the left at an angle of 110 degrees?

    I'll cover the former.

    Basically, you have the velocity vector in magnitude (V) angle (theta, angle from positive x axis, counterclockwise) form... its icky (thats the offical term btw ), because you have to do trig to do anything with it really.

    First, convert this vector to components with trig.

    Vx (component of velocity in x direction) = V * cos(theta)
    Vy (component of velocity in y direction) = V * sin(theta)

    Now, the displacement (D, change in position) caused by this unchanging velocity during a given time t is

    Dx (displacement in x direction) = Vx * t
    Dy (displacement in y direction) = Vy * t

    If you have its original position vector P, then the position P' after the time t is simply in vector terms

    P' = P + D

    Or in scalar terms

    P'x = Px + Dx
    P'y = Py + Dy
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Registered User Engineer's Avatar
    Join Date
    Oct 2001
    Posts
    125

    Arrow

    This is where trigonometry comes in handy. If you ever took it before, you will know what I am talking about.
    1 rule of the Samurai Code: if you have nothing to say, don't say anything at all!

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    79
    I feared I would have to use trigonometry. I think we'll start with it in school in a couple of week. I haven't taken any trigonometry yet, don't know if the Swedish school system is slowmoving or if I'm just no old enough.
    Anyway, thanks a lot, I'll take a look at it.

  5. #5
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    I remember being consumed with that problem when I was a freshman in high school. I kept trying to apply the y = mx + b line formula to 2D motion, but it just doesn't work nicely.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Line Drawing Algorithm
    By Axpen in forum Game Programming
    Replies: 15
    Last Post: 08-01-2005, 07:30 PM
  2. Database Search Algorithm
    By Krupux in forum C Programming
    Replies: 1
    Last Post: 08-28-2003, 10:57 PM
  3. help with calculating change from a dollar
    By z.tron in forum C++ Programming
    Replies: 3
    Last Post: 09-13-2002, 04:58 PM
  4. Replies: 2
    Last Post: 09-04-2001, 03:12 PM
  5. Simple File Creation Algorithm
    By muffin in forum C Programming
    Replies: 13
    Last Post: 08-24-2001, 04:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21