[ Prev | Index | Next ]
Japanese English

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.

Vector Components and Coordinate Systems
Vector Components and Coordinate Systems
If the reference coordinate system changes, the same position will be represented by different vector components.

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 -

void transformVector (
  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 -

void transformPolygon (
  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.
Note:
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 -

void transformModel (
  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.
Note:
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:

0.7071067811865476 0.7071067811865475 0.0

The transformed X and Y values are both equal to 1/√2, confirming that the transformation was performed correctly.



Sponsored Link



Japanese English
Index
[ Prev | Index | Next ]
News From RINEARN
* VCSSL is developed by RINEARN.

English Documentation for Our Software and VCSSL Is Now Nearly Complete
2025-06-30 - We're happy to announce that the large-scale expansion of our English documentation with the support of AI — a project that began two years ago — has now reached its initial target milestone.

VCSSL 3.4.52 Released: Enhanced Integration with External Programs and More
2025-05-25 - This update introduces enhancements to the external program integration features (e.g., for running C-language executables). Several other improvements and fixes are also included. Details inside.

Released: Latest Version of VCSSL with Fixes for Behavioral Changes on Java 24
2025-04-22 - VCSSL 3.4.50 released with a fix for a subtle behavioral change in absolute path resolution on network drives, introduced in Java 24. Details inside.

Released the Latest Versions of RINEARN Graph and VCSSL - Now Supporting Customizable Tick Positions and Labels!
2024-11-24 - Starting with this update, a new "MANUAL" tick mode is now supported, allowing users to freely specify the positions and labels of ticks on the graph. We'll explain the details and how to use it.

Released Exevalator 2.2: Now Compatible with TypeScript and Usable in Web Browsers
2024-10-22 - The open-source expression evaluation library, Exevalator, has been updated to version 2.2. It now supports TypeScript and can be used for evaluating expressions directly in web browsers. Explains the details.

Behind the Scenes of Creating an Assistant AI (Part 1: Fundamental Knowledge)
2024-10-07 - The first part of a series on how to create an Assistant AI. In this article, we introduce the essential knowledge you need to grasp before building an Assistant AI. What exactly is an LLM-based AI? What is RAG? And more.

Launching an Assistant AI to Support Software Usage!
2024-09-20 - We've launched an Assistant AI that answers questions about how to use RINEARN software and helps with certain tasks. Anyone with a ChatGPT account can use it for free. We'll explain how to use it.

Software Updates: Command Expansion in RINEARN Graph, and English Support in VCSSL
2024-02-05 - We updated our apps. This updates include "Enhancing the Command-Line Features of RINEARN Graph" and "Adding English Support to VCSSL." Dives into each of them!