Skip to content

linkcad.geom

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

Classes

Point

A 2D coordinate.

from linkcad.v1.geom import Point
p = Point(1000, 2000)
print(p.x, p.y)
Property / MethodDescription
x, yCoordinate components
distance_to(other)Euclidean distance
midpoint(other)Midpoint between two points
+, - operatorsVector arithmetic

Vector

A 2D direction/offset.

from linkcad.v1.geom import Vector
v = Vector(100, 200)
scaled = v * 2.0
Property / MethodDescription
x, yVector components
length()Vector magnitude
normalized()Unit vector
dot(other)Dot product
cross(other)2D cross product (scalar)
*, / operatorsScalar multiplication

Transformation

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

from linkcad.v1.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 MethodDescription
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
MethodDescription
apply(point)Transform a point
apply_all(points)Transform a list of points
inverse()Inverse transformation
* operatorCompose transformations

Bounds

An axis-aligned bounding box.

from linkcad.v1.geom import Bounds
b = Bounds(min_x=0, min_y=0, max_x=1000, max_y=1000)
Property / MethodDescription
min_x, min_yLower-left corner
max_x, max_yUpper-right corner
width, heightDimensions
center()Center point
contains(point)Point-in-bounds test
intersects(other)Overlap test
union(other)Merge two bounds

Angle

An angle value. Used where functions accept or return angular quantities.

from linkcad.v1.geom import Angle
a = Angle.from_degrees(45.0)
a = Angle.from_radians(0.785398)
Factory / PropertyDescription
Angle.from_degrees(deg)Create from degrees
Angle.from_radians(rad)Create from radians
angle.degreesValue in degrees
angle.radiansValue in radians

Resolution

Controls how curved shapes (circles, arcs, ellipses) are tessellated into polygon vertices during processing operations such as merge.

from linkcad.v1.geom import Resolution
res = Resolution()
res.minimum_facets = 32 # at least 32 segments per full circle
res.maximum_error = 1 # max deviation in database units
PropertyDescription
minimum_facetsMinimum number of polygon segments per full circle
maximum_errorMaximum allowed deviation from the true curve, in database units