svg_path_editor.geometry#
Classes#
2D point with |
|
2D vector with SymPy coordinates. |
|
\(2×2\) matrix |
|
Line segment from |
|
Elliptical arc in parametric form. |
Functions#
|
Rotation matrix for angle \(φ\) in degrees. |
|
Compute the dot product of two 2D vectors. |
|
Signed area of a simple polygon. |
Module Contents#
- svg_path_editor.geometry.rotation_matrix(phi)[source]#
Rotation matrix for angle \(φ\) in degrees.
Uses
\[\begin{split}R(φ) = \begin{pmatrix} \cos φ & -\sin φ \\ \sin φ & \cos φ \end{pmatrix},\end{split}\]where \(\cos\) and \(\sin\) are evaluated after converting \(φ\) from degrees to radians via
sympy.rad().
- class svg_path_editor.geometry.Point(x, y)[source]#
2D point with
decimal.Decimalcoordinates.- x: decimal.Decimal#
- y: decimal.Decimal#
- __ne__(value, /)[source]#
Compare coordinates for inequality.
- Parameters:
value (object)
- Return type:
bool
- property vec2: Vec2#
Exact conversion to
Vec2.Coordinates are converted to SymPy rationals via
dec_to_rat().- Return type:
- property length: decimal.Decimal#
Euclidean norm \(‖v‖_2 = \sqrt{x^2 + y^2}\).
- Return type:
decimal.Decimal
- property normalized: Point#
Unit vector \(v / ‖v‖_2\).
The zero vector is returned unchanged.
- Return type:
- class svg_path_editor.geometry.Vec2[source]#
2D vector with SymPy coordinates.
Supports exact arithmetic and simple linear operations.
- static from_point(p)[source]#
Construct a
Vec2from aPoint.Coordinates are converted to SymPy rationals via
dec_to_rat().
- property point: Point#
Convert to numeric
Point.Uses
rat_to_dec()to convert SymPy expressions toDecimal.- Return type:
- __eq__(other)[source]#
Equality comparison between
Vec2instances,Falsewhen comparing to non-Vec2.- Parameters:
other (object)
- Return type:
bool
- __ne__(value, /)[source]#
Inequality comparison between
Vec2instances,Falsewhen comparing to non-Vec2.- Parameters:
value (object)
- Return type:
bool
- svg_path_editor.geometry.dot(v1: Point, v2: Point) decimal.Decimal[source]#
- svg_path_editor.geometry.dot(v1: Vec2, v2: Vec2) Expr
Compute the dot product of two 2D vectors.
- class svg_path_editor.geometry.Mat2[source]#
\(2×2\) matrix
\[\begin{split}M = \begin{pmatrix} a & b \\ c & d \end{pmatrix}\end{split}\]acting on
Vec2by standard matrix-vector multiplication.- Variables:
a – Entry \(a_{11}\).
b – Entry \(a_{12}\).
c – Entry \(a_{21}\).
d – Entry \(a_{22}\).
- svg_path_editor.geometry.polygon_signed_area(poly)[source]#
Signed area of a simple polygon.
Uses the shoelace formula
\[A = \frac12 \sum_i (x_i y_{i+1} - x_{i+1} y_i),\]with positive area for counter-clockwise vertex order.
- class svg_path_editor.geometry.Line(p, q)[source]#
-
Parametric form
\[L(t) = p + (q - p)\,t, \quad t \in \mathbb{R}.\]- inward_normal(is_ccw)[source]#
Unit inward normal.
For a CCW-oriented boundary, the inward normal is obtained by rotating the edge direction \((Δx, Δy)\) 90° clockwise; for a CW boundary, by rotating 90° counter-clockwise:
\[\begin{split}n = \begin{cases} (Δy, -Δx) & \text{if CCW} \\ (-Δy, Δx) & \text{if CW} \end{cases}\end{split}\]The resulting vector is then normalized.
- Parameters:
is_ccw (bool) –
Trueif the enclosing polygon is CCW oriented.- Return type:
- offset(*, d, is_ccw, n=None)[source]#
Offset the line along its inward normal by distance
d.Both endpoints are translated by \(d ⋅ n_{\mathit{in}}\).
- Parameters:
d (Expr) – Signed offset distance.
is_ccw (bool) – Orientation of the surrounding boundary.
n (Precision | None) – Optional precision used in
Vec2.evalf().
- Return type:
- class svg_path_editor.geometry.ParametricEllipticalArc[source]#
Elliptical arc in parametric form.
The underlying full ellipse is
\[\begin{split}E(θ) &= R(φ) ⋅ \begin{pmatrix} r_x \cos θ \\ r_y \sin θ \end{pmatrix} + \begin{pmatrix} c_x \\ c_y \end{pmatrix}\end{split}\]where \(θ\) and \(φ\) are in degrees and \((c_x, c_y)\) is the center.
This arc covers the interval \([θ_0, θ_0 + Δθ]\) modulo \(360°\).
- Variables:
c – Center \((c_x, c_y)\).
r – Radii \((r_x, r_y)\).
theta0 – Start angle \(θ_0\) in degrees.
dtheta – Sweep \(Δθ\) in degrees (signed).
phi – Rotation angle \(φ\) in degrees.
- locally_convex(*, is_ccw)[source]#
Test if the arc is locally convex with respect to the boundary orientation.
- Returns:
Trueiff the interior lies on the convex side of the arc for a boundary with orientationis_ccw.- Parameters:
is_ccw (bool)
- Return type:
bool
- offset(*, d, is_ccw, n=None)[source]#
Offset the arc by changing its radii.
\(d > 0\): move inward
\(d < 0\): move outward
“Inward” is defined with respect to the polygon orientation: for a CCW boundary, the interior is to the left of the path, for a CW boundary to the right.
- Parameters:
d (Expr) – Signed offset distance applied to both radii.
is_ccw (bool) – Orientation of the surrounding boundary.
n (Precision | None) – Unused; kept for API symmetry with
Line.offset().
- Return type:
- angle_condition(theta: Symbol, *, n: Precision | None = None) Boolean[source]#
- angle_condition(theta: Expr, *, n: Precision | None = None) Boolean
Test whether
theta(in degrees) lies on this arc, modulo 360°.Works for positive and negative \(Δθ\) and wrap-around intervals.
- Parameters:
theta – Angle to test, interpreted in degrees.
n – Optional precision passed to
evalf(),ge(), andle().
- point_tangent(theta, n=None)[source]#
Point and tangent at parameter
theta(in degrees).Returns \((p(θ), ±p'(θ))\), where the derivative is w.r.t. \(θ\) in degrees and not normalized. The sign of the derivative is chosen so that the tangent at \(θ_0\) points along the arc and that at \(θ_1\) points away from the arc.
- transform(p, *, inverse=False)[source]#
Affine map between unit circle and this ellipse.
inverse=False: \((u, v) \mapsto (x, y)\) on the ellipse.inverse=True: \((x, y) \mapsto (u, v)\) on the unit circle.
The forward mapping is
\[(x, y) = c + R(φ)\,\mathrm{diag}(r_x, r_y)\,(u, v),\]where all angles are in degrees.