View Full Version : Orientating a box to eight points
Cookie
2003.05.05, 10:28 AM
I have a small problem:
I have a physics routine that moves eight particles, arranged in a box shape. Because of the nature of the physics routine, the particles don't necassarily form an exact box, but usually remain in a general box shape.
I have a 3D model of a shopping trolley (dont ask :lol:), which I need to allign to the box which best fits the eight points which represent the corners of the trolley.
I hope you all were able to decipher that description-any ideas how I would go about doing this?
I think since you have 4 edges in each x,y,z direction of local coordinates, it might be a good idea to take the average of those to be the orientation vectos in a box (easily put into a transformation matrix), and take the center to be the average position of the 8 corners. Then scale the local x,y,z coordinate vectors according to your needs, and draw the quads with vertices (1,1,1), (1,1,-1), (1,-1,-1)... (you get the idea), transformed by the generated transformation matrix. Hope this makes sense :?:
Cookie
2003.05.06, 09:45 AM
Thanks DoooG, but I already have a pre-made model of the shopping trolley, so I'm actually trying to find the correct orientation of the trolley so it best resembles the rotation of the eight particles which form a box. :sorry: sorry, its very confusing isn't it?!
Anyone else have any ideas at all?
w_reade
2003.05.06, 10:31 AM
Well, if you take one corner of the box and get the (normalised) directions to the three closest of the other corners, you should have three (basically) orthogonal vectors, representing the transformed x, y and z coordinates of the trolley. Now find the basis change matrix from the identity matrix to the matrix made of your three transformed vectors (in order), and you have your orientation matrix.
If you don't know how to do a basis change, then tough, I'm afraid. I always hated linear algebra, and even if I wanted to explain it I'd have to learn it properly again, so you'll have to seek details elsewhere. I know for sure there's sample code out there somewhere...
You could probably do it via euler angles or quaternions as well; whatever, the challenge is finding something (or a sequence of somethings) that turns (1 0 0), (0 1 0) and (0 0 1) into [transformedXvector], [transformedYvector] and [transformedZvector] respectively. Doing it backwards and then inverting the sequence might be conceptually easier to work with...
anyway, sorry for gibberish; lunch break over, got to go. Post if you don't get what I'm on about.
OneSadCookie
2003.05.06, 05:56 PM
It might be easier to use just four particles (forming a regular tetrahedron) and extract the orientation from those, rather than dealing with the full eight.
Originally posted by Cookie
...the particles don't necassarily form an exact box, but usually remain in a general box shape...
so, do you just wan't to rotate the trolley into the right direction, or do you actually want to skew the trolley to the "box"?
it's unclear to me what a general box shape is that doesn't necessarily form an exact box.
Cookie
2003.05.07, 12:38 AM
Thanks William, I'm pretty sure I understand what you are saying, I'll give it a shot when I get home tonight.
And c_dev, what I meant was that I have eight particles which represent the eight corners of a box. But because of the nature of my physics routine (damping and such), the sides of the box are not necassarily exactly orthagonal. (if that makes any more sense than before :???: ) All I'm trying to do is give the trolley object the same orientation as the box.
w_reade
2003.05.07, 04:50 AM
Hope it helps. BTW, where I mentioned coordinates, I actually meant axes, but I expect you worked that out anyway ;).
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.