mbcp/mcpe/mp_math/line.py
2024-08-06 18:02:51 +08:00

67 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
"""
Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
@Time : 2024/8/6 下午12:57
@Author : snowykami
@Email : snowykami@outlook.com
@File : line.py
@Software: PyCharm
"""
from typing import overload, TYPE_CHECKING
if TYPE_CHECKING:
from mcpe.mp_math.point import Point3
from mcpe.mp_math.vector import Vector3
class Line3:
def __init__(self, a: float, b: float, c: float, d:float):
"""
三维空间中的直线。
:param a:
:param b:
:param c:
:param d:
"""
self.a = a
self.b = b
self.c = c
self.d = d
def __str__(self):
return f"Line3({self.a}, {self.b}, {self.c}, {self.d})"
def get_perpendicular(self, p: "Point3") -> "Line3":
"""
获取直线经过指定点p的垂线。
:param p: 指定点p直线外的点
:return: 垂直于self且过点p的直线
"""
a = -self.b
b = self.a
c = 0
d = -(a * p.x + b * p.y + self.c * p.z)
return Line3(a, b, c, d)
def get_intersection(self, l: "Line3") -> "Point3":
"""
获取两空间直线的交点。
:param l: 另一条直线不平行于self不共线且共面
:return: 交点
"""
# 平行检测
if ...:
...
# 共线检测
if ...:
...
# 不共线检测
if ...:
...