Skip to content

linkcad.geom

The geometry module provides 2D primitives for coordinate math and shape manipulation.

Classes

Point

A 2D coordinate.

from linkcad.geom import Point

p = Point(1000, 2000)
print(p.x, p.y)
Property / Method Description
x, y Coordinate components
distance_to(other) Euclidean distance
midpoint(other) Midpoint between two points
+, - operators Vector arithmetic

Vector

A 2D direction/offset.

from linkcad.geom import Vector

v = Vector(100, 200)
scaled = v * 2.0
Property / Method Description
x, y Vector components
length() Vector magnitude
normalized() Unit vector
dot(other) Dot product
cross(other) 2D cross product (scalar)
*, / operators Scalar multiplication

PointArray

An ordered sequence of points, used for polygon and polyline vertices.

from linkcad.geom import PointArray

pts = PointArray([(0, 0), (1000, 0), (1000, 1000), (0, 1000)])
Property / Method Description
len(pts) Number of points
pts[i] Access by index
area() Signed area (polygons)
bounds() Bounding box
reversed() Reversed copy

Transformation

A 2D affine transformation (translation, rotation, scaling, mirroring).

from linkcad.geom import Transformation

t = Transformation.translate(1000, 2000)
t = Transformation.rotate(45.0)  # degrees
t = Transformation.scale(2.0)
t = Transformation.mirror_x()

combined = t1 * t2  # compose transformations
pt = t.apply(Point(0, 0))
Factory Method Description
Transformation.identity() No-op transform
Transformation.translate(dx, dy) Translation
Transformation.rotate(degrees) Rotation around origin
Transformation.scale(factor) Uniform scaling
Transformation.scale_xy(sx, sy) Non-uniform scaling
Transformation.mirror_x() Mirror about X axis
Transformation.mirror_y() Mirror about Y axis
Method Description
apply(point) Transform a point
apply_all(points) Transform a list of points
inverse() Inverse transformation
* operator Compose transformations

Bounds

An axis-aligned bounding box.

from linkcad.geom import Bounds

b = Bounds(min_x=0, min_y=0, max_x=1000, max_y=1000)
Property / Method Description
min_x, min_y Lower-left corner
max_x, max_y Upper-right corner
width, height Dimensions
center() Center point
contains(point) Point-in-bounds test
intersects(other) Overlap test
union(other) Merge two bounds