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))

  

原文地址:https://www.cnblogs.com/darkchii/p/12667848.html