Skip to main content
Solved

how do you formulate rotation in a transformation matrix?

  • October 18, 2025
  • 5 replies
  • 103 views

lmo_rott
Contributor
Forum|alt.badge.img+5

Hello, the workspace is close to “Creating CityGML Solitary Vegetation Object | Community” but without the issues. 
I would like to randomly rotate the instances along the Z axis. Dimensions are set as in the first matrix shown below. When I use the last row to rotate, as shown in the second matrix below, the rotation is ignored and dimensions change. I tried the rotators, and the 3D affiner after defining the matrix to no good results. It seems that CityGML only looks at the transformation matrix.  Any advise or workaround to force instance’s rotation is appreciated. I have a random rotation value stored in an attribute brought as an attribute of the location point. 

+++++ Matrix withOUT rotation +++++++++++

@Value(width) 0.0 0.0 0.0

0.0 @Value(width2) 0.0 0.0

0.0 0.0 @Value(height) 0.0

0.0 0.0 0.0 1.0

+++++ Matrix “WITH” rotation? +++++++++

@Value(width) 0.0 0.0 0.0

0.0 @Value(width2) 0.0 0.0

0.0 0.0 @Value(height) 0.0

0.0 0.0 0.0 @Value(rotation)

 

Best answer by virtualcitymatt

Here is an example I use - scale it the scale factor and the other 4 values I’ll explain below 

@Value(1-1) @Value(1-2) 0.0 0.0
@Value(2-1) @Value(1-1) 0.0 0.0
0.0 0.0 @Value(SCALEZ) 0.0
0.0 0.0 0.0 1.0

Rotation angle needs to be in radians e.g.,

((2*@pi())/360)*@Value(ROTATION)

1-1 = 

@Value(SCALEZ)*(@cos(@Value(_radians)))

1-2 = 

@Value(SCALEZ)*(-@sin(@Value(_radians)))

2-1 =

@Value(SCALEZ)*(@sin(@Value(_radians)))

In this case the scale applied is the same strength in each direction.

I think it’s probably easier to do all this stuff with a python caller and numpy.

You can also get it looking correct in FME and then use FME python to extract the transformation matrix from the fme object directly
 

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

5 replies

max_h
Supporter
Forum|alt.badge.img+19
  • Supporter
  • October 20, 2025

A rotation matrix looks a bit different: Rotation matrix - Wikipedia

In your case this should work:
@cos(@Value(rotation)) @mult(-1, @sin(@Value(rotation))) 0.0 0.0
@sin(@Value(rotation)) @cos(@Value(rotation))  0.0 0.0
0.0 0.0 @Value(height)  0.0
0.0 0.0 0.0 1.0

 


lmo_rott
Contributor
Forum|alt.badge.img+5
  • Author
  • Contributor
  • October 20, 2025

Hi Max, sorry I was not clear in my question. Yes, I know that is the rotation matrix, but I need to use the transformation matrix also to give height and width and then rotate each randomly. So both transfomrations matrices need to be combined into one which is why I was asking about the last row where I thought rotation could be added. I will try multiplying the two matrices. Your @mult() gave me the idea. Thanks.. I will report if it works. 🤞


virtualcitymatt
Celebrity
Forum|alt.badge.img+47
  • Celebrity
  • Best Answer
  • October 21, 2025

Here is an example I use - scale it the scale factor and the other 4 values I’ll explain below 

@Value(1-1) @Value(1-2) 0.0 0.0
@Value(2-1) @Value(1-1) 0.0 0.0
0.0 0.0 @Value(SCALEZ) 0.0
0.0 0.0 0.0 1.0

Rotation angle needs to be in radians e.g.,

((2*@pi())/360)*@Value(ROTATION)

1-1 = 

@Value(SCALEZ)*(@cos(@Value(_radians)))

1-2 = 

@Value(SCALEZ)*(-@sin(@Value(_radians)))

2-1 =

@Value(SCALEZ)*(@sin(@Value(_radians)))

In this case the scale applied is the same strength in each direction.

I think it’s probably easier to do all this stuff with a python caller and numpy.

You can also get it looking correct in FME and then use FME python to extract the transformation matrix from the fme object directly
 


lmo_rott
Contributor
Forum|alt.badge.img+5
  • Author
  • Contributor
  • October 21, 2025

Hi, I have it working now! yeeeeey 😁 . Below is the matrix that worked for me in terms of Matt’s example. 

After converting the angle to radians, I had to  use the mult() function.  Using * for multiplication causes a matrix that is not be properly read when converting to 3D tiles. 

@mult(@Value(SCALEZ),@cos(@Value(_rotatnAngl))) @mult(@Value(SCALEZ),-@sin(@Value(_rotatnAngl))) 0.0 0.0
@mult(@Value(SCALEZ),@sin(@Value(_rotatnAngl))) @mult(@Value(SCALEZ),@cos(@Value(_rotatnAngl))) 0.0 0.0
0.0 0.0 @Value(SCALEZ) 0.0
0.0 0.0 0.0 1.0

I hope this helps others, as well.  Thanks!


danilo_fme
Celebrity
Forum|alt.badge.img+51
  • Celebrity
  • October 21, 2025

Here is an example I use - scale it the scale factor and the other 4 values I’ll explain below 

@Value(1-1) @Value(1-2) 0.0 0.0
@Value(2-1) @Value(1-1) 0.0 0.0
0.0 0.0 @Value(SCALEZ) 0.0
0.0 0.0 0.0 1.0

Rotation angle needs to be in radians e.g.,

((2*@pi())/360)*@Value(ROTATION)

1-1 = 

@Value(SCALEZ)*(@cos(@Value(_radians)))

1-2 = 

@Value(SCALEZ)*(-@sin(@Value(_radians)))

2-1 =

@Value(SCALEZ)*(@sin(@Value(_radians)))

In this case the scale applied is the same strength in each direction.

I think it’s probably easier to do all this stuff with a python caller and numpy.

You can also get it looking correct in FME and then use FME python to extract the transformation matrix from the fme object directly
 

Great solution!