| |
|
|
||||
![]() |
||||||
| |
|
|||||
|
The COORDINATE_FRAME type
Just as the (x,y,z) values of a vector depend on the basis you are using, the (x,y,z) values of a point in 3D space depend on which coordinate frame you are using. For instance, the (x,y,z) position you are sitting at could be specified with respect to your chair, the corner of the room, the center of the Earth, or the center of the Sun. And just like vectors, your (x,y,z) coordinates will vary depending on the orientation of the coordinate frame. In Listing 4 all that was done to create the COORDINATE_FRAME type was to derive from BASIS and add a position member (known as the origin of the frame). Deriving from BASIS will preserve the ability to transform vectors to and from the local frame and rotate the frame. Specifying an origin allows us to transform points to and from the local frame, as well as translate and position the coordinate frame. It’s important to remember that the basis and the origin are specified with respect to a parent frame. For example, if a tire’s parent is the car, the tire’s basis and position must be in car coordinates. // A coordinate frame (basis and origin) with respect to a parent // class COORD_FRAME : public BASIS { public: POINT O; //this coordinate frame’s origin, relative to its parent frame public: COORD_FRAME() {} COORD_FRAME( const POINT& o, const VECTOR& v0, const VECTOR& v1, const VECTOR& v2 ) : O ( o ), BASIS ( v0, v1, v2 ) {} COORD_FRAME( const POINT& o, const BASIS& b ) : O ( o ), BASIS ( b ) {} const POINT& position() const { return O; } void position( const POINT& p ) { O = p; } const POINT transformPointToLocal( const POINT& p ) const { //translate to this frame’s origin, then project onto this basis return transformVectorToLocal( p - O ); } const POINT transformPointToParent( const POINT& p ) const { //transform the coordinate vector and translate by this origin return transformVectorToParent( p ) + O; } //translate the origin by the given vector void translate( const VECTOR& v ) { O += v; } }; |
|
|