Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Position of light sources relative to the camera?

Objects | CameraCoordinates Default Values |
---|---|

`plot::DistantLight` , `plot::PointLight` , `plot::SpotLight` | `FALSE` |

With `CameraCoordinates = FALSE`

, the coordinates
defining the position of a light are interpreted as model coordinates
in 3 space. Thus, the lights are positioned relative to the objects
in the scene. They do not move when the camera moves.

With `CameraCoordinates = TRUE`

, these coordinates
are interpreted as "camera coordinates". Thus, the lights
are attached to the camera and move automatically with the camera
when it is moved.

A vector (*x*, *y*, *z*) in
"camera coordinates" has to be interpreted as follows:

The *x*-coordinate
refers to the horizontal axis of the picture that you see in the finder
of the camera. Positive *x* values
are to your right hand side, negative *x* values
to your left hand side.

The *y*-coordinate
refers to the vertical axis of the picture that you see in the finder.
Positive *y* values
are above you, negative *y* values
below you.

The *z*-coordinate
refers to the position along the optical axis of the camera. Positive *z* values
refer to points in front of you, negative *z* values
to points behind you.

In camera coordinates, the camera position is (0, 0, 0).

For example, a point light positioned at the point (0, 1, 0) in camera coordinates is a "head lamp" fixed at a distance of 1 above the camera.

A 3D plot may contain several cameras. Changing the state of `CameraCoordinates`

for
a light affects its relation to *all* cameras of
a scene. With `CameraCoordinates`

= `TRUE`

,
the position of the light in 3 space changes, when a new camera is
chosen interactively.

We define a sphere:

sphere := plot::Spherical( [1, u, v], u = 0..2*PI, v = 0..PI, FillColorType = Functional, FillColorFunction = proc(u, v) begin [(2 + cos(2*u))/3, (2 + sin(2*u))/3, 0] end_proc):

We define sunlight shining from above:

sunlight := plot::DistantLight([0, 0, 1], [0, 0, 0]): plot(sphere, sunlight):

Next, the sunlight is defined relative to the camera. In camera
coordinates, "above the camera" is given by the `Position`

```
[0,
1, 0]
```

. Because the camera points downwards, we set the direction
of the sunlight "behind" the camera as well by choosing
the direction `[0, 1, -1.5]`

w.r.t. the camera:

sunlight := plot::DistantLight([0, 1, -1.5], [0, 0, 0], CameraCoordinates = TRUE): plot(sphere, sunlight):

delete sphere, sunlight, pointlight:

We define the same sphere as in the previous example:

sphere := plot::Spherical( [1, u, v], u = 0..2*PI, v = 0..PI, FillColorType = Functional, FillColorFunction = proc(u, v) begin [(2 + cos(2*u))/3, (2 + sin(2*u))/3, 0] end_proc):

We define an animated camera. First, we use sunlight fixed in space:

camera := plot::Camera([-3*sin(a), -3*cos(a), 2], [0, 0, 0], 0.3*PI, a = 0..2*PI): sunlight:= plot::DistantLight([0, -2, 3], [0, 0, 0]): plot(sphere, camera, sunlight):

Next, we use sunlight moving with the camera:

sunlight:= plot::DistantLight([0, 3, -2], [0, 0, 0], CameraCoordinates = TRUE): plot(sphere, camera, sunlight):

We define a point light that is fixed to some point above the camera:

pointlight := plot::PointLight([0, 1, 0], CameraCoordinates = TRUE): plot(sphere, camera, pointlight):

delete sphere, camera, sunlight, pointlight:

We define the same sphere as in the previous examples:

sphere := plot::Spherical( [1, u, v], u = 0..2*PI, v = 0..PI, FillColorType = Functional, FillColorFunction = proc(u, v) begin [(2 + cos(2*u))/3, (2 + sin(2*u))/3, 0] end_proc):

We define an animated point light that is positioned below the camera initially. It moves to some point above the camera during the animation:

pointlight := plot::PointLight([0, 10*a, 0], a = -1..1, CameraCoordinates = TRUE): plot(sphere, pointlight):

We define an animated point light that is positioned to the left of the camera initially. It moves to the right of the camera:

pointlight := plot::PointLight([10*a, 0, 0], a = -1 .. 1, CameraCoordinates = TRUE): plot(sphere, pointlight):

delete sphere, pointlight:

Was this topic helpful?