# Distance¶

## Distance Type¶

class ipctk.PointEdgeDistanceType

Members:

P_E0 : point is closest to edge vertex zero

P_E1 : point is closest to edge vertex one

P_E : point is closest to the interior of the edge

AUTO : automatically determine the closest point

class ipctk.EdgeEdgeDistanceType

Members:

EA0_EB0 : edges are closest at vertex 0 of edge A and 0 of edge B

EA0_EB1 : edges are closest at vertex 0 of edge A and 1 of edge B

EA1_EB0 : edges are closest at vertex 1 of edge A and 0 of edge B

EA1_EB1 : edges are closest at vertex 1 of edge A and 1 of edge B

EA_EB0 : edges are closest at the interior of edge A and vertex 0 of edge B

EA_EB1 : edges are closest at the interior of edge A and vertex 1 of edge B

EA0_EB : edges are closest at vertex 0 of edge A and the interior of edge B

EA1_EB : edges are closest at vertex 1 of edge A and the interior of edge B

EA_EB : edges are closest at an interior point of edge A and B

AUTO : automatically determine the closest point

class ipctk.PointTriangleDistanceType

Members:

P_T0 : point is closest to triangle vertex zero

P_T1 : point is closest to triangle vertex one

P_T2 : point is closest to triangle vertex two

P_E0 : point is closest to triangle edge zero (vertex zero to one)

P_E1 : point is closest to triangle edge one (vertex one to two)

P_E2 : point is closest to triangle edge two (vertex two to zero)

P_T : point is closest to the interior of the triangle

AUTO : automatically determine the closest point

ipctk.point_edge_distance_type(p: numpy.ndarray[numpy.float64[m, 1]], e0: numpy.ndarray[numpy.float64[m, 1]], e1: numpy.ndarray[numpy.float64[m, 1]])

Determine the closest pair between a point and edge.

Parameters:
p: numpy.ndarray[numpy.float64[m, 1]]

point

e0: numpy.ndarray[numpy.float64[m, 1]]

first vertex of the edge

e1: numpy.ndarray[numpy.float64[m, 1]]

second vertex of the edge

Returns:

The distance type of the point-edge pair.

ipctk.edge_edge_distance_type(ea0: numpy.ndarray[numpy.float64[3, 1]], ea1: numpy.ndarray[numpy.float64[3, 1]], eb0: numpy.ndarray[numpy.float64[3, 1]], eb1: numpy.ndarray[numpy.float64[3, 1]])

Determine the closest pair between two edges.

Parameters:
ea0: numpy.ndarray[numpy.float64[3, 1]]

first vertex of the first edge

ea1: numpy.ndarray[numpy.float64[3, 1]]

second vertex of the first edge

eb0: numpy.ndarray[numpy.float64[3, 1]]

first vertex of the second edge

eb1: numpy.ndarray[numpy.float64[3, 1]]

second vertex of the second edge

Returns:

The distance type of the edge-edge pair.

ipctk.point_triangle_distance_type(p: numpy.ndarray[numpy.float64[3, 1]], t0: numpy.ndarray[numpy.float64[3, 1]], t1: numpy.ndarray[numpy.float64[3, 1]], t2: numpy.ndarray[numpy.float64[3, 1]])

Determine the closest pair between a point and triangle.

Parameters:
p: numpy.ndarray[numpy.float64[3, 1]]

point

t0: numpy.ndarray[numpy.float64[3, 1]]

first vertex of the triangle

t1: numpy.ndarray[numpy.float64[3, 1]]

second vertex of the triangle

t2: numpy.ndarray[numpy.float64[3, 1]]

third vertex of the triangle

Returns:

The distance type of the point-triangle pair.

## Edge-Edge¶

ipctk.edge_edge_distance(ea0: numpy.ndarray[numpy.float64[3, 1]], ea1: numpy.ndarray[numpy.float64[3, 1]], eb0: numpy.ndarray[numpy.float64[3, 1]], eb1: numpy.ndarray[numpy.float64[3, 1]], dtype: ipctk.EdgeEdgeDistanceType = <EdgeEdgeDistanceType.AUTO: 9>) float

Compute the distance between a two lines segments in 3D.

Parameters:
ea0

first vertex of the first edge

ea1

second vertex of the first edge

eb0

first vertex of the second edge

