SRL Archive - OSR Help

X or Y Axis coordinates from degrees


VastlySuperior

2012-09-11 15:45:34

Is it possible to get the x and y coordinates for an item from the degrees and distance you are from an object.

If we think of a circle and I am the middle point of that circle and I can get the distance from an object and also the angle from me to the object, it should be theoretical possible to get the Y or X axis coordinates of the object.

I don't have the math for this, can some one help me with that? Is it possible to do something like this?

masterBB

2012-09-11 15:47:39

Read wrong

Nebula

2012-09-11 15:47:53

RotatePoint.

masterBB

2012-09-11 15:56:33

not tested

var
angle, dist: Extended;
begin
angle := 210 / 180 * PI; //degrees to radians
dist := 20;

x := Sin(Angle) * dist;
y := Cos(Angle) * dist * -1;
end;

Flight

2012-09-11 21:47:42

I'm honestly a bit confused here; how are you relating items to objects? Are you trying to get a tile X/Y coordinate of an object on the MS? If you give me an example I could surely understand you better.

VastlySuperior

2012-09-12 01:30:17

From: Flight
I'm honestly a bit confused here; how are you relating items to objects? Are you trying to get a tile X/Y coordinate of an object on the MS? If you give me an example I could surely understand you better.


Sorry that I only reply now but I was a bit peckered and went to sleep.

Yes, it is a object on the main screen, I identify it correctly and I move to the object, but in between me and the object is a lot of opsticals around which I have to move, so what I want is the coordinates of the x or y axis so that I can work out where I can draw a box which will tell me when the object was removed and it must be accurate in doing that. I know the distance to the object, I know the degrees from me to the object, how do I take that two values and convert it to a coordinate where I can draw the box? I will not always end up precisely N,E,S,W off the object, it might not always be one object that is different from all the other objects, there might be 4 or 5 close to that one, that one was just the closest from the mscx, mscy when I did the search.

Hope this clarifies it more.

@ masterBB, I will be testing your code later on and let you know what I find. Thanks


riwu

2012-09-12 01:35:26

masterBB's code will work. The angle in his code refers to the angle between the line and the normal (the upper vertical line). Basic trigonometry if you can see the right angle triangle. You'll have to add/subtract the x,y value from his code to MSCX,MSCY too in order to get the actual coordinate.

And just in case your compass is not facing perfectly north, you can use rs_GetCompassAngleRadians then RotatePoint.