# Getting a cordinate

## Recommended Posts

Hi, I am having trouble getting a cordinate. I know what that angle, distance(pixels/unit), and starting cords(x,y) are but how would I find out what the other pair is. 0 degrees would be strait up. So pretty much what would be the formaula for this? Angle 330 (or 30) ?x,?y ___\___ Distance 30u/px ____\_ _____ 0,0 (ps ignore the underscores since it wont accept white spaces)

##### Share on other sites

 (x,y) |\ | \y|  \  h |   \ |___a\    x   (0,0)We have h = 30.We have a = 30 degrees.sin a = y/hsin 30 = y/3030 * sin 30 = yy = 15

You can calculate use the cos or use Pythagoreas theorem to find X.

Also, click edit on my post to see how I formatted. HTH

Edit: The backslash breaks the code and source tags

##### Share on other sites
Wise man say:
SOH
CAH
TOA

Sin(x) = Opposite/Hypotenuse

Your angle describes a right-angle triangle

Angle 330 (or 30)
?x,?y
_|_\___ Distance 30u/px
_|__\_
_+---0,0

Opposite = Hypotenuse * Sin(x)

"Hypotenuse" refers to the length of the side opposite the right-angle corner of your right-angled triangle.

"Opposite" refers to the side opposite to the corner with the angle "x".

"Adjacent" refers to the side adjacent to the corner with the angle "x".

That help?

##### Share on other sites
Am I doing this wrong because if I had an angle of 181 then shouldn't the Y axis be longer since its pretty much vertical so it should be arround 29 ish but its -.5ish. Unless 181 is pointing sideways. If it is (I think it is) then how would I convert it so 0/360/180 is at the top and not 90/270. Would I just have to change the angle by adding 90? Or is there a better way?

BTW: Thanks for all of your replies, they were very helpful. I totally overlooked sine for some reason.

##### Share on other sites
are you sure you're using degree and not radians?
for example the math.h is using radians, to calculate degrees with a radians function do something like sin(deg*M_PI/180); maybe that helps

if you're shure this is right I would say its just
Cx=sin(angle)*Distance+StartX;
Cy=cos(angle)*Distance+StartY;

##### Share on other sites
I am having some trouble with this, my sprite should be turing is circles but it seems to be going in a wavy like patter, what could be wrong? Here is the code.... (with a bunch of junk)

	knts = 30.0f;	turningForce = 16;	//Turn by changing ships angle	directionChange = ((knts / SCALE_FACTOR) * timeInterval * turningForce) / 15;	direction = direction + directionChange;	if (direction > 360)		direction = direction - 360;	if (direction < 0)		direction = -(direction);	//math.h uses radians so transfer our degrees to radians	rAngle = sin(direction*M_PI/180); 	//Get the distance traveled	velocity = (knts / SCALE_FACTOR) * timeInterval;	//yChange =  velocity;	//Move along the path of our current angle	//sin(angle)*Distance+StartX;	yChange = sin(rAngle)*velocity;	xChange = cos(rAngle)*velocity;		yPos = yPos + yChange;	xPos = xPos + xChange;

EDIT: I just realized I made a mistake when I said I wanted 0 to be the the top, it should be facing the left.

After a bit more searching I realized that 0,180 and 360 moves to the right, however 0 and 360 should be to the left and 180 to the right. The same would go for other directions. Would this be a simple fix, or would it require a lot more coding?

Also a 90 degree angle seemd ot move at 135 or so (1/2 between top and right)

[Edited by - starfleetrp on March 26, 2006 1:27:07 PM]

##### Share on other sites
1. if you dont use direction somewhere else in your code you can remove the ifs, otherwise if its an integer you could do direction=(direction+360)%360;
2. why are you using rAngle = sin(direction*M_PI/180); ??
you convert a polar to rectangular coordinate, and then later in your code you're trying to convert it again? seems like what you wanted is rAngle = direction*M_PI/180;
although I dont think that writing a variable and 2 times checking it is faster than 1 multiplication, so you could just convert it inside your sin/cos calls
3. if you want to have it facing to the left why dont you just use sin((direction-90)*M_PI/180)*velocity?

##### Share on other sites
Thank you, I totally overlooked the sin in #2

And as for the number #1 I will do as you sugested and look into what the % means (since i've never used it...)

##### Share on other sites
the % is the modulo, which gives you the remainder of a division. for example 10/4 gives you with integers a 2, but the actual number to be divided by 4 giving 2 is 8 so the difference between 10 and 8 is 2 -> modulo == 2
if you do now %360 it will put all numbers above 360 in the range between 0 and 360 by subtracting 360 as often as needed.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627701
• Total Posts
2978705

• 21
• 14
• 12
• 10
• 12