Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

Hotlink Mirror on its axis

kristkun
Participant


Hi,

Can you please help me, I'm really struggling on how can I mirror the hotlink via API.
I think this should be done by setting the hotlink element's transmat. However, I really cannot understand how to apply reflection/mirror.

I did some research and found this reference.

kristkun_0-1716228846950.png

 

 

Based on the documentation,
x' = tmx[0] * x + tmx[1] * y + tmx[2] * z + tmx[3]

y' = tmx[4] * x + tmx[5] * y + tmx[6] * z + tmx[7]

z' = tmx[8] * x + tmx[9] * y + tmx[10] * z + tmx[11]

I tried to play around with the angle and mirror settings, but I got lost in betwee.
For example,
I placed the hotlink in 45Deg not mirrored,

kristkun_1-1716229068862.pngkristkun_2-1716229072266.png

Then I placed the hotlink in 45Deg mirrored,

kristkun_3-1716229128990.pngkristkun_4-1716229132681.png

If you will notice, tmx[0] and tmx[4] were negated.
I really don't know how to know which tmx index to negate.
I would appreciate it if you could guide me on this. (Helpful reference would be very much appreciated as well)

Note:
I did check the examples in the APIv27 Kit but i don't think there is a mirror example there (only angle rotation)

 

1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Ralph Wessel
Mentor

Also, when working with matrices, keep in mind that the order of operations matters, e.g. flipping and then rotating is not the same and rotating and then flipping. Reflect that in your code, so when applying transformations B and C to matrix A:

A . B . C is not the same as C . B . A

Ralph Wessel BArch
Software Engineer Speckle Systems

View solution in original post

3 REPLIES 3
Ralph Wessel
Mentor

A matrix is transformed by multiplying it by a transformation matrix - don't think of this as just multiplying individual values. So a 4x4 matrix for a 45° rotation (A) looks like:

0.70710678118654757, -0.70710678118654746, 0, 0,
0.70710678118654746, 0.70710678118654757, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1

 

The transformation matrix to flip across the y axis (B) looks like:

-1, 0, 0, 0,
0, 1 0, 0,
0, 0, 1, 0,
0, 0, 0, 1

 

A . B looks like:

-0.70710678118654757, -0.70710678118654746, 0, 0,
-0.70710678118654746, 0.70710678118654757, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1

 

If you imagine the operations applied to a shape, mirroring also affects rotations. If you looked at a top spinning clockwise in a mirror it would appear to be spinning anti-clockwise, i.e. the mirror reverses the rotation direction. That's why you see multiple values change.

Ralph Wessel BArch
Software Engineer Speckle Systems

Thanks for the feedback.
I was able to get the equivalent transmat values based on your response by applying a combination of reflection and rotation (performed 2x2 matrix multiplication)

Solution
Ralph Wessel
Mentor

Also, when working with matrices, keep in mind that the order of operations matters, e.g. flipping and then rotating is not the same and rotating and then flipping. Reflect that in your code, so when applying transformations B and C to matrix A:

A . B . C is not the same as C . B . A

Ralph Wessel BArch
Software Engineer Speckle Systems

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!