Skip to content

transformations

arnholm edited this page May 1, 2017 · 1 revision

Transformations

Transformations are essential in any CSG model. They express translation, rotation, scaling and mirroring. All of these, and any combination thereof are expressed using 4x4 homogenous transformation matrices. The transformation is always UP the hierarchy, e.g. from the coordinate system of a primitive to the next level up.

Homogenous transformations

The reader is referred to the literature for the definition of homogenous coordinate transformations, but it can be useful to mention the standard form of such a transformation, as applied in XCSG. It consists of a matrix multiplication by a vector containing 4 coordinates (x,y,z,w) with a 4x4 transformation matrix, resulting in a transformed set of coordinates (x',y',z',w'). Notice that in this context the 4th coordinate is always w==1:

tmatrix

In XCSG, a 4x4 transformation matrix is identified using the <tmatrix> tag. The <tmatrix> element shall contain exactly 4 <trow> subelements, each representing a row in the matrix. The row number in the matrix is defined by the <trow> order. Each <trow> subelement has 4 attributes, c0, c1, c2 and c3 representing the 4 column values in the row.

<tmatrix>
    <trow c0="1" c1="0" c2="0" c3="40"/>
    <trow c0="0" c1="1" c2="0" c3="50"/>
    <trow c0="0" c1="0" c2="1" c3="0"/>
    <trow c0="0" c1="0" c2="0" c3="1"/>
</tmatrix>

For each of the primitives or operators described in this document, a <tmatrix> shall either be omitted or shall appear exactly once as a direct subelement (see example given for the circle primitive). When a <tmatrix> is omitted, it is equivalent to specifying the identity transformation.

Complete example with correct use of <tmatrix> to offset a cube to to x=20 and y=10

<?xml version="1.0" encoding="utf-8"?>
<xcsg version="1.0">
    <cube size="20" center="false">
        <tmatrix>
            <trow c0="1" c1="0" c2="0" c3="20"/>
            <trow c0="0" c1="1" c2="0" c3="10"/>
            <trow c0="0" c1="0" c2="1" c3="0"/>
            <trow c0="0" c1="0" c2="0" c3="1"/>
        </tmatrix>
    </cube>
</xcsg>

Clone this wiki locally