# 3D vector precise location calculations

I've asked this question before on stackoverflow but people told me that "It requires some pretty serious trigonometry". I'm just a silly programmer, not that smart that I even know anything about that trigonometry but I'm still willing to learn it if there is no other way. But, learning that would delay my project so much that I'm better of asking it. I know that the site doesn't actually allow people asking for things but at least a description or explanation on how to calculate it would help a lot!

To get to the main question, I've got 4 3D vector locations and the user is allowed to click anywhere between these 4 points. I've managed to get the absolute position by force the user to limit the action to a rotation of 0, 0, 0. The problem is, I don't want to force the user to make their rotation 0, 0, 0. I'll attach a picture to show you a few things, the information that comes with the image is as following:

So lets say we got these coordinates ( might be useful? ):

• Top left: 2753.8962, -2399.3669
• Top right: 2757.0393, -2399.3669
• bottom left: 2753.8962, -2409.8771
• bottom right: 2757.0393, -2409.8771
• center: 2755.4746, -2403.3447

The offsets are as following ( offsets from the center to ... ):

• Top left: -1.578533411026, 3.9779634475708
• Top right: 1.5644228458405, 3.9779634475708
• Bottom left: -1.578533411026, -6.5323362350464
• Bottom right: 1.5644228458405, -6.5323362350464
• Center: 0, 0 ( of course. )

There is a total rotation possible of 360 degrees. Any help would be very helpful! :)

update: Okay, so I took the answer from BaronVT and changed the calculation to: bx - math.cos ( rx ), by + math.cos ( ry )

It should return a value which hold the offsets from the center ( which is 0, 0 ) but it's calculating a bit wrong I guess. To make the question readable for people;

• bx = the most outer part of the bounding box ( most left part of the vehicle )
• by = the most upper part of the bounding box ( top left, together with bx )
• rx = rotation on the X-axis
• ry = rotation on the Y-axis

I'm able to get the current position of the vehicle, also where the player clicked ( they are clicking on an element, which returns an X, Y, Z too ).

I'm not sure if this is what you're asking, but if the top left corner of the unrotated truck is $(-1.58, 3.98)$, then after a counter-clockwise rotation of $\theta$ degrees, the same corner will be at

$$(-1.58\cos\theta - 3.98\sin\theta, -1.58\sin\theta + 3.98\cos\theta)$$

(i.e. $(x,y)$ winds up at $(x\cos\theta - y\sin\theta, x\sin\theta + y\cos\theta)$, see rotation matrices for more information)

EDIT: after further conversation with OP, we determined that what he wanted to do was, after rotating the truck, click a location on the screen, and then find what location that corresponds to in the unrotated truck. Of course, this is just a rotation by $-\theta$ and after figuring that out, the rest was straightforward.

• You mean, if the truck rotates 360 degrees, the same location which was -1.58, 3.98 will be the same as the calculation you gave me? What if the truck only rotates 45 degrees? The - and + should be flipped. Am I right? – Tosfera Jan 15 '15 at 18:50
• I mean, for any angle $\theta$, that calculation will tell you where a point is after rotating the entire plane about the center by that angle. The formula I gave, with $\theta = 45°$, will put that corner of the truck at $(-3.93,1.70)$. – BaronVT Jan 15 '15 at 18:58
• Ah! That clears some question marks! I'll grab my source tonight and try it out! :) – Tosfera Jan 15 '15 at 18:59
• Edited my question, it doesn't rly work like I expected. If you would need any more information, just ask! – Tosfera Jan 17 '15 at 23:47
• Hi again, sorry for the late response. It doesn't look like the code you have implements the calculation I suggest. What do you mean by 'rotation on the x-axis' and 'rot. on the y-axis'? There is only one rotation, by an angle theta. In code, the new corner should be at (bx*math.cos(theta) - by*math.sin(theta), bx*math.sin(theta) + by*math.cos(theta) – BaronVT Jan 20 '15 at 17:11