SA-MP Forums Archive
Getting a Center point from 2 Co-ordinates - 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: Getting a Center point from 2 Co-ordinates (/showthread.php?tid=265702)



Getting a Center point from 2 Co-ordinates - Lorenc_ - 02.07.2011



Title says it all, does anyone have a solution?


Re: Getting a Center point from 2 Co-ordinates - Skylar Paul - 02.07.2011

Seems like you're going to need an algorithm.. Oh how I hate mathematics..


Re: Getting a Center point from 2 Co-ordinates - Lorenc_ - 02.07.2011

Well of course I do xD, though I don't know any particular algorithm for this...


Re: Getting a Center point from 2 Co-ordinates - Skylar Paul - 02.07.2011

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
Well of course I do xD, though I don't know any particular algorithm for this...
If I knew advanced mathematics I would help you, but I don't think I have any chance at it considering I still managed to fail Geometry, lol. Good luck finding someone.


Re: Getting a Center point from 2 Co-ordinates - Shadoww5 - 02.07.2011

Try this:

PHP код:
stock GetCenterPoint(Float:Pos1Float:Pos2)
{
    new 
Float:dist;
    if(
Pos1 Pos2) { dist Pos1+((Pos1-Pos2)/2); }
    else { 
dist Pos2+((Pos2-Pos1)/2); }
    return 
dist;

How to use:

PHP код:
public OnPlayerDeath(playeridkilleridreason)
{
    new 
Float:F[3], Float:FF[3];
    
GetPlayerPos(playeridF[0], F[1], F[2]);
    
GetPlayerPos(killeridFF[0], FF[1], FF[2]);
    new 
Float:GetCenterPoint(F[0], FF[0]);
    new 
Float:GetCenterPoint(F[1], FF[1]);
    
printf("Medium point: %f X & %f Y"XY);
    return 
1;




Re: Getting a Center point from 2 Co-ordinates - Lorenc_ - 02.07.2011

Quote:
Originally Posted by Shadoww5
Посмотреть сообщение
Try this:

PHP код:
stock GetCenterPoint(Float:Pos1Float:Pos2)
{
    new 
Float:dist;
    if(
Pos1 Pos2) { dist Pos1+((Pos1-Pos2)/2); }
    else { 
dist Pos2+((Pos2-Pos1)/2); }
    return 
dist;

How to use:

PHP код:
public OnPlayerDeath(playeridkilleridreason)
{
    new 
Float:F[3], Float:FF[3];
    
GetPlayerPos(playeridF[0], F[1], F[2]);
    
GetPlayerPos(killeridFF[0], FF[1], FF[2]);
    new 
Float:GetCenterPoint(F[0], FF[0]);
    new 
Float:GetCenterPoint(F[1], FF[1]);
    
printf("Medium point: %f X & %f Y"XY);
    return 
1;

Not for that, I want to find the center location from the X, Y to the other X, Y.

stock GetCenterPoint(Float:Pos1_X, Float:Pos1_Y, Float:Pos2_X, Float:Pos2_Y)


Re: Getting a Center point from 2 Co-ordinates - Calgon - 02.07.2011

Is this relevant?


Re: Getting a Center point from 2 Co-ordinates - Mauzen - 02.07.2011

Here it is, isnt that hard:

pawn Код:
stock GetMiddlePos(Float:x_1, Float:y_1, Float:x_2, Float:y_2, &Float:x_mid, &Float:y_mid)
{
    x_mid = (x_1 + x_2) / 2;    // Arithmetic mean value is all you need
    y_mid = (y_1 + y_2) / 2;
}



Re: Getting a Center point from 2 Co-ordinates - Sasino97 - 02.07.2011

I studied analytic geometry at school:

SR = Square Root
| = Absolute value
**2 = Squared
x1, x2, y1, y2 = The variables

PHP код:
SR[|x1-x2|**- |y1-y2|**2
-------------

EDIT: Wrong, thats the formula to find the distance , sorry.

The right formula is

PHP код:
[(x1+x2)/2], [(y1+y2)/2



Re: Getting a Center point from 2 Co-ordinates - Lorenc_ - 02.07.2011

Quote:
Originally Posted by Mauzen
Посмотреть сообщение
Here it is, isnt that hard:

pawn Код:
stock GetMiddlePos(Float:x_1, Float:y_1, Float:x_2, Float:y_2, &Float:x_mid, &Float:y_mid)
{
    x_mid = (x_1 + x_2) / 2;    // Arithmetic mean value is all you need
    y_mid = (y_1 + y_2) / 2;
}
Ill try this out and post my results (Edit this post), yes calgon, thats what i was looking for.