Skip to content
Symi Docs
Python
On this page

Geometry

Exact symbolic plane geometry. Coordinates, lengths, and angles are Expression values.

Constructors#

Constructing a geometry class directly uses the shared default context. The matching Context method constructs the object in an explicit context.

point_2d#

Explicit context

point_2d(x: Any, y: Any) -> Point2d

segment_2d#

Explicit context

segment_2d(start: Point2d, end: Point2d) -> Segment2d

polygon_2d#

Explicit context

polygon_2d(vertices: list[Point2d]) -> Polygon2d

Simple polygon from its vertex list in order; degenerate inputs raise.

triangle_2d#

Explicit context

triangle_2d(
    point_a: Point2d,
    point_b: Point2d,
    point_c: Point2d,
) -> Triangle2d

Collinear vertices raise.

circle_2d#

Explicit context

circle_2d(center: Point2d, radius: Any) -> Circle2d

point_2d methods#

x#

Point2d property

x: Expression

The x coordinate of the point.

y#

Point2d property

y: Expression

The y coordinate of the point.

coordinates#

Point2d method

coordinates() -> tuple[Expression, Expression]

The (x, y) coordinate pair of the point.

distance_to#

Euclidean distance, exact (a sqrt expression in general).

Point2d method

distance_to(other: Point2d) -> Expression

Euclidean distance, exact (a sqrt expression in general).

segment_2d methods#

length#

Also the finite-set length accessor on Expression in WASM; context disambiguates.

Segment2d method

length() -> Expression

Also the finite-set length accessor on expression in WASM; context disambiguates.

midpoint#

Segment2d method

midpoint() -> Point2d

Midpoint of the segment.

perpendicular_bisector_equation#

The bisector line as an equal relation in x and y.

Segment2d method

perpendicular_bisector_equation(
    variable_x: Any,
    variable_y: Any,
) -> Expression

The bisector line as an equal relation in x and y.

polygon_2d and triangle_2d#

area#

Polygon2d method

area() -> Expression
Calling forms and variants

Variant for this object — Triangle2d method: Triangle2d.area

area() -> Expression

For a Polygon2d or Triangle2d, this is the unsigned shoelace area of the ordered boundary, so a polygon's orientation does not change its area. A circle's area is a different formula under a different owner; see Circle2d.area.

perimeter#

Polygon2d method

perimeter() -> Expression
Calling forms and variants

Variant for this object — Triangle2d method: Triangle2d.perimeter

perimeter() -> Expression

centroid#

Polygon2d method

centroid() -> Point2d
Calling forms and variants

Variant for this object — Triangle2d method: Triangle2d.centroid

centroid() -> Point2d

interior_angles#

Polygon2d method

interior_angles() -> list[tuple[Point2d, Expression]]
Calling forms and variants

Variant for this object — Triangle2d method: Triangle2d.interior_angles

interior_angles() -> list[tuple[Point2d, Expression]]

Each vertex paired with its interior angle. Notes: WASM returns VertexAngle objects with vertex/angle getters.

vertex_angle (WASM result class)#

vertex#

Not exposed by the Python bindings. Available as UniffiVertexAngle.vertex in Kotlin, UniffiVertexAngle.vertex in Swift, api::results::VertexAngle::vertex in Rust.

angle#

Not exposed by the Python bindings. Available as UniffiVertexAngle.angle in Kotlin, UniffiVertexAngle.angle in Swift, api::results::VertexAngle::angle in Rust.

circle_2d methods#

center#

Circle2d property

center: Point2d

The center of the circle.

radius#

Circle2d property

radius: Expression

The radius of the circle.

Circle2d.area#

Circle2d method

area() -> Expression

The exact disk area πr2\pi r^2, from the circle's symbolic radius. This is not the polygon and triangle shoelace operation of area above; the two share a member name and nothing else.

circumference#

Circle2d method

circumference() -> Expression

Circumference of the circle.

equation#

Circle2d method

equation(variable_x: Any, variable_y: Any) -> Expression

The circle as an equal relation in x and y.

Exact boundary intersections#

intersection#

Point2d method

intersection(other: Geometry2D) -> list[GeometryIntersectionComponent]
Calling forms and variants

Variant for this object — Circle2d method: Circle2d.intersection

