## Orientating a box to eight points

Member
Posts: 40
Joined: 2002.04
Post: #1
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 ), 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?
Moderator
Posts: 869
Joined: 2003.01
Post: #2
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 :?:
Member
Posts: 40
Joined: 2002.04
Post: #3
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?
Unregistered

Post: #4
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.
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
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.
Member
Posts: 151
Joined: 2002.09
Post: #6
...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.
Member
Posts: 40
Joined: 2002.04
Post: #7
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.