How to calculate this?
#1

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
Reply
#2

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
Reply
#3

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...
Reply
#4

OOPS! yep, indeed ^^
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)