Skip to content

Geometry Drawing (functions/paint2D.py / functions/paint3D.py)

Drawing is provided by functions/paint2D.py (2D) and functions/paint3D.py (3D). Both take a list of SymPy geometry objects and return a matplotlib.figure.Figure that can be embedded directly in a QWebEngineView or any Qt container.

Function Description
draw2d(objects, figsize=(8.0,6.0), dpi=100, show_axis=True, show_grid=True, auto_scale=True, xlim=None, ylim=None, margin=0.15) Draws 2D objects such as points / lines / segments / rays / circles / triangles / polygons
draw3d(objects, figsize=(8.0,6.0), dpi=100, show_axis=True, show_grid=True, auto_scale=True, xlim=None, ylim=None, zlim=None, margin=0.15, elev=25, azim=-60) Draws 3D objects such as Point3D / Line3D / Segment3D / Ray3D / Plane

objects is a list of (sympy geometry object, style dict or None) pairs; with auto_scale=True the axis ranges are derived from the objects (plus margin). show_axis / show_grid toggle the axes and grid, and the 3D view can be rotated with elev / azim.

The style dict overrides the defaults; common keys: color, linewidth, linestyle, marker, markersize, edgecolor, facecolor, fill, alpha, label.

from sympy import Point, Line
from functions.paint2D import draw2d

fig = draw2d([
    (Point(0, 0), None),
    (Line((0, 0), (1, 1)), {"color": "red", "linewidth": 2}),
])

from sympy import Point3D, Line3D
from functions.paint3D import draw3d

fig3 = draw3d([(Point3D(0, 0, 0), {"color": "blue"})])

Note

CJK labels are rendered through matplotlib's CJK font (e.g. Microsoft YaHei) so they do not show up as boxes. All three modes of the All-in-One plot area (function / plane geometry / solid geometry) call this module. paint2D.py and paint3D.py share no drawing base class and are implemented independently.