跳转到内容

linkcad.geom

几何模块提供用于坐标数学和形状操作的 2D 基元。

Point

2D 坐标。

from linkcad.geom import Point
p = Point(1000, 2000)
print(p.x, p.y)
属性 / 方法说明
x, y坐标分量
distance_to(other)欧几里得距离
midpoint(other)两点之间的中点
+, - operators向量算术

Vector

2D 方向/偏移。

from linkcad.geom import Vector
v = Vector(100, 200)
scaled = v * 2.0
属性 / 方法说明
x, y向量分量
length()向量长度
normalized()单位向量
dot(other)点积
cross(other)2D 叉积(标量)
*, / operators标量乘法

Transformation

2D 仿射变换(平移、旋转、缩放、镜像)。

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))
工厂方法说明
Transformation.identity()无操作变换
Transformation.translate(dx, dy)平移
Transformation.rotate(degrees)围绕原点旋转
Transformation.scale(factor)等比缩放
Transformation.scale_xy(sx, sy)非等比缩放
Transformation.mirror_x()关于 X 轴镜像
Transformation.mirror_y()关于 Y 轴镜像
方法说明
apply(point)变换一个点
apply_all(points)变换点列表
inverse()逆变换
* operator组合变换

Bounds

轴对齐边界框。

from linkcad.geom import Bounds
b = Bounds(min_x=0, min_y=0, max_x=1000, max_y=1000)
属性 / 方法说明
min_x, min_y左下角
max_x, max_y右上角
width, height尺寸
center()中心点
contains(point)点在边界内测试
intersects(other)重叠测试
union(other)合并两个边界框

Angle

角度值。用于函数接受或返回角度量的场景。

from linkcad.geom import Angle
a = Angle.from_degrees(45.0)
a = Angle.from_radians(0.785398)
工厂 / 属性说明
Angle.from_degrees(deg)从度创建
Angle.from_radians(rad)从弧度创建
angle.degrees以度表示的值
angle.radians以弧度表示的值

Resolution

控制曲线形状(圆、圆弧、椭圆)在合并等处理操作期间如何细分为多边形顶点。

from linkcad.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
属性说明
minimum_facets每个完整圆的最少多边形线段数
maximum_error相对真实曲线的最大允许偏差,以数据库单位表示