# Forum

### Author Topic: Normal Vectors of Cameras  (Read 4172 times)

#### reperry

• Newbie
• Posts: 19
##### Normal Vectors of Cameras
« on: March 23, 2017, 09:38:01 PM »
I am interested in scripting based on the camera angles. Specifically, I would like the cameras' normal vectors in the chunk coordinate system. These normals would be parallel or anti-parallel to the sticks displayed coming out of the blue rectangles.

How can I calculate these camera normal vectors?

I know the cameras each have chunk.cameras[0].transform.rotation(), but how do I go from this rotation matrix to a normal vector?

Any assistance would be greatly appreciated!

#### reperry

• Newbie
• Posts: 19
##### Re: Normal Vectors of Cameras
« Reply #1 on: March 23, 2017, 11:29:13 PM »
I am working with a turntable capture. I have a stack of four cameras, each tilted down different amounts. I have aligned my chunk so that the rings of cameras are parallel to the x-z plane and y is up through the center of the rings (see attached picture). I want to know how far each camera is tilted away from parallel to the y-axis.

Here is my failed attempt -- the script runs, but the results don't make sense:

Code: [Select]
`import mathimport PhotoScandef getTilt(chunknum=0):    chunk = PhotoScan.app.document.chunks[chunknum]        for camera in chunk.cameras:        if camera.transform is not None:            rot = camera.transform.rotation()                    #y-axis unit vector            v0 = [0.0,1.0,0.0]            #y-axis rotated by the camera rotation matrix            v1 = rot*PhotoScan.Vector(v0)            #normalize y-vector just in case            v1length = (v1[0]**2+v1[1]**2+v1[2]**2)**(1/2.)            v1 = [v/v1length for v in v1]            #determine angle between y-axis and rotated y-axis with dot product            theta = math.acos(v1[0]*v0[0]+v1[1]*v0[1]+v1[2]*v0[2])            print('angle: {} im: {}'.format(theta*180/math.pi,camera.label[0:]))if __name__ == "__main__":    getTilt(0)`

#### Alexey Pasumansky

• Agisoft Technical Support
• Hero Member
• Posts: 14965
##### Re: Normal Vectors of Cameras
« Reply #2 on: March 24, 2017, 10:43:27 AM »
Hello reperry,

If you need the orientation of the camera direction vector in the internal coordinate system, I can suggest to try the following:
Code: [Select]
`camera.transform.mulv(PhotoScan.Vector([0,0,1]))`
Best regards,
Alexey Pasumansky,
Agisoft LLC

#### reperry

• Newbie
• Posts: 19
##### Re: Normal Vectors of Cameras
« Reply #3 on: March 27, 2017, 05:22:17 PM »
It is the chunk coordinate system that I am interested in obtaining the camera vectors for. The coordinate system indicated by the x-y-z axes in my screenshot. The vectors for the bottom ring of cameras should have normal vectors with almost zero y-component. The other rings should all have negative y-components.

#### Alexey Pasumansky

• Agisoft Technical Support
• Hero Member
• Posts: 14965
##### Re: Normal Vectors of Cameras
« Reply #4 on: March 27, 2017, 06:45:11 PM »
Hello reperry,

Then you need to apply chunk transform matrix from the left to the vector in the internal system:

Code: [Select]
`v_int = camera.transform.mulv(PhotoScan.Vector([0,0,1]))v_chunk = chunk.transform.matrix.mulv(v_int)`
Best regards,
Alexey Pasumansky,
Agisoft LLC

#### reperry

• Newbie
• Posts: 19
##### Re: Normal Vectors of Cameras
« Reply #5 on: March 27, 2017, 06:54:32 PM »
Yes!!!! Perfect! Thank you!!!!

That works and makes sense. Thank you so much for the help.

For the cameras in the lowest loop, I now get the following angles between the camera vectors and my chunk y-axis:

2017-03-27 11:52:17 angle: 91.46877907090001
2017-03-27 11:52:17 angle: 91.46147001199684
2017-03-27 11:52:17 angle: 91.51786905965345
2017-03-27 11:52:17 angle: 91.55225732294619
2017-03-27 11:52:17 angle: 91.60681993768857
2017-03-27 11:52:17 angle: 91.59428129535009
2017-03-27 11:52:17 angle: 91.56908584035449
2017-03-27 11:52:17 angle: 91.56522374789431
2017-03-27 11:52:17 angle: 91.53343429406974
2017-03-27 11:52:17 angle: 91.61503578078066

which is exactly what i have been looking to see! This makes my day.