コンテンツにスキップ

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)2 点間の中点
+, - 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)2 つの範囲をマージ

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完全な円 1 つあたりの最小ポリゴンセグメント数
maximum_error真の曲線からの最大許容偏差(データベース単位)