Help with angles / relative position
#1

Hi!

I'm not too good at maths, and I'm having a headache trying to find out how to calculate the relative position from a object to another object depending on the facing angle (Z Angle)

This is my 'initial data':

Main object Pos:
x -> 69.5837
y -> 1719.8

'Depending' object pos with main object at 125 degrees
x -> 71.8405
y -> 1716.7
angle -> -54.7є

Then how can I calculate the relative position of the object depending on the angle of the main object? (Need the formulae)

Thanks for your help!

Siralos
Reply
#2

if your relative objects' position is on the same plane (on the x/y axis), then you might be able to use a sinus/cosinus transformation - it converts an input coordinate+angle+radius to a target position on the same height (z axis, due the formula transforms x/y coordinates only). handy for roads bends left/right.
if you need an object positioned AND rotated on all 3 axis, then you have to read about quaternions, they are, as the name implicates, a 4-dimensional representation of rotations. you might have read about the attached objects, theyre using a rotation-matrix (most prolly derivated by using quaternions, iam not sure about this). to attach an object to its parent, you "only" need its relative position from the origin/parent.
warning: to obtain a relative objects' position/rotation offset, its clever to place the parent at 0-0-0 rotation, find the children-object (attached object) position and rotation (x/y only), and then to subtract each parameter. the result can be used to attach it with the upward-mentioned sin/cos functions, as long you are rotating the objects on the z axis only. a later rotation on the x or y axis will be influenced by the so-called "gimbal lock" - good luck at finding a better solution, iam (again) actually trying to crack those fucking quaternions, with few success btw ><
edit: oops, i forgot to paste the sin/cos in action, here it is, derivated from my object editor:
pawn Код:
ObjectX[o][0]=floatadd(BasisPosX,Radius*floatsin(Angle,degrees));
ObjectY[o][0]=floatadd(BasisPosY,Radius*floatcos(Angle,degrees));
Reply
#3

Thakyou very much; they are only rotating on Z axis, so, your formulae should do the trick.
Then, to recapitulate; set the main object to Z angle.
Find the X, Y, angle of the relative object and subtract them.
For example: x = 2, y = 2, a=20; then calculate the distance from 0,0 to 2,2... sqrt(2^2 + 2^2) = sqrt( = 2.82
And then the final position will be:
ObjectX[o][0]=floatadd(BasisPosX,2.82*floatsin(Angle,degrees));
ObjectY[o][0]=floatadd(BasisPosY,2.82*floatcos(Angle,degrees));
ObjectA = floatadd(BasisAngle, 20)

Am I right?

Thanks!!!
Reply
#4

instead of
pawn Код:
ObjectA = floatadd(BasisAngle, 20)
use the SetObjectPos() and SetObjectRot() function, after you assigned the calculated coordinates for the attached object. you might want to save the positions, then its faster to use the array for access to the values btw.
the sin/cos looks good. dont forget to ad some SendClientMessageToAll debug information, you will want to know whats going on, since you didnt convert the variable name i was using. if the attached obbjects' angle is the same, you dont need to calculate it again. if it needs change, you might need to calculate each objects END rotation/angle aswell:
imagine you got a curve (left bend= 45 degrees), then its center axis is rotated @ 0.0, ergo its two ends are rotated by 25.000 and -25.000 degrees. if you attach a 40 meter straight part to any end of the curve, the straight road needs to be rotated by 1/2 of the curves total rotation [fixed*] (45°/2 = 22.5° and -22.5°).
this gets worse when you attach more and more objects. i see the atan2 function ahead heheh

edit: @mp2:NahIDontLikeToUseParagraphsThankYouNeverthele ss ^^
Reply
#5

@Babul: http://www.bbc.co.uk/skillswise/fact...ing-paragraphs
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)