An abstract Python class for visible geometries in a custom 3D visualization scene built on top of Matplotlib's mplot3d toolkit.
A base class that allows you to create your 3D geometries to be manipulated in the same 3D scene.
Extensive styling options available to make unique a geometry, such as colors, line widths, and more.
A 3D scene to walk around your geometries with its interactive controls.
All Quick3D objects will be managed by a 3D scene that can add objects, adjust the view angle, and customize their appearance.
Create a basic 3D coordinate system with XYZ axes.
from quick3d import Scene3D # Create a new 3D scene scene = Scene3D() # Display the scene scene.show()
Create and customize 3D cubes with different styles.
from quick3d import Scene3D, Cube3D # Create a new scene scene = Scene3D() # Add a cube with default style cube1 = Cube3D(center=(-2, 0, 0), size=1) scene.add_object(cube1) # Add a cube with custom style cube2 = Cube3D(center=(0, 0, 0), size=1) custom_style = { 'facecolor': 'lightgreen', 'edgecolor': 'darkgreen', 'linewidth': 2.0, 'alpha': 0.8 } scene.add_object(cube2, style=custom_style) # Add a larger cube with transparent style cube3 = Cube3D(center=(2, 0, 0), size=1.5) transparent_style = { 'facecolor': 'lightblue', 'edgecolor': 'navy', 'linewidth': 1.0, 'alpha': 0.3, 'linestyle': '--' } scene.add_object(cube3, style=transparent_style) # Display the scene scene.show()
Customize the coordinate system axes and lighting.
$ pip install quick3d
Quick3D requires Python 3.6 or higher, and depends on matplotlib, numpy, and mpl_toolkits.
Base class for all 3D objects in the Quick3D library. Provides basic functionality for styling and rendering 3D objects with light response.
Quick3D()
facecolor - Color of the object's face (default: 'lightblue')edgecolor - Color of the object's edges (default: 'navy')linewidth - Width of the object's lines (default: 1.0)alpha - Transparency of the object (default: 0.7)linestyle - Style of the object's lines (default: '-')light_intensity - Highlight intensity (default: 0.8)shadow_color - Shadow color (default: 'darkgray')highlight_edges - Highlight edges on bright faces (default: True)Returns a reference to the object instance.
def get_instance(self) -> Quick3D
Abstract method to plot the 3D object with the specified style. Must be implemented by subclasses.
def plot(self, style: dict, ax: Axes3D, **kwargs)
style - Style dictionaryax - 3D axes to render on**kwargs - Additional keyword arguments including light parametersSets visual style properties from a dictionary.
def set_style(self, style: dict)
style - Dictionary containing style propertiesReturns current style properties as a dictionary.
def get_style(self) -> dict
Resets style properties to default values.
def reset_default_style(self)
Abstract method to get the bounding box of the object. Must be implemented by subclasses.
def get_domain(self) -> np.ndarray
Abstract method to get the centroid of the object. Must be implemented by subclasses.
def get_centroid(self) -> np.ndarray
Class for creating and managing 3D scenes with unified light source management.
Scene3D(*args, **kwargs)
objects - List of 3D objects in the scenestyles - List of style dictionaries for the objectsfig - Matplotlib figure objectax - 3D axes object_custom_axes - CustomAxes object for coordinate systemlight_direction - Light direction vector (default: (1, 1, 1))ambient_light - Ambient light intensity (0-1, default: 0.3)Adds a Quick3D object to the scene.
def add_object(self, obj: Quick3D, style: dict = None)
obj - Quick3D object to addstyle - Style dictionary for the object (optional)Displays the 3D scene with support for different axes modes.
def show(self, elev: float = 20, azim: float = -80,** kwargs)
elev - Elevation angle in degrees (default: 20)azim - Azimuth angle in degrees (default: -80)**kwargs - Additional keyword arguments including:axes - Axes mode: 'custom' (default), True, FalseSets the light direction for the scene.
def set_light_direction(self, direction: Tuple[float, float, float])
direction - Light direction vector (x, y, z)Sets the ambient light intensity for the scene.
def set_ambient_light(self, intensity: float)
intensity - Ambient light intensity (0-1)Creates and returns a CustomAxes object for the scene.
def create_custom_axes(self, style=None, **kwargs) -> CustomAxes
style - Style dictionary for the axes (optional)**kwargs - Additional keyword arguments for CustomAxesRemoves the CustomAxes object from the scene.
def remove_custom_axes(self)
Sets the style of the CustomAxes object.
def set_custom_axes_style(self, style: dict)
style - Style dictionary for the axesReturns the current style of the CustomAxes object.
def get_custom_axes_style(self) -> dict
Class for drawing customizable coordinate axes in 3D scenes.
CustomAxes(length: float = 1.0,
origin: Tuple[float, float, float] = (0, 0, 0),
**kwargs)
length - Length of the axes (default: 1.0)origin - Origin coordinates (default: (0, 0, 0))**kwargs - Additional keyword arguments for grid configuration:grid_size - Grid cell size (default: 1.0)grid_limits - Grid density (default: 8)grid_color - Grid color (default: 'gray')grid_linewidth - Grid line width (default: 0.6)grid_alpha - Grid transparency (default: 0.8)top_margin_ratio - Top margin ratio (default: 0.1)show_xy_plane - Show XY plane (default: True)show_xz_plane - Show XZ plane (default: False)show_yz_plane - Show YZ plane (default: False)plane_color - Coordinate plane color (default: 'gray')plane_alpha - Coordinate plane transparency (default: 0.2)length - Length of the axes (default: 1.0)origin - Origin coordinates (default: (0, 0, 0))x_color - Color of the X axis (default: 'red')y_color - Color of the Y axis (default: 'green')z_color - Color of the Z axis (default: 'blue')linewidth - Width of the axes lines (default: 2.0)label_fontsize - Font size for axis labels (default: 12)grid_size - Grid cell size (default: 1.0)grid_limits - Grid density (default: 8)grid_color - Grid color (default: 'gray')grid_linewidth - Grid line width (default: 0.6)grid_alpha - Grid transparency (default: 0.8)top_margin_ratio - Top margin ratio (default: 0.1)show_xy_plane - Show XY plane (default: True)show_xz_plane - Show XZ plane (default: False)show_yz_plane - Show YZ plane (default: False)plane_color - Coordinate plane color (default: 'gray')plane_alpha - Coordinate plane transparency (default: 0.2)Draws the custom axes and grid on the given 3D axes.
def plot(self, style: dict, ax: Axes3D, **kwargs)
style - Style dictionaryax - The 3D axes to draw on**kwargs - Additional keyword arguments including axes='custom'Sets visual style properties from a dictionary.
def set_style(self, style: dict)
style - Dictionary containing style propertiesReturns current style properties as a dictionary.
def get_style(self) -> dict
Returns the domain range of the axes.
def get_domain(self) -> np.ndarray
Returns the centroid of the axes.
def get_centroid(self) -> np.ndarray
A 3D cube object with light response. Inherits from Quick3D.
Cube3D(center: Tuple[float, float, float] = (0, 0, 0), size: float = 1.0)
center - Center coordinates of the cube (default: (0, 0, 0))size - Edge length of the cube (default: 1.0)center - Center coordinates of the cubesize - Edge length of the cubeface_normals - Normal vectors of the 6 facesPlots the 3D cube with the specified style and light response.
def plot(self, style: dict, ax: Axes3D, **kwargs)
style - Style dictionaryax - 3D axes to render on**kwargs - Additional keyword arguments including light parametersReturns the bounding box of the cube.
def get_domain(self) -> np.ndarray
Returns the centroid of the cube.
def get_centroid(self) -> np.ndarray
A 3D cuboid (rectangular prism) object with light response. Inherits from Quick3D.
Cuboid3D(origin: Tuple[float, float, float] = (0, 0, 0),
length: float = 2.0, # x方向长度
width: float = 1.0, # y方向宽度
height: float = 1.5, # z方向高度
origin_location: str = 'center')
origin - Origin coordinates (default: (0, 0, 0))length - Length in x direction (default: 2.0)width - Width in y direction (default: 1.0)height - Height in z direction (default: 1.5)origin_location - Origin position relative to the cuboid:'center' - Center point (default)'x_min_y_min_z_min' - Minimum x, y, z vertex'x_max_y_min_z_min' - Maximum x, minimum y, z vertex'x_min_y_max_z_min' - Minimum x, maximum y, z vertex'x_max_y_max_z_min' - Maximum x, y, minimum z vertex'x_min_y_min_z_max' - Minimum x, y, maximum z vertex'x_max_y_min_z_max' - Maximum x, minimum y, z vertex'x_min_y_max_z_max' - Minimum x, maximum y, z vertex'x_max_y_max_z_max' - Maximum x, y, z vertexorigin - Origin coordinateslength - Length in x directionwidth - Width in y directionheight - Height in z directionorigin_location - Origin position relative to the cuboidcenter - Geometric center of the cuboidface_normals - Normal vectors of the 6 facesPlots the 3D cuboid with the specified style and light response.
def plot(self, style: dict, ax: Axes3D, **kwargs)
style - Style dictionaryax - 3D axes to render on**kwargs - Additional keyword arguments including light parametersReturns the bounding box of the cuboid.
def get_domain(self) -> np.ndarray
Returns the centroid of the cuboid.
def get_centroid(self) -> np.ndarray
A 3D cylinder object with light response. Inherits from Quick3D.
Cylinder3D(center: Tuple[float, float, float] = (0, 0, 0), radius: float = 1.0, height: float = 2.0, slices: int = 32)
center - Center coordinates of the cylinder (default: (0, 0, 0))radius - Base radius of the cylinder (default: 1.0)height - Height of the cylinder (along Z-axis, default: 2.0)slices - Number of side segments (more = smoother, default: 32)center - Center coordinates of the cylinderradius - Base radius of the cylinderheight - Height of the cylinderslices - Number of side segmentsPlots the 3D cylinder with the specified style and light response.
def plot(self, style: dict, ax: Axes3D, **kwargs)
style - Style dictionaryax - 3D axes to render on**kwargs - Additional keyword arguments including light parametersReturns the bounding box of the cylinder.
def get_domain(self) -> np.ndarray
Returns the centroid of the cylinder.
def get_centroid(self) -> np.ndarray
A 3D sphere object with light response. Inherits from Quick3D.
Sphere3D(center: Tuple[float, float, float] = (0, 0, 0), radius: float = 1.0, rings: int = 20, sectors: int = 32)
center - Center coordinates of the sphere (default: (0, 0, 0))radius - Radius of the sphere (default: 1.0)rings - Number of latitude lines (more = smoother, default: 20)sectors - Number of longitude lines (more = smoother, default: 32)center - Center coordinates of the sphereradius - Radius of the sphererings - Number of latitude linessectors - Number of longitude linesPlots the 3D sphere with the specified style and light response.
def plot(self, style: dict, ax: Axes3D, **kwargs)
style - Style dictionaryax - 3D axes to render on**kwargs - Additional keyword arguments including light parametersReturns the bounding box of the sphere.
def get_domain(self) -> np.ndarray
Returns the centroid of the sphere.
def get_centroid(self) -> np.ndarray