python 几何教学_python - 求解基础空间解析几何

未完成,有空再继续完善。。

代码:

import numpy as np

def point_to_line_distance(a, b, c, x0, y0):

return np.abs(a * x0 + b * y0 + c) / np.sqrt(a * a + b * b)

def point_to_plane_distance(a, b, c, d, x0, y0, z0):

return np.abs(a * x0 + b * y0 + c * z0 + d) / np.sqrt(a * a + b * b + c * c)

def point_slope_to_intercept(x0, y0, slope):

return y0 - (-1. / slope) * x0

def parse_expression(exp: str = ''):

return ''

def point_is_in_area(x0, y0, trig_points):

for x, y in trig_points:

if x0 > x:

pass

def three_points_compute_area(points):

point1 = points[0]

point2 = points[1]

point3 = points[2]

vertor1 = point2 - point1

vertor2 = point3 - point1

normal_vector = np.cross(vertor1, vertor2)

return 1. / 2. * np.sqrt(normal_vector.dot(normal_vector))

def three_dimension_points_output_equation(points):

point1 = points[0]

point2 = points[1]

point3 = points[2]

vertor1 = point2 - point1

vertor2 = point3 - point1

normal_vector = np.cross(vertor1, vertor2)

A = normal_vector[0]

B = normal_vector[1]

C = normal_vector[2]

D = A * point1[0] + B * point1[1] + C * point1[2]

return str(A) + 'x + ' + str(B) + 'y + ' + str(C) + 'z + ' + str(D) + ' = 0'

if __name__ == '__main__':

points = np.array(

[

[2, -1, 4],

[-1, 3, -2],

[0, 2, 3]

])

print(three_points_compute_area(points))

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值