pyvista_js.Camera#

class pyvista_js.Camera(position: tuple[float, float, float] = (0.0, 0.0, 1.0), focal_point: tuple[float, float, float] = (0.0, 0.0, 0.0), view_up: tuple[float, float, float] = (0.0, 1.0, 0.0), view_angle: float = 30.0, clipping_range: tuple[float, float] = (0.01, 1000.01), parallel_projection: bool = False, elevation: float = 0.0)#

ベースクラス: object

Represents a virtual camera in a 3D scene.

Provides a PyVista-like API for controlling camera position, orientation, and projection settings in vtk.js scenes.

パラメータ:
  • position (tuple of float, optional) -- Camera position as (x, y, z). Default is (0, 0, 1).

  • focal_point (tuple of float, optional) -- Point the camera looks at as (x, y, z). Default is (0, 0, 0).

  • view_up (tuple of float, optional) -- View-up vector as (x, y, z). Default is (0, 1, 0).

  • view_angle (float, optional) -- Camera view angle (field of view) in degrees. Default is 30.0.

  • clipping_range (tuple of float, optional) -- Near and far clipping plane distances as (near, far). Default is (0.01, 1000.01).

  • parallel_projection (bool, optional) -- Enable parallel (orthographic) projection instead of perspective projection. Default is False.

  • elevation (float, optional) -- Camera elevation angle in degrees. Default is 0.0.

サンプル

>>> import pyvista_js as pv
>>> camera = pv.Camera()
>>> camera.position = (5, 5, 5)
>>> camera.focal_point = (0, 0, 0)
>>> plotter = pv.Plotter()
>>> _ = plotter.add_mesh(pv.Sphere())
>>> plotter.camera = camera
>>> plotter.show()
__init__(position: tuple[float, float, float] = (0.0, 0.0, 1.0), focal_point: tuple[float, float, float] = (0.0, 0.0, 0.0), view_up: tuple[float, float, float] = (0.0, 1.0, 0.0), view_angle: float = 30.0, clipping_range: tuple[float, float] = (0.01, 1000.01), parallel_projection: bool = False, elevation: float = 0.0) None#

Initialize a Camera instance.

Methods

__init__([position, focal_point, view_up, ...])

Initialize a Camera instance.

azimuth(angle)

Rotate the camera position horizontally around the focal point.

disable_parallel_projection()

Disable parallel projection (use perspective projection).

enable_parallel_projection()

Enable parallel (orthographic) projection.

orbit_elevation(angle)

Rotate the camera position vertically around the focal point.

roll(angle)

Roll the camera around the view direction axis.

zoom(factor)

Move the camera closer to or farther from the focal point.

Attributes

clipping_range

Get or set the clipping range (near, far).

elevation

Get or set the camera elevation angle in degrees.

focal_point

Get or set the camera focal point.

parallel_projection

Get or set parallel projection mode.

position

Get or set the camera position.

view_angle

Get or set the camera view angle in degrees.

view_up

Get or set the view-up vector.

azimuth(angle: float) None#

Rotate the camera position horizontally around the focal point.

パラメータ:

angle (float) -- Rotation angle in degrees. Positive values rotate counter-clockwise when viewed from above the up vector.

サンプル

>>> import pyvista_js as pv
>>> camera = pv.Camera(position=(0, 0, 5), focal_point=(0, 0, 0))
>>> camera.azimuth(90)
>>> import numpy as np
>>> np.allclose(camera.position, (5, 0, 0), atol=1e-10)
True
property clipping_range: tuple[float, float]#

Get or set the clipping range (near, far).

パラメータ:

value (tuple of float) -- Near and far clipping plane distances as (near, far).

戻り値:

Clipping range as (near, far).

戻り値の型:

tuple of float

サンプル

>>> import pyvista_js as pv
>>> camera = pv.Camera()
>>> camera.clipping_range = (0.1, 100.0)
>>> camera.clipping_range
(0.1, 100.0)
disable_parallel_projection() None#

Disable parallel projection (use perspective projection).

Switches the camera from parallel projection to perspective projection. This is equivalent to setting parallel_projection = False.

サンプル

>>> import pyvista_js as pv
>>> camera = pv.Camera()
>>> camera.enable_parallel_projection()
>>> camera.disable_parallel_projection()
>>> camera.parallel_projection
False
property elevation: float#

Get or set the camera elevation angle in degrees.

The elevation angle controls the vertical rotation of the camera. It rotates the camera about the cross product of the negative of the direction of projection and the view up vector, using the focal point as the center of rotation.