eb1

second vertex of the second edge

dtype

(optional) edge-edge distance type to compute

Returns:

The distance between the two edges.

Note

The distance is actually squared distance.

ipctk.edge_edge_distance_gradient(ea0: numpy.ndarray[numpy.float64[3, 1]], ea1: numpy.ndarray[numpy.float64[3, 1]], eb0: numpy.ndarray[numpy.float64[3, 1]], eb1: numpy.ndarray[numpy.float64[3, 1]], dtype: ipctk.EdgeEdgeDistanceType = <EdgeEdgeDistanceType.AUTO: 9>) numpy.ndarray[numpy.float64[12, 1]]

Compute the gradient of the distance between a two lines segments.

Parameters:
ea0

first vertex of the first edge

ea1

second vertex of the first edge

eb0

first vertex of the second edge

eb1

second vertex of the second edge

dtype

(optional) point edge distance type to compute

Returns:

The gradient of the distance wrt ea0, ea1, eb0, and eb1.

Note

The distance is actually squared distance.

ipctk.edge_edge_distance_hessian(ea0: numpy.ndarray[numpy.float64[3, 1]], ea1: numpy.ndarray[numpy.float64[3, 1]], eb0: numpy.ndarray[numpy.float64[3, 1]], eb1: numpy.ndarray[numpy.float64[3, 1]], dtype: ipctk.EdgeEdgeDistanceType = <EdgeEdgeDistanceType.AUTO: 9>) numpy.ndarray[numpy.float64[12, 12]]

Compute the hessian of the distance between a two lines segments.

Parameters:
ea0

first vertex of the first edge

ea1

second vertex of the first edge

eb0

first vertex of the second edge

eb1

second vertex of the second edge

dtype

(optional) point edge distance type to compute

Returns:

The hessian of the distance wrt ea0, ea1, eb0, and eb1.

Note

The distance is actually squared distance.

## Edge-Edge Mollifier¶

ipctk.edge_edge_mollifier_threshold(ea0_rest: numpy.ndarray[numpy.float64[3, 1]], ea1_rest: numpy.ndarray[numpy.float64[3, 1]], eb0_rest: numpy.ndarray[numpy.float64[3, 1]], eb1_rest: numpy.ndarray[numpy.float64[3, 1]]) float

Compute the threshold of the mollifier edge-edge distance.

This values is computed based on the edges at rest length.

Parameters:
ea0_rest: numpy.ndarray[numpy.float64[3, 1]]

rest position of the first vertex of the first edge

ea1_rest: numpy.ndarray[numpy.float64[3, 1]]

rest position of the second vertex of the first edge

eb0_rest: numpy.ndarray[numpy.float64[3, 1]]

rest position of the first vertex of the second edge

eb1_rest: numpy.ndarray[numpy.float64[3, 1]]

rest position of the second vertex of the second edge

Returns:

Threshold for edge-edge mollification.

ipctk.edge_edge_cross_squarednorm(ea0: numpy.ndarray[numpy.float64[3, 1]], ea1: numpy.ndarray[numpy.float64[3, 1]], eb0: numpy.ndarray[numpy.float64[3, 1]], eb1: numpy.ndarray[numpy.float64[3, 1]]) float

Compute the squared norm of the edge-edge cross product.

Parameters:
ea0: numpy.ndarray[numpy.float64[3, 1]]

first vertex of the first edge

ea1: numpy.ndarray[numpy.float64[3, 1]]

second vertex of the first edge

eb0: numpy.ndarray[numpy.float64[3, 1]]

first vertex of the second edge

eb1: numpy.ndarray[numpy.float64[3, 1]]

second vertex of the second edge

Returns:

The squared norm of the edge-edge cross product.

ipctk.edge_edge_cross_squarednorm_gradient(ea0: numpy.ndarray[numpy.float64[3, 1]], ea1: numpy.ndarray[numpy.float64[3, 1]], eb0: numpy.ndarray[numpy.float64[3, 1]], eb1: numpy.ndarray[numpy.float64[3, 1]]) numpy.ndarray[numpy.float64[12, 1]]

Compute the gradient of the squared norm of the edge cross product.

Parameters:
ea0: numpy.ndarray[numpy.float64[3, 1]]

first vertex of the first edge

ea1: numpy.ndarray[numpy.float64[3, 1]]

