math_calc

This module provides functions for geometric and mathematical calculations.

define_xy_line(point1, point2, point3)[source]

Defines a line in 3D space using two points and a third point to determine the plane. Returns the slope (m) and y-intercept (b) of the line in the x-y plane.

Parameters

point1tuple

Coordinates of the first point (x, y, z).

point2tuple

Coordinates of the second point (x, y, z).

point3tuple

Coordinates of the third point (x, y, z) used to define the plane.

Returns

mfloat

Slope of the line in the x-y plane.

bfloat

Y-intercept of the line in the x-y plane.

dist_from_line(line, point)[source]

Calculates the distance from a point to a line defined by its slope and y-intercept. The line is defined in the x-y plane, and the point is a 2D point (x, y).

Parameters

linetuple

Slope (m) and y-intercept (b) of the line.

pointtuple

Coordinates of the point (x, y).

Returns

distancefloat

Perpendicular distance from the point to the line.

distance3D(a, b)[source]

Calculates the Euclidean distance between two 3D points.

Parameters

atuple

Coordinates of the first point (x, y, z).

btuple

Coordinates of the second point (x, y, z).

Returns

distancefloat

Euclidean distance between the two points.

get_line_from_points(point1, point2)[source]

Calculate the slope and y-intercept of a line given two points.

Parameters

point1tuple

Coordinates of the first point (x, y).

point2tuple

Coordinates of the second point (x, y).

Returns

mfloat

Slope of the line.

bfloat

Y-intercept of the line.

perpendicular_distance_point_to_line(line: tuple[float, float], point: tuple[float, float]) float[source]
perpendicular_distance_point_to_line(line: tuple[tuple[float, float], tuple[float, float]], point: tuple[float, float]) float

Calculate the perpendicular distance from a point to a line defined by two points.

This function uses the cross product method for accurate distance calculation and handles all edge cases including vertical and horizontal lines.

Parameters

pointtuple

Coordinates of the point (x, y).

line_point1tuple

Coordinates of the first point defining the line (x, y).

line_point2tuple

Coordinates of the second point defining the line (x, y).

Returns

distancefloat

Perpendicular distance from the point to the line.

Raises

ValueError:

If the two line points are identical (cannot define a line).

perpendicular_distance_point_to_line_3d(point, line_point1, line_point2)[source]

Calculate the perpendicular distance from a point to a line in 3D space.

Uses vector cross product to find the shortest distance from a point to a line defined by two points in 3D space.

Parameters

pointtuple

Coordinates of the point (x, y, z).

line_point1tuple

Coordinates of the first point defining the line (x, y, z).

line_point2tuple

Coordinates of the second point defining the line (x, y, z).

Returns

distancefloat

Perpendicular distance from the point to the line in 3D space.

Raises

ValueError:

If the two line points are identical (cannot define a line).