Coordinate Transformation
This section covers how to perform coordinate transformations for vectors, polygons, and models.
Sponsored Link
What Is Coordinate Transformation?
The vector-related functions introduced in the previous section are mainly used for understanding spatial relationships between 3D objects. For example, you might want to determine where a certain position would appear from the perspective of a different coordinate system, or find the intersection between a model and a vector.
When handling positions that span multiple coordinate systems, you can't simply compare raw vector components -- you need to perform a transformation.
This is because in different coordinate systems, the origin and axis orientations generally differ. As a result, a vector pointing to the same position in space may have different component values depending on the coordinate system.
For example, the point (1, 2, 3) in one system might appear as (0, 5, 3) in another.
In other words, the component values of a vector are only meaningful in the context of the coordinate system in which it is defined. A vector and its coordinate system should always be treated as a pair.

It is often necessary to express the position indicated by a vector in one coordinate system using the components of another. This process is what we call coordinate transformation.
For instance, if you want to calculate the distance between two points that belong to different coordinate systems, you first need to transform both vectors to a common coordinate system before measuring the distance.
Transforming Vectors
- Function Format -
int vectorID, int bufferID, int coordinateID
)
Arguments:
- vectorID: The ID of the vector to transform.
- bufferID: The ID of the vector to store the transformed components. This vector must be created in advance. Its contents will be overwritten by the transformation.
- coordinateID: The ID of the target coordinate system to transform into.
Transforming Polygons
Polygons internally store vectors representing the positions of their vertices.
Therefore, to compute spatial relationships involving polygons, you need to transform all vectors that make up the polygon.
To transform a polygon, use the transformPolygon function:
- Function Format -
int polygonID, int bufferID, int coordinateID
)
Arguments:
- polygonID: The ID of the polygon to transform.
- bufferID: The ID of the polygon to store the transformed vectors. Create this polygon in advance using a function like newPolygon(int copyPolygonID) to make a copy of the source polygon.
- coordinateID: The ID of the target coordinate system.
The source and buffer polygons must be of the same type and structure. If they differ, the transformation may fail. This is why it is recommended to pass a copy of the original polygon as "bufferID."
Transforming Models
Since models are composed of many polygons, they internally contain a large number of vectors.
To compute spatial relationships involving models, you also need to transform all vectors that make up the model.
To transform a model, use the transformModel(...) function:
- Function Format -
int modelID, int bufferID, int coordinateID
)
Arguments:
- modelID: The ID of the model to transform.
- bufferID: The ID of the model to store the transformed vectors. Create this model in advance using a function like newModel(int copyModelID) to make a copy of the source model.
- coordinateID: The ID of the target coordinate system.
The number of polygons and vertices must match between modelID and bufferID. Passing a copy of the source model ensures compatibility.
Example Program
Let's create a local coordinate system, place a vector within it, and transform that vector into the world coordinate system.
Write the following code and run it:
import graphics3d.Graphics3DFramework;
import Graphics3D;
import Math; // for using the constant PI
// Function called at the start of the program
void onStart ( int rendererID ) {
// Create a local coordinate system
int coord = newCoordinate( );
// Mount it onto the world coordinate system
mountCoordinate( coord, rendererID );
// Rotate the local coordinate system 45 degrees around the Z axis
rotCoordinateZ( coord, PI/4.0 );
// Create a vector with X = 1.0
int vector = newVector( 1.0, 0.0, 0.0 );
// Place the vector on the local coordinate system
mountVector( vector, rendererID, coord );
// Create a copy of the vector to store the transformation result
int trans = newVector( vector );
// Transform the vector into the world coordinate system
transformVector(
vector, trans, getWorldCoordinate( rendererID )
);
// Output the result
println(
getVectorX( trans ), getVectorY( trans ), getVectorZ( trans )
);
}
Sample.vcssl
This program places the vector (X, Y, Z) = (1.0, 0.0, 0.0) in a local coordinate system that is rotated 45 degrees around the Z axis, then transforms it into the world coordinate system and prints the result to the VCSSL console.
When you run the program, the VCSSL console will display:
The transformed X and Y values are both equal to 1/√2, confirming that the transformation was performed correctly.
- 3D Computer Graphics
- Setting Up the Foundation
- Mouse Control and Animation
- Using the Framework
- Creating and Placing Light Sources (and Adjusting Their Properties)
- Creating and Placing Models / Standard Models
- Creating and Placing Polygons, and Various Types of Polygons
- Moving 3D Objects
- Rotating 3D Objects
- Scaling 3D Objects
- Flipping 3D Objects
- Setting Colors for 3D Objects
- Configuring the Shape of 3D Objects
- Fill Settings for 3D Objects
- Material Settings for 3D Objects
- Understanding Coordinate Systems: Concepts, Creation, and Placement
- Moving Coordinate Systems
- Walking Coordinate Systems
- Controlling the Origin Position of a Coordinate System
- Rotating Coordinate Systems
- Spinning a Coordinate System
- Euler Angle-Based Attitude Control of Coordinate Systems
- Camera Work
- Creating, Placing, and Performing Basic Operations on Vectors
- Coordinate Transformations
- Screen Projection
- Collision Detection