second vertex of the first edge

eb0: numpy.ndarray[numpy.float64[3, 1]]

first vertex of the second edge

eb1: numpy.ndarray[numpy.float64[3, 1]]

second vertex of the second edge

Returns:

The gradient of the squared norm of the edge cross product wrt ea0, ea1, eb0, and eb1.

ipctk.edge_edge_cross_squarednorm_hessian(ea0: numpy.ndarray[numpy.float64[3, 1]], ea1: numpy.ndarray[numpy.float64[3, 1]], eb0: numpy.ndarray[numpy.float64[3, 1]], eb1: numpy.ndarray[numpy.float64[3, 1]]) numpy.ndarray[numpy.float64[12, 12]]

Compute the hessian of the squared norm of the edge cross product.

Parameters:
ea0: numpy.ndarray[numpy.float64[3, 1]]

first vertex of the first edge

ea1: numpy.ndarray[numpy.float64[3, 1]]

second vertex of the first edge

eb0: numpy.ndarray[numpy.float64[3, 1]]

first vertex of the second edge

eb1: numpy.ndarray[numpy.float64[3, 1]]

second vertex of the second edge

Returns:

The hessian of the squared norm of the edge cross product wrt ea0, ea1, eb0, and eb1.

ipctk.edge_edge_mollifier(*args, **kwargs)

1. edge_edge_mollifier(x: float, eps_x: float) -> float

Mollifier function for edge-edge distance.

Parameters:
• x: squared norm of the edge-edge cross product

• eps_x: mollifier activation threshold

Returns:

The mollifier coefficient to premultiply the edge-edge distance.

2. edge_edge_mollifier(ea0: numpy.ndarray[numpy.float64[3, 1]], ea1: numpy.ndarray[numpy.float64[3, 1]], eb0: numpy.ndarray[numpy.float64[3, 1]], eb1: numpy.ndarray[numpy.float64[3, 1]], eps_x: float) -> float

Compute a mollifier for the edge-edge distance.

This helps smooth the non-smoothness at close to parallel edges.

Parameters:
• ea0: first vertex of the first edge

• ea1: second vertex of the first edge

• eb0: first vertex of the second edge

• eb1: second vertex of the second edge

• eps_x: mollifier activation threshold

Returns:

The mollifier coefficient to premultiply the edge-edge distance.

1. edge_edge_mollifier_gradient(x: float, eps_x: float) -> float

The gradient of the mollifier function for edge-edge distance.

Parameters:
• x: squared norm of the edge-edge cross product

• eps_x: mollifier activation threshold

Returns:

The gradient of the mollifier function for edge-edge distance wrt x.

2. edge_edge_mollifier_gradient(ea0: numpy.ndarray[numpy.float64[3, 1]], ea1: numpy.ndarray[numpy.float64[3, 1]], eb0: numpy.ndarray[numpy.float64[3, 1]], eb1: numpy.ndarray[numpy.float64[3, 1]], eps_x: float) -> numpy.ndarray[numpy.float64[12, 1]]

Compute the gradient of the mollifier for the edge-edge distance.

Parameters:
• ea0: first vertex of the first edge

• ea1: second vertex of the first edge

• eb0: first vertex of the second edge

• eb1: second vertex of the second edge

• eps_x: mollifier activation threshold

Returns:

ipctk.edge_edge_mollifier_hessian(*args, **kwargs)

1. edge_edge_mollifier_hessian(x: float, eps_x: float) -> float

The hessian of the mollifier function for edge-edge distance.

Parameters:
• x: squared norm of the edge-edge cross product

• eps_x: mollifier activation threshold

Returns:

The hessian of the mollifier function for edge-edge distance wrt x.

2. edge_edge_mollifier_hessian(ea0: numpy.ndarray[numpy.float64[3, 1]], ea1: numpy.ndarray[numpy.float64[3, 1]], eb0: numpy.ndarray[numpy.float64[3, 1]], eb1: numpy.ndarray[numpy.float64[3, 1]], eps_x: float) -> numpy.ndarray[numpy.float64[12, 12]]

Compute the hessian of the mollifier for the edge-edge distance.

Parameters:
• ea0: first vertex of the first edge

• ea1: second vertex of the first edge

• eb0: first vertex of the second edge

