Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: MetaUser555 on October 13, 2015, 09:53:26 PM

Title: Rotate Region by a specific angle
Post by: MetaUser555 on October 13, 2015, 09:53:26 PM
Hi,
I'm new to python and i'm trying to rotate my region by a specified angle.
I'm stuck on how to do this with my limited python skills!
would someone steer me in the right direction?
Here's what i have at the moment - i seem to be able to reset my region (now commented out) but not rotate it.
Ideally i want to rotate in a direction by 90 degrees.
thanks for your help!

Code: [Select]
import PhotoScan
import math

doc = PhotoScan.app.document
chunk = doc.chunks[0]
reg = chunk.region

#<---- Rotation ---- i've put random numbers in here>
reg.rot = PhotoScan.Matrix( [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]] ).t

#chunk.resetRegion()


print (reg.rot)
print (doc.chunks[0])
Title: Re: Rotate Region by a specific angle
Post by: Alexey Pasumansky on October 14, 2015, 03:00:49 PM
Hello bolegna,

Are you working with the referenced chunks or not?
Title: Re: Rotate Region by a specific angle
Post by: MetaUser555 on October 14, 2015, 07:06:02 PM
Hi Alexey,
It's just a standard chunk, nothing special.
cheers
Title: Re: Rotate Region by a specific angle
Post by: Alexey Pasumansky on October 14, 2015, 07:10:07 PM
In this case you can multiple the rotation matrix of the region (region.rot) by the rotation matrices that perform the rotation around each axis.

         |  1  0  0 |
    X  = |  0  A -B |
         |  0  B  A |

         |  C  0 -D |
    Y  = |  0  1  0 |
         |  D  0  C |

         |  E -F  0 |
    Z  = |  F  E  0 |
         |  0  0  1 | 

where
A, B - cos and sin of the rotation angle around X,
C, D - cos and sin of the rotation angle around Y,
E, F - cos and sin of the rotation angle around Z.

So for 90 degree rotation matrices will be the following:
xm = PhotoScan.Matrix( [[1,0,0],[0,0,-1],[0,1,0]] )
ym = PhotoScan.Matrix( [[0,0,-1],[0,1,0],[1,0,0]] )
zm = PhotoScan.Matrix( [[0,-1,0],[1,0,0],[0,0,1]] )

Hope it helps.
Title: Re: Rotate Region by a specific angle
Post by: tonik on March 21, 2019, 02:03:42 PM
Hello,

I would like to modify this script:

https://github.com/agisoft-llc/metashape-scripts/blob/master/src/bounding_box_to_coordinate_system.py

I want ability to rotate bounding box in Z-axis (around center). With angles if possible. Would be cool if script ask user to give certain angle for Z-axis (0-360).
My projects are in real world referenced coordinates.

I have tried to solve this, but I have no luck so far. Can somebody help me how to solve this? I'm not very good with scripting.

Thanks!