SA-MP Forums Archive
Mathematical Problem! Who can help me out? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Mathematical Problem! Who can help me out? (/showthread.php?tid=68640)



Mathematical Problem! Who can help me out? - Sandra18[NL] - 12.03.2009

Hi, i am not very good in maths (and english ) so i need your help.

I want to calculate some coordinates in 3d space. I think i can explain it the best with a drawing:



Lets say i know the coordinates (XYZ) of point A and point B
Now draw (virtually) a line between point A and point B (the red line).
Point C is on the red line and i know the distance between point A and point C.
How do i calculate the coordinates (XYZ) of point C

I hope someone can help me..




Re: Mathematical Problem! Who can help me out? - Marcel - 12.03.2009

As you're Dutch, so am I, this will help you out a bit:
http://www.pandd.nl/stereo/kubus.htm
This is also Dutch, and very usefull.
http://www.flashcollection4u.com/dat...pythagoras.swf


Re: Mathematical Problem! Who can help me out? - Finn - 12.03.2009

How do you calculate the distance between points A and C, if you don't know the coords of the point C?


Re: Mathematical Problem! Who can help me out? - Sandra18[NL] - 12.03.2009

Quote:
Originally Posted by Finn
How do you calculate the distance between points A and C, if you don't know the coords of the point C?
I use a default distance for example 2.0.

So basically: I want to calculate the coords of point C which is 2.0 coords away from point A, towards point B


Re: Mathematical Problem! Who can help me out? - Nubotron - 12.03.2009

Try this:
pawn Код:
/*Parameters
start[] : point A's coords
end[]  : point B's coords
lenght : distance from point A to point C
coords : array where will be stored point C's coords
*/

GetCoordsOnLine3D(Float:start[], Float:end[], Float:length, Float:coords[])
{
  coords[0] = start[0] - end[0];
  coords[1] = start[1] - end[1];
  coords[2] = start[2] - end[2];

  new Float:sqrt = floatsqroot((coords[0] * coords[0]) + (coords[1] * coords[1]) + (coords[2] * coords[2]));

  if (sqrt < 0.01)
    sqrt = 0.01;

  coords[0] = -length * (coords[0] / sqrt) + start[0];
  coords[1] = -length * (coords[1] / sqrt) + start[1];
  coords[2] = -length * (coords[2] / sqrt) + start[2];
}



Re: Mathematical Problem! Who can help me out? - Sandra18[NL] - 13.03.2009

Thanks it works!