🐛 fix ε accuracy

This commit is contained in:
2024-08-27 09:08:27 +08:00
parent a74811291f
commit 5a0e2f189c
14 changed files with 734 additions and 149 deletions

33
tests/test_line3.py Normal file
View File

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
"""
Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
@Time : 2024/8/26 上午7:54
@Author : snowykami
@Email : snowykami@outlook.com
@File : test_line3.py
@Software: PyCharm
"""
import logging
from mbcp.mp_math.point import Point3
from mbcp.mp_math.vector import Vector3
from mbcp.mp_math.line import Line3
class TestLine3:
def test_point_and_normal_factory(self):
"""
测试通过点和法向量构造直线
"""
correct_ans = Line3(1, -2, 3, -8)
p = Point3(2, -3, 0)
n = Vector3(1, -2, 3)
actual_ans = Line3.from_point_and_direction(p, n)
logging.info(f"正确答案:{correct_ans} 实际答案:{actual_ans}")
assert actual_ans == correct_ans

29
tests/test_plane3.py Normal file
View File

@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
"""
Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
@Time : 2024/8/26 上午9:07
@Author : snowykami
@Email : snowykami@outlook.com
@File : test_plane3.py
@Software: PyCharm
"""
import logging
from mbcp.mp_math.line import Line3
from mbcp.mp_math.plane import Plane3
class TestPlane3:
def test_intersection_line3(self):
"""
测试平面的交线
"""
correct_ans = Line3(4, 3, 1, 1)
pl1 = Plane3(1, 0, -4, 23)
pl2 = Plane3(2, -1, -5, 33)
actual_ans = pl1.cal_intersection_line3(pl2)
logging.info(f"正确答案:{correct_ans} 实际答案:{actual_ans}")
assert actual_ans == correct_ans

View File

@ -1,22 +0,0 @@
# -*- coding: utf-8 -*-
"""
Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
@Time : 2024/8/6 下午1:05
@Author : snowykami
@Email : snowykami@outlook.com
@File : test_vector.py
@Software: PyCharm
"""
from mbcp.mp_math.vector import Vector3
from mbcp.mp_math.point import Point3
def test_v():
v1 = Vector3(1, 2, 3)
v2 = Vector3(4, 5, 6)
v3 = v1 + v2
assert v3._x == 5
assert v3._y == 7
assert v3._z == 9
print("test_v 1111passed")

52
tests/test_vector3.py Normal file
View File

@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
"""
Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
@Time : 2024/8/26 上午6:58
@Author : snowykami
@Email : snowykami@outlook.com
@File : test_question_1.py
@Software: PyCharm
"""
import logging
from mbcp.mp_math.vector import Vector3
class TestVector3:
"""测试问题集"""
def test_vector_cross_product(self):
"""
测试向量叉乘
Returns:
"""
v1 = Vector3(1, 2, 3)
v2 = Vector3(3, 4, 5)
actual_ans = v1 @ v2
correct_ans = Vector3(-2, 4, -2)
logging.info(f"正确答案{correct_ans} 实际答案{v1 @ v2}")
assert correct_ans == actual_ans
def test_determine_vector_parallel(self):
"""
测试判断向量是否平行
Returns:
"""
v1 = Vector3(1, 2, 3)
v2 = Vector3(3, 6, 9)
actual_ans = v1.is_parallel(v2)
correct_ans = True
logging.info("v1和v2是否平行%s", v1.is_parallel(v2))
assert correct_ans == actual_ans
v1 = Vector3(1, 2, 3)
v2 = Vector3(3, 6, 8)
actual_ans = v1.is_parallel(v2)
correct_ans = False
logging.info("v1和v2是否平行%s", v1.is_parallel(v2))
assert correct_ans == actual_ans

View File

@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
"""
应用题测试集
"""
import logging
from mbcp.mp_math.line import Line3
from mbcp.mp_math.plane import Plane3
from mbcp.mp_math.point import Point3
class TestWordProblem:
def test_c8s4e4(self):
"""
同济大学《高等数学》第八版 下册 第八章第四节例4
问题求与两平面x-4z-3=0和2x-y-5z-1=0的交线平行且过点(-3, 2, 5)的直线方程。
"""
correct_ans = Line3(4, 3, 1, 1)
pl1 = Plane3(1, 0, -4, -3)
pl2 = Plane3(2, -1, -5, -1)
p = Point3(-3, 2, 5)
"""解法1"""
# 求直线方向向量s
s = pl1.normal @ pl2.normal
actual_ans = Line3.from_point_and_direction(p, s)
logging.info(f"正确答案:{correct_ans} 实际答案:{actual_ans}")
assert actual_ans == correct_ans
"""解法2"""
# 过点p且与pl1平行的平面pl3
pl3 = pl1.cal_parallel_plane3(p)
# 过点p且与pl2平行的平面pl4
pl4 = pl2.cal_parallel_plane3(p)
# 求pl3和pl4的交线
actual_ans = pl3.cal_intersection_line3(pl4)
print(pl3, pl4, actual_ans)
logging.info(f"正确答案:{correct_ans} 实际答案:{actual_ans}")
assert actual_ans == correct_ans