intersection(other: Geometry2D) -> list[GeometryIntersectionComponent]

Variant for this object — Polygon2d method: Polygon2d.intersection

intersection(other: Geometry2D) -> list[GeometryIntersectionComponent]

Variant for this object — Segment2d method: Segment2d.intersection

intersection(other: Geometry2D) -> list[GeometryIntersectionComponent]

Variant for this object — Triangle2d method: Triangle2d.intersection

intersection(other: Geometry2D) -> list[GeometryIntersectionComponent]

Every point, segment, polygon, triangle, and circle exposes the same symmetric intersection method. Polygon and triangle operands mean their closed boundary; circle operands mean their circumference. Isolated intersections are returned as Point2d objects, while a shared edge or coincident circle is returned as the corresponding Segment2d or Circle2d component instead of sampled points. The component sequence is exact and deterministic. If any required symbolic predicate cannot be decided, the operation declines instead of returning an incomplete list. Both operands must belong to the same context.

Output#

All geometry classes also provide to_latex (and serialize_object in WASM; Python serializes through Context.serializeObject).

Example#

Geometry objects return exact symbolic measurements.

Python
import symi

context = symi.Context()
first = context.point_2d(0, 0)
second = context.point_2d(3, 4)
segment = context.segment_2d(first, second)

print(segment.length())
print(segment.midpoint().coordinates())
print(context.circle_2d(first, 2).area())

Additional API#

Circle2d#

Circle2d constructor

Circle2d(center: Point2d, radius: Any)

Construct the circle with the given center and radius.

Circle2d.getattribute#

Circle2d method

__getattribute__(name: str) -> Any

Reject attribute access on a stale object before delegating to the default lookup.

Circle2d.repr#

Circle2d method

__repr__() -> str

The repr() text, which reports staleness instead of failing.

Circle2d.is_stale#

Circle2d property

is_stale: bool

Reports whether resetting the owning context invalidated the expression. All other operations reject a stale receiver with an actionable error.

Point2d#

Point2d constructor

Point2d(x: Any, y: Any)

Construct the point (x, y).

Point2d.getattribute#

Point2d method

__getattribute__(name: str) -> Any

Reject attribute access on a stale object before delegating to the default lookup.

Point2d.repr#

Point2d method

__repr__() -> str

The repr() text, which reports staleness instead of failing.

Point2d.is_stale#

Point2d property

is_stale: bool

Reports whether resetting the owning context invalidated the expression. All other operations reject a stale receiver with an actionable error.

Polygon2d#

Polygon2d constructor

Polygon2d(vertices: list[Point2d])

Simple polygon from its vertex list in order; degenerate inputs raise.

Polygon2d.getattribute#

Polygon2d method

__getattribute__(name: str) -> Any

Reject attribute access on a stale object before delegating to the default lookup.

Polygon2d.repr#

Polygon2d method

__repr__() -> str

The repr() text, which reports staleness instead of failing.

Polygon2d.is_stale#

Polygon2d property

is_stale: bool

Reports whether resetting the owning context invalidated the expression. All other operations reject a stale receiver with an actionable error.

Segment2d#

Segment2d constructor

Segment2d(start: Point2d, end: Point2d)

Construct the segment running from start to end.

Segment2d.getattribute#

Segment2d method

__getattribute__(name: str) -> Any

Reject attribute access on a stale object before delegating to the default lookup.

Segment2d.repr#

Segment2d method

__repr__() -> str

The repr() text, which reports staleness instead of failing.

Segment2d.is_stale#

Segment2d property

is_stale: bool

Reports whether resetting the owning context invalidated the expression. All other operations reject a stale receiver with an actionable error.

Triangle2d#

Triangle2d constructor

Triangle2d(point_a: Point2d, point_b: Point2d, point_c: Point2d)

Collinear vertices raise.

Triangle2d.getattribute#

Triangle2d method

__getattribute__(name: str) -> Any

Reject attribute access on a stale object before delegating to the default lookup.

Triangle2d.repr#

Triangle2d method

__repr__() -> str

The repr() text, which reports staleness instead of failing.

Triangle2d.is_stale#

Triangle2d property

is_stale: bool

Reports whether resetting the owning context invalidated the expression. All other operations reject a stale receiver with an actionable error.

Symi documentation · Python