Calculate RZ from X and Y
#1

Hey.
I have some dumpster coordinates (exported from dev.prineside) and i want to re-create theese objects with the correct position. Could i calculate the RZ from the X and Y axis or i have to search for other methods?

Код:
	{2535.39, 1942.25, 10.6094},
	{2676.45, 1665.69, 10.6094},
	{2676.45, 1705.57, 10.6094},
	{2657.12, 1942.25, 10.6094},
	{2676.45, 1825.41, 10.6094},
	{2178.22, 1418.84, 10.6250},
	{2181.56, 1418.84, 10.6250},
	{1878.65, 683.77, 10.6250},
	{1881.38, 683.77, 10.6250},
	{1969.95, 693.74, 10.6250},
	{1975.70, 712.70, 10.6250},
	{2006.20, 706.45, 11.2500},
	{1884.84, 722.70, 10.6250},
	{1882.10, 722.70, 10.6250}
Reply
#2

RZ? I think that you mean Rot Z but don't understand whats ROT is this..
can you explain it better?
Reply
#3

There's no direction given from these coordinates, so it's not possible to calculate a Z rotation from that coords alone, except you want to have the Z rotation pointing from one coordinate to the other.
Reply
#4

I forget the exact name of the function in pawn, I think it's atan2 or tan2.

atan2(y2-y1,x2-x1);

Or something to that regard.
Reply
#5

Quote:
Originally Posted by Joe Staff
Посмотреть сообщение
I forget the exact name of the function in pawn, I think it's atan2 or tan2.

atan2(y2-y1,x2-x1);

Or something to that regard.
The actual implementation uses atan2(x, y) but is clockwise.

atan2(y, x) also works, but it's counter-clockwise + 90.0° (x and y vectors switched).

So if you use it like you did, you must subtract 90 from the result, or use x, y and negate it.

Код:
a = atan2(vy, vx) - 90.0
or

Код:
a = -atan2(vx, vy)
Reply
#6

Thanks for the reply dude
Anyway i don't really understand what you sayin' with my sh!t english But i tried both example that you said

Код:
a = atan2(vy, vx) - 90.0
and

Код:
DumpsterData[dumpsterid][dumpsterR] = (-atan2(X, Y) + 45.0);
and the result is almost that i want.


but if the rotation of the object has not equals to 0.0;


soo could you give me more advice to finish this? i want to 'clone' all of theese dumpsters with server sided objects.
i'm very bad in maths so im look like this now
Reply
#7

Quote:
Originally Posted by m4karow
Посмотреть сообщение
Thanks for the reply dude
Anyway i don't really understand what you sayin' with my sh!t english But i tried both example that you said

Код:
a = atan2(vy, vx) - 90.0
and

Код:
DumpsterData[dumpsterid][dumpsterR] = (-atan2(X, Y) + 45.0);
and the result is almost that i want.


but if the rotation of the object has not equals to 0.0;


soo could you give me more advice to finish this? i want to 'clone' all of theese dumpsters with server sided objects.
i'm very bad in maths so im look like this now
You cannot just use the coordinates. That gives an angle relative to the SA Map Center - 0.0, 0.0 (which is completely wrong).

You need 2 points from which you can calculate an angle (in the direction from Point A to Point B), but this condition isn't met as each Dumpster just has one set of coordinates without any info about its direction.

There is no way to tell in which direction it should be facing just from its coords. In this case you'll have to rotate them manually.
Reply
#8

Look at the all SA object array.

https://sampforum.blast.hk/showthread.php?tid=415397
Reply
#9

oh my this is what i was searching for!! thank you very much
Reply
#10

Just do something like this......

Код:
Float:GetDistanceBetweenPoints3D(Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2){
    return VectorSize(x1-x2,y1-y2,z1-z2);
}

SaveModelsInRange(modelid, Float:x, Float:y, Float:z, Float:range, file[])
{
	if(isnull(file))
	    return 0;

	new File:f, tmp[128];

	f = fopen(file, io_write);


	for(new i = 0; i < sizeof(SearchData); i++)
	{
	    if( (modelid == SearchData[i][Search_Model]) &&
			(GetDistanceBetweenPoints3D(x, y, z, SearchData[i][SearchX], SearchData[i][SearchY], SearchData[i][SearchZ]) < range) )
		{
		    format(tmp, sizeof(tmp), "{ %f, %f, %f, %f, %f, %f, %f }, \r\n",
				SearchData[i][SearchX], SearchData[i][SearchY], SearchData[i][SearchZ],
		        SearchData[i][SearchRX], SearchData[i][SearchRY], SearchData[i][SearchRZ]
		    );
		    fwrite(f, tmp);
		}
	}
	
	fclose(f);

	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)