• eb1: second vertex of the second edge

• eps_x: mollifier activation threshold

Returns:

The hessian of the mollifier.

## Line-Line¶

ipctk.line_line_distance(ea0: numpy.ndarray[numpy.float64[3, 1]], ea1: numpy.ndarray[numpy.float64[3, 1]], eb0: numpy.ndarray[numpy.float64[3, 1]], eb1: numpy.ndarray[numpy.float64[3, 1]]) float

Compute the distance between a two infinite lines in 3D.

Parameters:
ea0: numpy.ndarray[numpy.float64[3, 1]]

first vertex of the edge defining the first line

ea1: numpy.ndarray[numpy.float64[3, 1]]

second vertex of the edge defining the first line

eb0: numpy.ndarray[numpy.float64[3, 1]]

first vertex of the edge defining the second line

eb1: numpy.ndarray[numpy.float64[3, 1]]

second vertex of the edge defining the second line

Returns:

The distance between the two lines.

Note

The distance is actually squared distance.

Warning

If the lines are parallel this function returns a distance of zero.

ipctk.line_line_distance_gradient(ea0: numpy.ndarray[numpy.float64[3, 1]], ea1: numpy.ndarray[numpy.float64[3, 1]], eb0: numpy.ndarray[numpy.float64[3, 1]], eb1: numpy.ndarray[numpy.float64[3, 1]]) numpy.ndarray[numpy.float64[12, 1]]

Compute the gradient of the distance between a two lines in 3D.

Parameters:
ea0: numpy.ndarray[numpy.float64[3, 1]]

first vertex of the edge defining the first line

ea1: numpy.ndarray[numpy.float64[3, 1]]

second vertex of the edge defining the first line

eb0: numpy.ndarray[numpy.float64[3, 1]]

first vertex of the edge defining the second line

eb1: numpy.ndarray[numpy.float64[3, 1]]

second vertex of the edge defining the second line

Returns:

The gradient of the distance wrt ea0, ea1, eb0, and eb1.

Note

The distance is actually squared distance.

Warning

If the lines are parallel this function returns a distance of zero.

ipctk.line_line_distance_hessian(ea0: numpy.ndarray[numpy.float64[3, 1]], ea1: numpy.ndarray[numpy.float64[3, 1]], eb0: numpy.ndarray[numpy.float64[3, 1]], eb1: numpy.ndarray[numpy.float64[3, 1]]) numpy.ndarray[numpy.float64[12, 12]]

Compute the hessian of the distance between a two lines in 3D.

Parameters:
ea0: numpy.ndarray[numpy.float64[3, 1]]

first vertex of the edge defining the first line

ea1: numpy.ndarray[numpy.float64[3, 1]]

second vertex of the edge defining the first line

eb0: numpy.ndarray[numpy.float64[3, 1]]

first vertex of the edge defining the second line

eb1: numpy.ndarray[numpy.float64[3, 1]]

second vertex of the edge defining the second line

Returns:

The hessian of the distance wrt ea0, ea1, eb0, and eb1.

Note

The distance is actually squared distance.

Warning

If the lines are parallel this function returns a distance of zero.

## Point-Edge¶

ipctk.point_edge_distance(p: numpy.ndarray[numpy.float64[m, 1]], e0: numpy.ndarray[numpy.float64[m, 1]], e1: numpy.ndarray[numpy.float64[m, 1]], dtype: ipctk.PointEdgeDistanceType = <PointEdgeDistanceType.AUTO: 3>) float

Compute the distance between a point and edge in 2D or 3D.

Parameters:
p

point

e0

first vertex of the edge

e1

second vertex of the edge

dtype

(optional) point edge distance type to compute

Returns:

The distance between the point and edge

Note

The distance is actually squared distance.

ipctk.point_edge_distance_gradient(p: numpy.ndarray[numpy.float64[m, 1]], e0: numpy.ndarray[numpy.float64[m, 1]], e1: numpy.ndarray[numpy.float64[m, 1]], dtype: ipctk.PointEdgeDistanceType = <PointEdgeDistanceType.AUTO: 3>) numpy.ndarray[numpy.float64[m, 1]]

Compute the gradient of the distance between a point and edge.

Parameters:
p

point

e0

first vertex of the edge

e1

second vertex of the edge

dtype

(optional) point edge distance type to compute

