latentspace.

Local coordinate system

Types of coordinate systems: Global vs. Local

In engineering, computer graphics, and physics, understanding the relationship between different coordinate systems is essential for accurate modeling, simulation, and analysis. The attached figure describes the concept of a global coordinate system (GCS) and a local coordinate system (LCS), both of which are commonly used to define the position and orientation of objects in 3D space.

The GCS is represented by the axes x , y , and z . This system provides a fixed reference for describing the location of all objects within the space. In contrast, the LCS, denoted by the axes x' , y' , and z' , is tied to a specific object within the GCS. It moves and rotates with the object, providing a reference frame that is local to the object itself.

Global coordinate system and local coordinate system
Global coordinate system and local coordinate system

These transformations between coordinate systems are governed by rotation matrices or transformation matrices that contain the cosine and sine functions of the angles between the axes.

Simple implementation of Plane2d

The Plane2d class defines the origin, x-axis, and y-axis as the properties of a 2D coordinate system. In this class that I implemented, the core functions are as follows:

    class Plane2d(AxesVisualizer):
        def __init__(self, origin: np.ndarray, x_axis: np.ndarray, y_axis: np.ndarray, normalize: bool = True):
            self._origin = origin
            self._x_axis = x_axis / np.linalg.norm(x_axis) if normalize else x_axis
            self._y_axis = y_axis / np.linalg.norm(y_axis) if normalize else y_axis
            
    
        def _get_local_coords_matrix(self) -> np.ndarray:
            """Returns a local coordinate matrix expressed in homogeneous coordinates

            Returns:
                np.ndarray: local coordinates of self
            """
            
            return np.array(
                [
                    [self.x_axis[0], self.y_axis[0], self.origin[0]],
                    [self.x_axis[1], self.y_axis[1], self.origin[1]],
                    [0, 0, 1],
                ]
            )
        
        def get_converted_geometry_by_plane(self, plane_to_convert: Plane2d, geometry_to_convert: GeometryCollection) -> GeometryCollection:
            """Converts a given geometry from one plane to another

            Args:
                plane_to_convert (Plane2d): Target plane to convert the coordinate system
                geometry_to_convert (GeometryCollection): Geometry of Shapely to convert

            Returns:
                GeometryCollection: Converted geometry
            """
            
            matrix_to_map_global_coords = np.linalg.inv(self._get_local_coords_matrix())
            matrix_to_map_local_coords = plane_to_convert._get_local_coords_matrix() @ matrix_to_map_global_coords

            return affinity.affine_transform(
                geom=geometry_to_convert,
                matrix=[
                    matrix_to_map_local_coords[0][0], 
                    matrix_to_map_local_coords[0][1],
                    matrix_to_map_local_coords[1][0], 
                    matrix_to_map_local_coords[1][1],
                    matrix_to_map_local_coords[0][2],
                    matrix_to_map_local_coords[1][2],
                ]
            )

The figure below illustrates the transformation process.

First, the inverse of a transformation matrix must be taken to convert a polygon from the original plane to another. This step corresponds to the transition from the blue polygon to the black polygon, and to the code line matrix_to_map_global_coords = np.linalg.inv(self._get_local_coords_matrix()) above. Through this step, the polygon in the local coordinate system is mapped to the global coordinate system, which treats (0, 0) as the origin.

After this step, the polygon must be remapped from the global coordinate system to the target local coordinate system. This corresponds to the transition from the black polygon to the green polygon. The line matrix_to_map_local_coords = plane_to_convert._get_local_coords_matrix() @ matrix_to_map_global_coords corresponds to this step.

Throughout the entire transformation process, the polygon preserves the same vertex indices, geometry shape, and orientation (counter-clockwise in this case).
Simple implementation of Plane2d Simple implementation of Plane2d
Coordinate system transformation process

Applying coordinate system transformation in Architectural design

As shown above, the transformation from GCS to LCS involves rotation, translation, and reflection matrices that convert a geometry's coordinates to its position and orientation within the plane.

In architectural design, a transformation matrix can help align building shapes along intended angles and directions within an axial framework. For example, consider an algorithm developed to automate apartment layout, given a set of building templates. In this situation, the buildings can be placed simply along a given axis defined for arranging the apartments.

The logic described above is applied after defining two planes and the geometries for the apartments.
Applying it in apartment design automation (1 of 4) Applying it in apartment design automation (2 of 4) Applying it in apartment design automation (3 of 4) Applying it in apartment design automation (4 of 4)
Applying it in apartment design automation


References