Orientating a box to eight points
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 descriptionany ideas how I would go about doing this?
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 descriptionany 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 :?:
Thanks DoooG, but I already have a premade 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?
Anyone else have any ideas at all?
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.
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.
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.
Quote: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.
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.
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.
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
Two gluProject points?  mikey  5  5,056 
Jan 5, 2012 01:03 PM Last Post: mikey 

surface rendering from data points  mc1961  6  5,051 
Nov 15, 2007 03:37 PM Last Post: TomorrowPlusX 

ordering of control points in glMap1f(...data)  WhatMeWorry  10  6,916 
Mar 11, 2006 08:36 PM Last Post: WhatMeWorry 

Cocoa and OpenGL entry points?  napthali  5  3,983 
Dec 31, 2003 06:22 PM Last Post: AnotherJake 

Selecting 3D Points  BlueAvian  4  2,873 
Oct 7, 2003 10:57 AM Last Post: Johan 