Returns:

The gradient of the distance wrt p, e0, and e1.

Note

The distance is actually squared distance.

ipctk.point_edge_distance_hessian(p: numpy.ndarray[numpy.float64[m, 1]], e0: numpy.ndarray[numpy.float64[m, 1]], e1: numpy.ndarray[numpy.float64[m, 1]], dtype: ipctk.PointEdgeDistanceType = <PointEdgeDistanceType.AUTO: 3>) numpy.ndarray[numpy.float64[m, n]]

Compute the hessian of the distance between a point and edge.

Parameters:
p

point

e0

first vertex of the edge

e1

second vertex of the edge

dtype

(optional) point edge distance type to compute

Returns:

The hessian of the distance wrt p, e0, and e1.

Note

The distance is actually squared distance.

## Point-Line¶

ipctk.point_line_distance(p: numpy.ndarray[numpy.float64[m, 1]], e0: numpy.ndarray[numpy.float64[m, 1]], e1: numpy.ndarray[numpy.float64[m, 1]]) float

Compute the distance between a point and line in 2D or 3D.

Parameters:
p: numpy.ndarray[numpy.float64[m, 1]]

point

e0: numpy.ndarray[numpy.float64[m, 1]]

first vertex of the edge defining the line

e1: numpy.ndarray[numpy.float64[m, 1]]

second vertex of the edge defining the line

Returns:

The distance between the point and line.

Note

The distance is actually squared distance.

ipctk.point_line_distance_gradient(p: numpy.ndarray[numpy.float64[m, 1]], e0: numpy.ndarray[numpy.float64[m, 1]], e1: numpy.ndarray[numpy.float64[m, 1]]) numpy.ndarray[numpy.float64[m, 1]]

Compute the gradient of the distance between a point and line.

Parameters:
p: numpy.ndarray[numpy.float64[m, 1]]

point

e0: numpy.ndarray[numpy.float64[m, 1]]

first vertex of the edge defining the line.

e1: numpy.ndarray[numpy.float64[m, 1]]

second vertex of the edge defining the line.

Returns:

The gradient of the distance wrt p, e0, and e1.

Note

The distance is actually squared distance.

ipctk.point_line_distance_hessian(p: numpy.ndarray[numpy.float64[m, 1]], e0: numpy.ndarray[numpy.float64[m, 1]], e1: numpy.ndarray[numpy.float64[m, 1]]) numpy.ndarray[numpy.float64[m, n]]

Compute the hessian of the distance between a point and line.

Parameters:
p: numpy.ndarray[numpy.float64[m, 1]]

point

e0: numpy.ndarray[numpy.float64[m, 1]]

first vertex of the edge defining the line

e1: numpy.ndarray[numpy.float64[m, 1]]

second vertex of the edge defining the line

Returns:

The hessian of the distance wrt p, e0, and e1.

Note

The distance is actually squared distance.

## Point-Plane¶

point_plane_distance(p: numpy.ndarray[numpy.float64[3, 1]], t0: numpy.ndarray[numpy.float64[3, 1]], t1: numpy.ndarray[numpy.float64[3, 1]], t1: numpy.ndarray[numpy.float64[3, 1]]) -> float

Compute the distance between a point and a plane.

Parameters:
p

point

t0

first vertex of the triangle

t1

second vertex of the triangle

t2

third vertex of the triangle

Returns:

The distance between the point and plane.

Note

The distance is actually squared distance.

point_plane_distance_gradient(p: numpy.ndarray[numpy.float64[3, 1]], t0: numpy.ndarray[numpy.float64[3, 1]], t1: numpy.ndarray[numpy.float64[3, 1]], t1: numpy.ndarray[numpy.float64[3, 1]]) -> numpy.ndarray[numpy.float64[12, 1]]

Compute the gradient of the distance between a point and a plane.

Parameters:
p

point

t0

first vertex of the triangle

t1

second vertex of the triangle

t2

third vertex of the triangle

Returns:

The gradient of the distance wrt p, t0, t1, and t2.

Note

The distance is actually squared distance.

point_plane_distance_hessian(p: numpy.ndarray[numpy.float64[3, 1]], t0: numpy.ndarray[numpy.float64[3, 1]], t1: numpy.ndarray[numpy.float64[3, 1]], t1: numpy.ndarray[numpy.float64[3, 1]]) -> numpy.ndarray[numpy.float64[12, 12]]