パラメータ:

value (float) -- Elevation angle in degrees.

戻り値:

Elevation angle in degrees.

戻り値の型:

float

サンプル

>>> import pyvista_js as pv
>>> camera = pv.Camera()
>>> camera.elevation
0.0
>>> camera.elevation = 45.0
>>> camera.elevation
45.0
enable_parallel_projection() None#

Enable parallel (orthographic) projection.

Switches the camera from perspective projection to parallel projection. This is equivalent to setting parallel_projection = True.

サンプル

>>> import pyvista_js as pv
>>> camera = pv.Camera()
>>> camera.enable_parallel_projection()
>>> camera.parallel_projection
True
property focal_point: tuple[float, float, float]#

Get or set the camera focal point.

パラメータ:

value (tuple of float) -- Focal point as (x, y, z).

戻り値:

Focal point as (x, y, z).

戻り値の型:

tuple of float

サンプル

>>> import pyvista_js as pv
>>> camera = pv.Camera()
>>> camera.focal_point = (1, 2, 3)
>>> camera.focal_point
(1.0, 2.0, 3.0)
orbit_elevation(angle: float) None#

Rotate the camera position vertically around the focal point.

This method is named orbit_elevation to avoid conflict with the elevation property, which stores a static angle value.

パラメータ:

angle (float) -- Rotation angle in degrees. Positive values tilt the camera upward.

サンプル

>>> import pyvista_js as pv
>>> camera = pv.Camera(position=(0, 0, 5), focal_point=(0, 0, 0))
>>> camera.orbit_elevation(90)
>>> import numpy as np
>>> np.allclose(camera.position, (0, -5, 0), atol=1e-10)
True
property parallel_projection: bool#

Get or set parallel projection mode.

When True, uses parallel (orthographic) projection instead of perspective projection. Parallel projection is useful for viewing 2D datasets, CAD-like orthographic views, and scientific visualization where perspective distortion is undesirable.

パラメータ:

value (bool) -- Enable (True) or disable (False) parallel projection.

戻り値:

Whether parallel projection is enabled.

戻り値の型:

bool

サンプル

>>> import pyvista_js as pv
>>> camera = pv.Camera()
>>> camera.parallel_projection = True
>>> camera.parallel_projection
True
property position: tuple[float, float, float]#

Get or set the camera position.

パラメータ:

value (tuple of float) -- Camera position as (x, y, z).

戻り値:

Camera position as (x, y, z).

戻り値の型:

tuple of float

サンプル

>>> import pyvista_js as pv
>>> camera = pv.Camera()
>>> camera.position = (5, 0, 0)
>>> camera.position
(5.0, 0.0, 0.0)
roll(angle: float) None#

Roll the camera around the view direction axis.

パラメータ:

angle (float) -- Roll angle in degrees.

サンプル

>>> import pyvista_js as pv
>>> camera = pv.Camera(position=(0, 0, 5), focal_point=(0, 0, 0))
>>> camera.roll(90)
>>> import numpy as np
>>> np.allclose(camera.view_up, (1, 0, 0), atol=1e-10)
True
property view_angle: float#

Get or set the camera view angle in degrees.

パラメータ:

value (float) -- View angle in degrees (field of view).

戻り値:

View angle in degrees.

戻り値の型:

float

サンプル

>>> import pyvista_js as pv
>>> camera = pv.Camera()
>>> camera.view_angle = 45.0
>>> camera.view_angle
45.0
property view_up: tuple[float, float, float]#

Get or set the view-up vector.

パラメータ:

value (tuple of float) -- View-up vector as (x, y, z).

戻り値:

View-up vector as (x, y, z).

戻り値の型:

tuple of float

サンプル

>>> import pyvista_js as pv
>>> camera = pv.Camera()
>>> camera.view_up = (0, 0, 1)
>>> camera.view_up
(0.0, 0.0, 1.0)
zoom(factor: float) None#

Move the camera closer to or farther from the focal point.

パラメータ:

factor (float) -- Zoom factor. Values greater than 1 move the camera closer (zoom in); values between 0 and 1 move it farther away (zoom out).

例外:

ValueError -- If factor is not positive.

サンプル

>>> import pyvista_js as pv
>>> camera = pv.Camera(position=(0, 0, 10), focal_point=(0, 0, 0))
>>> camera.zoom(2.0)
>>> import numpy as np
>>> np.allclose(camera.position, (0, 0, 5), atol=1e-10)
True