mirror of
https://github.com/snowykami/mbcp.git
synced 2026-04-26 12:25:37 +00:00
🐛 fix line.cal_intersection
This commit is contained in:
@@ -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':
|
||||
...
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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``
|
||||
|
||||
Reference in New Issue
Block a user