🐛 fix line.cal_intersection

This commit is contained in:
2024-08-28 04:22:22 +08:00
parent 5f4adbb75f
commit ab17af3fda
7 changed files with 178 additions and 7 deletions

View File

@@ -12,6 +12,7 @@ import math
from typing import overload
from .const import PI # type: ignore
from .utils import approx
class AnyAngle:
@@ -129,12 +130,21 @@ class AnyAngle:
def __add__(self, other: 'AnyAngle') -> 'AnyAngle':
return AnyAngle(self.radian + other.radian, is_radian=True)
def __eq__(self, other):
return approx(self.radian, other.radian)
def __sub__(self, other: 'AnyAngle') -> 'AnyAngle':
return AnyAngle(self.radian - other.radian, is_radian=True)
def __mul__(self, other: float) -> 'AnyAngle':
return AnyAngle(self.radian * other, is_radian=True)
def __repr__(self):
return f"AnyAngle({self.radian}, is_radian=True)"
def __str__(self):
return f"AnyAngle({self.degree}° or {self.radian} rad)"
@overload
def __truediv__(self, other: float) -> 'AnyAngle':
...

View File

@@ -64,14 +64,23 @@ class Line3:
Returns:
距离
Raises:
ValueError: 直线不平行
TypeError: 不支持的类型
"""
if isinstance(other, Line3):
if self.is_parallel(other):
return (self.point - other.point).cross(self.direction).length / self.direction.length
# 相交/重合 = 0平行和异面需要计算距离
if self == other:
# 重合
return 0
elif self.is_parallel(other):
# 平行
return (other.point - self.point).cross(self.direction).length / self.direction.length
elif not self.is_coplanar(other):
# 异面
return abs(self.direction.cross(other.direction) @ (self.point - other.point) / self.direction.cross(other.direction).length)
else:
raise ValueError("Lines are not parallel.")
# 相交
return 0
elif isinstance(other, Point3):
return (other - self.point).cross(self.direction).length / self.direction.length
else:

View File

@@ -6,10 +6,11 @@ import numpy as np
from .const import APPROX
from .mp_math_typing import RealNumber
from .point import Point3
from .angle import AnyAngle
from .utils import approx
if TYPE_CHECKING:
from .angle import AnyAngle
# if TYPE_CHECKING:
#
class Vector3:
@@ -50,6 +51,10 @@ class Vector3:
def cross(self, other: 'Vector3') -> 'Vector3':
"""
向量积 叉乘v1 cross v2 -> v3
叉乘为0则两向量平行。
其余结果的模为平行四边形的面积。
返回如下行列式的结果:
``i j k``