# [vtkusers] Transform axes

Gib Bogle g.bogle at auckland.ac.nz
Thu Nov 6 15:32:13 EST 2014

```Hi David,

I obviously have not fully grasped the concept, although I've looked at a few examples and the vtkTransform docs.

In my test code I want to place two actors, each with its own orientation.  In the code below they are given the same orientation - the transform is intended to take the local (x,y,z) axes to global (y,z,x), and in fact the rotation I get is correct.  But I am unable to place the actors where I want.  They finish up at (0,-3,0) and (0,3,0), in other words pos[] and pos2[2] are in the rotated coordinate system.  How do I rotate the actors and set their positions in the (unchanged) global coordinates?

vx[0] = 0;
vx[1] = 1;
vx[2] = 0;
vy[0] = 0;
vy[1] = 0;
vy[2] = 1;
vz[0] = 1;
vz[1] = 0;
vz[2] = 0;
double M[4][4] = {{vx[0],vy[0],vz[0],0}, {vx[1],vy[1],vz[1],0}, {vx[2],vy[2],vz[2],0}, {0,0,0,1}};
for (int i=0; i<4; i++) {
for (int j=0; j<4; j++) {
vtkM->SetElement(i,j,M[i][j]);
}
}

pos[0] = -3; pos[1] = 0; pos[2] = 0;
transform->SetMatrix(vtkM);
actor->SetUserTransform(transform);
actor->SetOrigin(0,0,0);
actor->SetPosition(pos);

pos2[0] = 3; pos2[1] = 0; pos2[2] = 0;
transform2->SetMatrix(vtkM);
actor2->SetUserTransform(transform2);
actor2->SetOrigin(0,0,0);
actor2->SetPosition(pos2);

Thanks
Gib
________________________________
From: David Gobbi [david.gobbi at gmail.com]
Sent: Thursday, 6 November 2014 5:34 p.m.
To: Gib Bogle
Cc: vtkusers at vtk.org
Subject: Re: [vtkusers] Transform axes

Hi Gib,

for is very easy to achieve.

To transform an object from its canonical x,y,z axes onto a
new set of orthogonal axes, all you need is to set the first three
columns of a 4x4 matrix to those axes.

if the axis vectors are u, v, and w, then the transform matrix is

u_x, v_x, w_x, 0,
u_y, v_y, w_y, 0,
u_z, v_z, w_z, 0,
0, 0, 0, 1

No algebra involved!

- David

On Wed, Nov 5, 2014 at 5:47 PM, Gib Bogle <g.bogle at auckland.ac.nz<mailto:g.bogle at auckland.ac.nz>> wrote:
Hi all,

This is a 3D geometry problem, one that many people must have solved.  I want to apply a transform to my actor to bring it's local axes (which are initially aligned with the global axes) into alignment with a specified triplet of orthogonal vectors.  In fact alignment with a pair is sufficient.  I'm hoping that somebody has done this in VTK and can save me the trouble of going through the algebra.

Thanks
Gib

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20141106/3e47a4bc/attachment.html>
```