View Single Post
Old 26th November 2007, 00:41   #269
AJ Sindri
Junior Member
 
AJ Sindri's Avatar
 
Join Date: Nov 2007
Posts: 29
Converting Movement Equations Polar (r,d) to Parametric (x,y)

I've been working for sometime trying to change polar movement equations into parametric. After looking at a few presents, this is what I came up with:

midx=//x pole goes here;
midy=//y pole goes here;
r=atan2((x-midx),(y-midy));
rx=-cos(r);
ry=sin(r);
dx=sin(r);
dy=cos(r);
d=abs(sqrt(pow(y+midy,2)+pow(x+midx,2)))*2;

midx and midy are the x and y cordiants for the pole (equivilant to the origin in parametric), or the center of the polar equation.

r is the angle counterclockwise from the ray starting at the pole and extending right, and d is the distance from the pole.

rx,dx,ry,dy are the direction of the vector. The first letter is what type of direction (distance or radial) and the second letter is what variable goes under (rx would go under the x=, and dy would go under the y=, etc)

The Vector is comprised of a direction times the distance.

This all may be a bit confusing so here are some sample equations: (asume midx and midy equals 0)

CONVERTING:
r=r+.1;
d=d+.1;
TO
x=x+rx*.1+dx*.1;
y=y+ry*.1+dx*.1;

If you want to multiply a direction by the distance or angle use r or d:

CONVERTING:
r=r+.1/(d+.2);
TO
x=x+rx*.1/(d+.2);
y=y+ry*.1/(d+.2);

I like the equation but the converting process can get kind of annoying. feel free to use any of this and please comment!

A fun little program:
in the dynamic movements point box:

midx=getkbmouse(1);
midy=getkbmouse(2);
ang=atan2((x-midx),(y-midy));
rx=-cos(ang);
ry=sin(ang);
dx=sin(ang);
dy=cos(ang);
d=abs(sqrt(pow(y+midy,2)+pow(x+midx,2)))*2;
x=x+rx*.05/(d+.2)*sin(d*6)-dx*.05*sin(r*6);
y=y+ry*.05/(d+.2)*sin(d*6)-dy*.05*sin(r*6);

//move your mouse around and have fun!!
AJ Sindri is offline   Reply With Quote