1
votes

My question is fairly difficult to explain, so please bear with me. I have a random object with Forward, Right, and Up vectors. Now, imagine this particular object is rotated randomly across all three axis randomly. How would I go about finding the REAL coordinates of a point relative to the newly rotated object?

Example: enter image description here

How would I, for instance, find the forward-most corner of the cube given its Forward, Right, and Up vectors (as well as its coordinates, obviously) assuming that the colored axis is the 'real' axis.

The best I could come up with is:

x=cube.x+pointToFind.x*(forward.x+right.x+up.x)
y=cube.y+pointToFind.y*(forward.y+right.y+up.y)
z=cube.z+pointToFind.z*(forward.z+right.z+up.z)

This worked sometimes, but failed when one of the coordinates for the point was 0 for obvious reasons.

In short, I don't know what do to, or really how to accurately describe what I'm trying to do... This is less of a programming questions and more of a general math question.

1
This is a simple problem if you understand anything about vectors, matricies and coordinate transformations: en.wikipedia.org/wiki/Transformation_matrixduffymo
Well, I'm not using rotation matrices to preform the rotations since that's limited to the gimbal lock (at least in my experience). I'm just using old fashion vector rotations. The major problem is, I don't know too much about any of this other than the basics.ChaseGarrett
Not limited to gimbal lock. Those are general ideas.duffymo

1 Answers

1
votes

In general, you would have to project all corners of the object, one after the other, on the target direction (i.e., compute the scalar or dot product of both vectors) and remember the point delivering the maximum value.

Because of the special structure of the cube, several simplifications are possible. You can rotate the target direction vector into the local frame. Then the determination of the maximal projection can be read off the signs of its local coordinates. If the sign of the coordinate is positive the scalar product is maximized by maximizing the cube coordinate to 1. If the sign is negative, then the scalar product is maximized by minimizing the cube coordinate to 0.

Inverse rotation is the same as forming dot products with the columns of the rotation matrix (forward, right, up), so

 result = zero-vector; //zero corner of the cube
 if( dot( target, forward ) > 0 )
      result += forward;

 if( dot( target, up ) > 0 )
      result += up;

 if( dot( target, right ) > 0 )
      result += right;