SA-MP Forums Archive
Math help - 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)
+--- Thread: Math help (/showthread.php?tid=343492)



Math help - Psymetrix - 17.05.2012

I need a function or just the equation to mark a position in San Andreas on a 320 x 320 textdraw map.

I've had a look through several includes but they didn't help.
The closest I've gotten is getting the position on the screen but it wasn't accurate.

If you need any more information, please say so.
Thanks.


Re: Math help - MP2 - 17.05.2012

The SA map is 6000 'units' across, so just do 320/6000 and that is one 'unit'.


Re: Math help - Psymetrix - 18.05.2012

Thanks Mike but I'm no closer. I've been at this since yesterday morning and not having any luck, at all..

Every time I get close something goes wrong. I'm terrible at maths and appreciate any more help you can give me.

Here's a picture of the maps location.



As you can see, I can't even get the marker on the map.

The top left corner is 160 from the left, 110 from the top and is 320x320.

San Andreas X:0.0000 and Y:0.0000 is 320.0000, 273.0000 on the map.
Thanks


Re: Math help - Psymetrix - 18.05.2012

Ok. So I have this:
pawn Код:
y = y - (y + y);
    posX = x / (6000/320) + 320;
    posY = (y / (6000/320) + 273);
The only problem now is that the closer to the edge of the map I get, the less accurate it becomes


AW: Re: Math help - Nero_3D - 18.05.2012

Quote:
Originally Posted by Psymetrix
Посмотреть сообщение
Ok. So I have this:
pawn Код:
y = y - (y + y);
    posX = x / (6000/320) + 320;
    posY = (y / (6000/320) + 273);
The only problem now is that the closer to the edge of the map I get, the less accurate it becomes
If you use 6000 / 320 you tell the compiler to do an integer division
And the result wouldnt be 18.75, it would be 18

pawn Код:
posX = (((3000.0 + x) / 360.0) + 160.0);
posY = (((3000.0 - y) / 360.0) + 110.0);
How did you calculated the middle, if the map is 360x360
Because if I do 160 + 360 / 2 I get 340 not 320 for x, and 290 for y

pawn Код:
posX = ((x / (6000.0 / 360.0)) + 340.0);
posY = ((y / -(6000.0 / 360.0)) + 290.0);



Re: Math help - Psymetrix - 18.05.2012

Thanks guys. It works.

@Nero_3D

This is what I ended up with:
pawn Код:
posX = ((x / (6000.0 / 320.0)) + 320.0);
    posY = ((y / -(6000.0 / 320.0)) + 270.0);
The map is 320 x 320, not 360. That was a typo in my last post, sorry.


Re: Math help - Psymetrix - 18.05.2012

It took a lot of courage to post this. I know this may seem very simple to most but math is not my strong point.