How is a camera/observer vector calculated in PGFPlots

image

A unit camera vector pointing toward the camera/observer can be useful for calculating e.g. background and foreground. I saw it used first time here:

Parabolic Moebius map on sphere using tikz

and I have myself used it e.g. here:

Quiver plot on surface

-just by copying the vector:

@Jasper asks in the comments how it is derived and I ask this question to make my own answer - finally doing the work myself.

The vector can be derived from definitions of cos sin and the description from the manual:

/pgfplots/view={⟨azimuth⟩}{⟨elevation⟩} (initially {25}{30}) Changes both view angles of a 3D axis. The azimuth (first argument) is the horizontal angle which is rotated around the z-axis. For a 3D plot, the z-axis always points to the top. The elevation (second argument) is the vertical rotation around the (rotated) x-axis. Positive elevation values indicate a view from above, negative a view from below. All values are measured in degree

I draw the camera vector as a red line with a circle/ball at the end. To better visualise the vector, I also draw dashed lines in the x-y plane and up to the end point. Note that this vector points directly toward the camera/observer in the two left graphs below and is therefore only seen as a circle in the origin.

With only \azimuth rotation we have:



Observing the green right angle triangle, we get:

Now we also apply an \elevation:



Observing the blue vertical right angle triangle, we get

As the hypotenuse is one, the cathetus in the x-y plane from before is scaled by cos(\elevation) and we have the result:

Considerations to what happens when cos/sin to \azimuth/\elevation changes sign needs to be done to complete the derivation.

Ask AI
#1 #2 #3 #4 #5 #6 #7 #8 #9 #10 #11 #12 #13 #14 #15 #16 #17 #18 #19 #20 #21 #22 #23 #24 #25 #26 #27 #28 #29 #30 #31 #32 #33 #34 #35 #36 #37 #38 #39 #40 #41 #42 #43 #44 #45 #46 #47 #48 #49 #50 #51 #52 #53 #54 #55 #56 #57 #58 #59 #60 #61 #62 #63 #64 #65 #66 #67 #68 #69 #70