Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Coordinate Transform

This topic is 5795 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, i would like to do the following: I want to plot a graph like a sin or cos, but i want it to be plotted along a path, for example a circle. I thought about transforming the coordinate system to polar, but how could i draw the polar system without transforming back to carthesian? Im a little bit confused here now Thank you! Bye, Gerd

Share this post

Link to post
Share on other sites
You have to revert back to cartesian coordinates to draw it; it''s just easier to express it in terms of polar coordinates.

r = a + sin(theta)

where a is the radius of the circle.


x = r*cos(theta)
y = r*sin(theta)

If you had a general trajectory (other than a circle), the problem would be more complicated, in terms of maths, but we could probably find an algorithm that does it without too much of a problem.


Share this post

Link to post
Share on other sites
Why is it confusing? Are you asking about plotting it on a computer or by hand? Unless you are using a math package that supports polar plots you are going to have to convert it to rectangular with (x,y)=(r*cos(theta),r*sin(theta)). That is no biggy on a computer. I think most graphing calculators support polar plots or at least provide functions to do the conversion for you. If you are doing it by hand that conversion is a pain in the rump so you use polar graph paper instead. If you can''t find any locally then surely you can find some online.

Share this post

Link to post
Share on other sites
cedricl gave a great solution to the wave around a circle problem. I''ll try to summarize an approach for a general path. Wish I could host images to illustrate. For a general path, you need to find the cartesian coordinates of the wave exactly the way cedricl says, x = r*cos(angle), y = r*sin(angle). But these values are represented in a coordinate system that is to be aligned with the path. Thus, a transformation is required.

I''ll attempt to summarize an approach:

let t = a parameter that represents the position along your path (whether that be a circle or anything else). t = 0 at the start of the path and t = 1 at the end of the path. For a circular path, when t = 0, the angle would be 0 and when t = 1, then angle would be 360 degrees.

let l = the wavelength of the sin/cos wave that you''re interested in.
let a = amplitude of the wave
let pi = 3.14159265;

Now, the process, in pseudocode:

float dt = 1/number_of_points;
float t = 0.;

for (i = 0; i < number_of_points; i++)
// calculate the path point
xp = x coordinate of path at t
yp = y coordinate of path at t

// calculate the cartesian wave point, in wave space
xw = distance along the path;
yw = a*sin(2*pi*xw/l); // or cos, whatever.

// calculate the normal vector to the path as a unit
// vector
nx = x coordinate of path normal vector at t
ny = y coordinate of path normal vector at t

// now transform (xw, yw) to be aligned with the path.
// this could be done using matrices, but I didn''t want
// to have to explain my notation. The transformed
// version of xw is simply xp + the dot product of
// (yw,0) with (nx,ny).
xw'' = xp + yw*nx;

// similarly, the transformed version of yw is simply
// yp + the dot product of (0,yw) with (nx,ny)
yw'' = yp + yw*ny;

// what happened here is that I used the path itself to define
// a baseline (xp,yp) coordinate. The wave is a perturbation
// of that position normal to the path. In terms of the wave,
// given a baseline point, the only adjustment is vertical
// relative to the wave, which corresponds to the normal vector
// of the path. So I adjusted (xp,yp) along the normal vector
// by the amplitude of the wave at that point, the amplitude
// of the wave being yw. The horizontal wave position xw is
// only used to find the amplitude.

// the point to plot is (xw'', yw'')

// increment the path position for the next point
t += dt;

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!