How to calculate this? - 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: How to calculate this? (
/showthread.php?tid=211056)
How to calculate this? -
iMonk3y - 14.01.2011
I drew a picture, because it would be difficult to explain with my own words.
Edit: orange points are supposed to be evenly spaced.
No hurries
Re: How to calculate this? -
Babul - 14.01.2011
thats a simple linear interpolation. youll be surprised how easy it is:
lets assume point 1 is the Visage Casino, and Point 2 is the Caligulas, and its (obviously wrong) coords could be:
Visage:
PX[0]=2500; PY[0]=2600;
Caligs:
PX[1]=2900; PY[1]=2400;
1) calculate the distance between point 0 to 1 (for each axis)
Код:
new Float:DistX=PX[1]-PX[0];//2900-2500= 400
new Float:DistY=PY[1]-PY[0];//2400-2600= -200
you will get the distance either as a positive or negative number, thats what we need, DistX is positive to travel to the right, and DistY is negative, as it goes down.
2) add 1 to the new points (3), thats the amount of "steps" you need to do when you intend to jump from the start to the target:
Код:
new NewPoints=3;
new Float:StepX=DistX/(NewPoints+1);//400/4= 100
new Float:StepY=DistY/(NewPoints+1);//-200/4= -50
once you got the stepsizes for each axis, you need to
3) create a loop and take the step values into account. by multiplying the step-distance by the step-number, you get the distance for each point.
Код:
for (new Steps=0;Steps<NewPoints+1;Steps++)
{
new Float:X=PX[0]+Steps*DistX;
new Float:Y=PY[0]+Steps*DistY;
new string[128];
format(string,sizeof(string),"PX:%f - PY:%f",X,Y);
SendClientMessageToAll(0xffffffff,string);
}
not tested, but done it countless times lol
Re: How to calculate this? -
iMonk3y - 14.01.2011
Thanks Babul! As simple as that
though you made a tiny mistake:
pawn Код:
for (new Steps=0;Steps<NewPoints+1;Steps++)
{
new Float:X=PX[0]+Steps*DistX; //Instead of DistX there should be StepX
new Float:Y=PY[0]+Steps*DistY; //Instead of DistY there should be StepY
new string[128];
format(string,sizeof(string),"PX:%f - PY:%f",X,Y);
SendClientMessageToAll(0xffffffff,string);
}
Again thanks thanks thanks...
Re: How to calculate this? -
Babul - 14.01.2011
OOPS! yep, indeed ^^