Compute the hessian of the distance between a point and a plane.

Parameters:
p

point

t0

first vertex of the triangle

t1

second vertex of the triangle

t2

third vertex of the triangle

Returns:

The hessian of the distance wrt p, t0, t1, and t2.

Note

The distance is actually squared distance.

## Point-Point¶

ipctk.point_point_distance(p0: numpy.ndarray[numpy.float64[m, 1]], p1: numpy.ndarray[numpy.float64[m, 1]]) float

Compute the distance between two points.

Parameters:
p0: numpy.ndarray[numpy.float64[m, 1]]

first point

p1: numpy.ndarray[numpy.float64[m, 1]]

second point

Returns:

The distance between p0 and p1

Note

The distance is actually squared distance.

ipctk.point_point_distance_gradient(p0: numpy.ndarray[numpy.float64[m, 1]], p1: numpy.ndarray[numpy.float64[m, 1]]) numpy.ndarray[numpy.float64[m, 1]]

Compute the gradient of the distance between two points.

Parameters:
p0: numpy.ndarray[numpy.float64[m, 1]]

first point

p1: numpy.ndarray[numpy.float64[m, 1]]

second point

Returns:

The gradient of the distance wrt p0 and p1.

Note

The distance is actually squared distance.

ipctk.point_point_distance_hessian(p0: numpy.ndarray[numpy.float64[m, 1]], p1: numpy.ndarray[numpy.float64[m, 1]]) numpy.ndarray[numpy.float64[m, n]]

Compute the hessian of the distance between a point and point.

Parameters:
p0: numpy.ndarray[numpy.float64[m, 1]]

first point

p1: numpy.ndarray[numpy.float64[m, 1]]

second point

Returns:

The hessian of the distance wrt p0 and p1.

Note

The distance is actually squared distance.

## Point-Triangle¶

ipctk.point_triangle_distance(p: numpy.ndarray[numpy.float64[3, 1]], t0: numpy.ndarray[numpy.float64[3, 1]], t1: numpy.ndarray[numpy.float64[3, 1]], t2: numpy.ndarray[numpy.float64[3, 1]], dtype: ipctk.PointTriangleDistanceType = <PointTriangleDistanceType.AUTO: 7>) float

Compute the distance between a two lines segments in 3D.

Parameters:
p

point.

t0

first vertex of the triangle.

t1

second vertex of the triangle.

t2

third vertex of the triangle.

dtype

(Optional) point-triangle distance type to compute

Returns:

The distance between the point and triangle.

Note

The distance is actually squared distance.

ipctk.point_triangle_distance_gradient(p: numpy.ndarray[numpy.float64[3, 1]], t0: numpy.ndarray[numpy.float64[3, 1]], t1: numpy.ndarray[numpy.float64[3, 1]], t2: numpy.ndarray[numpy.float64[3, 1]], dtype: ipctk.PointTriangleDistanceType = <PointTriangleDistanceType.AUTO: 7>) numpy.ndarray[numpy.float64[12, 1]]

Compute the gradient of the distance between a two lines segments.

Parameters:
p

point

t0

first vertex of the triangle

t1

second vertex of the triangle

t2

third vertex of the triangle

dtype

(optional) point-triangle distance type to compute

Returns:

The gradient of the distance wrt ea0, ea1, eb0, and eb1.

Note

The distance is actually squared distance.

ipctk.point_triangle_distance_hessian(p: numpy.ndarray[numpy.float64[3, 1]], t0: numpy.ndarray[numpy.float64[3, 1]], t1: numpy.ndarray[numpy.float64[3, 1]], t2: numpy.ndarray[numpy.float64[3, 1]], dtype: ipctk.PointTriangleDistanceType = <PointTriangleDistanceType.AUTO: 7>) numpy.ndarray[numpy.float64[12, 12]]

Compute the hessian of the distance between a two lines segments.

Parameters:
p

point

t0

first vertex of the triangle

t1

second vertex of the triangle

t2

third vertex of the triangle

dtype

(optional) point-triangle distance type to compute

Returns:

The hessian of the distance wrt ea0, ea1, eb0, and eb1.

Note

The distance is actually squared distance.

Last update: January 26, 2023