CMM-22 / a5

CMM Assignment 5 - Rigid body dynamics
0 stars 0 forks source link

[Frequent Question] What the hell are P3D and V3D? #5

Open eastskykang opened 2 years ago

eastskykang commented 2 years ago

I have to apologize first. This is indeed very confusing if you are new to our code base.

In our code base, P3D and V3D both have 3 real numbers. However, they have different meanings.

V3D represents a 3D vector. A vector has direction and magnitude. The V3D always has the same magnitude regardless of the coordinate system that is expressed in.

Meantime, P3D represents a 3D point i.e. its three numbers are x, y, z coordinates of a specific point. Thus, it's magnitude changes as the coordinate system changes which of the point's coordinates is expressed in.

There's the following relationship between P3D and V3D.

// example 
P3D startingpoint(0.1, 0.2, 0.3);
V3D vector_from_startingpoint_to_endpoint(0.5, 0.6, 0.7)
P3D endpoint = startingpoint + vector_from_startingpoint_to_endpoint; // endpoint is now (0.6, 0.8, 1.0)
// example 
P3D startingpoint(0.1, 0.2, 0.3);
P3D endpoint(0.3, 0.2, 0.1);
V3D vector_from_startingpoint_to_endpoint(startingpoint, endpoint); // vector_from_startingpoint_to_endpoint is now (0.2, 0, -0.2)

In short, if you call the function getWorldCoordinates(P3D p), it will give you the coordinates expressed in world frame that is pos + orientation * V3D(pLocal) where pos is the world position of the origin of the body frame (in RB case, it's the global position of CoM) and orientation is the orientation of the frame. (see this)

For V3D, getWorldCoordinates(P3D p) just gives you orientation * vLocal (see this)

p.s. this is a bit confusing, but it is often useful to distinguish 3D coordinates with a 3D vector to prevent potential errors.