Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/src/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ PYBIND11_MODULE(ipctk, m)
define_point_point_distance(m);
define_point_plane_distance(m);
define_point_triangle_distance(m);
define_signed_distance(m);

// friction
define_smooth_friction_mollifier(m);
Expand Down
1 change: 1 addition & 0 deletions python/src/distance/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(SOURCES
point_plane.cpp
point_point.cpp
point_triangle.cpp
signed_distance.cpp
)

target_sources(ipctk PRIVATE ${SOURCES})
3 changes: 2 additions & 1 deletion python/src/distance/bindings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ void define_point_edge_distance(py::module_& m);
void define_point_line_distance(py::module_& m);
void define_point_point_distance(py::module_& m);
void define_point_plane_distance(py::module_& m);
void define_point_triangle_distance(py::module_& m);
void define_point_triangle_distance(py::module_& m);
void define_signed_distance(py::module_& m);
117 changes: 117 additions & 0 deletions python/src/distance/signed_distance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#include <common.hpp>

#include <ipc/distance/signed/point_line.hpp>
#include <ipc/distance/signed/point_plane.hpp>
#include <ipc/distance/signed/line_line.hpp>

using namespace ipc;

void define_signed_distance(py::module_& m)
{
// Point-line (2D) signed distance
m.def(
"point_line_signed_distance", point_line_signed_distance,
R"ipc_Qu8mg5v7(
Compute the signed distance from a point to a directed line segment (2D).

Parameters:
p: The query point (2D).
e0: The first endpoint of the directed edge (2D).
e1: The second endpoint of the directed edge (2D).

Returns:
The signed scalar distance from `p` to the (infinite) line through `e0` and `e1`.
)ipc_Qu8mg5v7",
"p"_a, "e0"_a, "e1"_a);

m.def(
"point_line_signed_distance_gradient",
point_line_signed_distance_gradient,
R"ipc_Qu8mg5v7(
Compute the gradient of the signed point-to-line distance (2D).

Returns a 6-vector ordered as [dp, de0, de1].
)ipc_Qu8mg5v7",
"p"_a, "e0"_a, "e1"_a);

m.def(
"point_line_signed_distance_hessian",
point_line_signed_distance_hessian,
R"ipc_Qu8mg5v7(
Compute the Hessian of the signed point-to-line distance (2D).

Returns a 6x6 Hessian matrix with variables ordered as [p, e0, e1].
)ipc_Qu8mg5v7",
"p"_a, "e0"_a, "e1"_a);

// Point-plane (3D) signed distance
m.def(
"point_plane_signed_distance", point_plane_signed_distance,
R"ipc_Qu8mg5v7(
Compute the signed distance from a point to the plane of a triangle (3D).

Parameters:
p: The query point (3D).
t0: First vertex of the triangle (3D).
t1: Second vertex of the triangle (3D).
t2: Third vertex of the triangle (3D).

Returns:
The signed distance from `p` to the triangle plane.
)ipc_Qu8mg5v7",
"p"_a, "t0"_a, "t1"_a, "t2"_a);

m.def(
"point_plane_signed_distance_gradient",
point_plane_signed_distance_gradient,
R"ipc_Qu8mg5v7(
Compute the gradient of the signed point-to-plane distance (3D).

Returns a 12-vector ordered as [dp, dt0, dt1, dt2].
)ipc_Qu8mg5v7",
"p"_a, "t0"_a, "t1"_a, "t2"_a);

m.def(
"point_plane_signed_distance_hessian",
point_plane_signed_distance_hessian,
R"ipc_Qu8mg5v7(
Compute the Hessian of the signed point-to-plane distance (3D).

Returns a 12x12 Hessian matrix with variables ordered as [p, t0, t1, t2].
)ipc_Qu8mg5v7",
"p"_a, "t0"_a, "t1"_a, "t2"_a);

// Line-line (3D) signed distance
m.def(
"line_line_signed_distance", line_line_signed_distance,
R"ipc_Qu8mg5v7(
Compute the signed distance between two lines in 3D.

Parameters:
ea0, ea1: Two points on the first line.
eb0, eb1: Two points on the second line.

Returns:
The signed distance along the common normal between the two lines.
)ipc_Qu8mg5v7",
"ea0"_a, "ea1"_a, "eb0"_a, "eb1"_a);

m.def(
"line_line_signed_distance_gradient",
line_line_signed_distance_gradient,
R"ipc_Qu8mg5v7(
Compute the gradient of the signed line-line distance (3D).

Returns a 12-vector ordered as [d/d(ea0); d/d(ea1); d/d(eb0); d/d(eb1)].
)ipc_Qu8mg5v7",
"ea0"_a, "ea1"_a, "eb0"_a, "eb1"_a);

m.def(
"line_line_signed_distance_hessian", line_line_signed_distance_hessian,
R"ipc_Qu8mg5v7(
Compute the Hessian of the signed line-line distance (3D).

Returns a 12x12 Hessian matrix with variables ordered as [ea0, ea1, eb0, eb1].
)ipc_Qu8mg5v7",
"ea0"_a, "ea1"_a, "eb0"_a, "eb1"_a);
}
128 changes: 64 additions & 64 deletions python/src/geometry/normal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,56 +92,56 @@ void define_normal(py::module_& m)
)ipc_qu8mg5v7");

m.def(
"edge_vertex_unnormalized_normal", &edge_vertex_unnormalized_normal,
"point_line_unnormalized_normal", &point_line_unnormalized_normal,
R"ipc_qu8mg5v7(
Computes the unnormalized normal vector of an edge-vertex pair.
Computes the unnormalized normal vector of a point-line pair.

Parameters
----------
v: The vertex position.
e0: The start position of the edge.
e1: The end position of the edge.
p: The point's position.
e0: The start position of the line.
e1: The end position of the line.

Returns
-------
The unnormalized normal vector.
)ipc_qu8mg5v7",
py::arg("v"), py::arg("e0"), py::arg("e1"));
py::arg("p"), py::arg("e0"), py::arg("e1"));

m.def(
"edge_vertex_normal", &edge_vertex_normal,
"point_line_normal", &point_line_normal,
R"ipc_qu8mg5v7(
Computes the normal vector of an edge-vertex pair.
Computes the normal vector of a point-line pair.

Parameters
----------
v: The vertex position.
e0: The start position of the edge.
e1: The end position of the edge.
p: The point's position.
e0: The start position of the line.
e1: The end position of the line.

Returns
-------
The normal vector.
)ipc_qu8mg5v7",
py::arg("v"), py::arg("e0"), py::arg("e1"));
py::arg("p"), py::arg("e0"), py::arg("e1"));

m.def(
"edge_vertex_unnormalized_normal_jacobian",
&edge_vertex_unnormalized_normal_jacobian,
"point_line_unnormalized_normal_jacobian",
&point_line_unnormalized_normal_jacobian,
R"ipc_qu8mg5v7(
Computes the Jacobian of the unnormalized normal vector of an edge-vertex pair.
Computes the Jacobian of the unnormalized normal vector of a point-line pair.

Parameters
----------
v: The vertex position.
e0: The start position of the edge.
e1: The end position of the edge.
p: The point's position.
e0: The start position of the line.
e1: The end position of the line.

Returns
-------
The Jacobian of the unnormalized normal vector.
The Jacobian of the unnormalized normal vector of the point-line pair.
)ipc_qu8mg5v7",
py::arg("v"), py::arg("e0"), py::arg("e1"));
py::arg("p"), py::arg("e0"), py::arg("e1"));

m.def(
"triangle_unnormalized_normal", &triangle_unnormalized_normal,
Expand Down Expand Up @@ -248,112 +248,112 @@ void define_normal(py::module_& m)
py::arg("a"), py::arg("b"), py::arg("c"));

m.def(
"edge_edge_unnormalized_normal", &edge_edge_unnormalized_normal,
"line_line_unnormalized_normal", &line_line_unnormalized_normal,
R"ipc_qu8mg5v7(
Computes the unnormalized normal vector of two edges.
Computes the unnormalized normal vector of two lines.

Parameters
----------
ea0: The first vertex of the first edge.
ea1: The second vertex of the first edge.
eb0: The first vertex of the second edge.
eb1: The second vertex of the second edge.
ea0: The first vertex of the first line.
ea1: The second vertex of the first line.
eb0: The first vertex of the second line.
eb1: The second vertex of the second line.

Returns
-------
The unnormalized normal vector of the two edges.
The unnormalized normal vector of the two lines.
)ipc_qu8mg5v7",
py::arg("ea0"), py::arg("ea1"), py::arg("eb0"), py::arg("eb1"));

m.def(
"edge_edge_normal", &edge_edge_normal,
"line_line_normal", &line_line_normal,
R"ipc_qu8mg5v7(
Computes the normal vector of two edges.
Computes the normal vector of two lines.

Parameters
----------
ea0: The first vertex of the first edge.
ea1: The second vertex of the first edge.
eb0: The first vertex of the second edge.
eb1: The second vertex of the second edge.
ea0: The first vertex of the first line.
ea1: The second vertex of the first line.
eb0: The first vertex of the second line.
eb1: The second vertex of the second line.

Returns
-------
The normal vector of the two edges.
The normal vector of the two lines.
)ipc_qu8mg5v7",
py::arg("ea0"), py::arg("ea1"), py::arg("eb0"), py::arg("eb1"));

m.def(
"edge_edge_unnormalized_normal_jacobian",
&edge_edge_unnormalized_normal_jacobian,
"line_line_unnormalized_normal_jacobian",
&line_line_unnormalized_normal_jacobian,
R"ipc_qu8mg5v7(
Computes the Jacobian of the unnormalized normal vector of two edges.
Computes the Jacobian of the unnormalized normal vector of two lines.

Parameters
----------
ea0: The first vertex of the first edge.
ea1: The second vertex of the first edge.
eb0: The first vertex of the second edge.
eb1: The second vertex of the second edge.
ea0: The first vertex of the first line.
ea1: The second vertex of the first line.
eb0: The first vertex of the second line.
eb1: The second vertex of the second line.

Returns
-------
The Jacobian of the unnormalized normal vector of the two edges.
The Jacobian of the unnormalized normal vector of the two lines.
)ipc_qu8mg5v7",
py::arg("ea0"), py::arg("ea1"), py::arg("eb0"), py::arg("eb1"));

m.def(
"edge_edge_normal_jacobian", &edge_edge_normal_jacobian,
"line_line_normal_jacobian", &line_line_normal_jacobian,
R"ipc_qu8mg5v7(
Computes the Jacobian of the normal vector of two edges.
Computes the Jacobian of the normal vector of two lines.

Parameters
----------
ea0: The first vertex of the first edge.
ea1: The second vertex of the first edge.
eb0: The first vertex of the second edge.
eb1: The second vertex of the second edge.
ea0: The first vertex of the first line.
ea1: The second vertex of the first line.
eb0: The first vertex of the second line.
eb1: The second vertex of the second line.

Returns
-------
The Jacobian of the normal vector of the two edges.
The Jacobian of the normal vector of the two lines.
)ipc_qu8mg5v7",
py::arg("ea0"), py::arg("ea1"), py::arg("eb0"), py::arg("eb1"));

m.def(
"edge_edge_unnormalized_normal_hessian",
&edge_edge_unnormalized_normal_hessian,
"line_line_unnormalized_normal_hessian",
&line_line_unnormalized_normal_hessian,
R"ipc_qu8mg5v7(
Computes the Hessian of the unnormalized normal vector of two edges.
Computes the Hessian of the unnormalized normal vector of two lines.

Parameters
----------
ea0: The first vertex of the first edge.
ea1: The second vertex of the first edge.
eb0: The first vertex of the second edge.
eb1: The second vertex of the second edge.
ea0: The first vertex of the first line.
ea1: The second vertex of the first line.
eb0: The first vertex of the second line.
eb1: The second vertex of the second line.

Returns
-------
The Hessian of the unnormalized normal vector of the two edges.
The Hessian of the unnormalized normal vector of the two lines.
)ipc_qu8mg5v7",
py::arg("ea0"), py::arg("ea1"), py::arg("eb0"), py::arg("eb1"));

m.def(
"edge_edge_normal_hessian", &edge_edge_normal_hessian,
"line_line_normal_hessian", &line_line_normal_hessian,
R"ipc_qu8mg5v7(
Computes the Hessian of the normal vector of two edges.
Computes the Hessian of the normal vector of two lines.

Parameters
----------
ea0: The first vertex of the first edge.
ea1: The second vertex of the first edge.
eb0: The first vertex of the second edge.
eb1: The second vertex of the second edge.
ea0: The first vertex of the first line.
ea1: The second vertex of the first line.
eb0: The first vertex of the second line.
eb1: The second vertex of the second line.

Returns
-------
The Hessian of the normal vector of the two edges.
The Hessian of the normal vector of the two lines.
)ipc_qu8mg5v7",
py::arg("ea0"), py::arg("ea1"), py::arg("eb0"), py::arg("eb1"));
}
4 changes: 2 additions & 2 deletions src/ipc/candidates/edge_edge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ VectorMax3d EdgeEdgeCandidate::compute_unnormalized_normal(
Eigen::ConstRef<VectorMax12d> positions) const
{
assert(positions.size() == 12);
return edge_edge_unnormalized_normal(
return line_line_unnormalized_normal(
positions.head<3>(), positions.segment<3>(3), positions.segment<3>(6),
positions.tail<3>());
}
Expand All @@ -110,7 +110,7 @@ EdgeEdgeCandidate::compute_unnormalized_normal_jacobian(
Eigen::ConstRef<VectorMax12d> positions) const
{
assert(positions.size() == 12);
return edge_edge_unnormalized_normal_jacobian(
return line_line_unnormalized_normal_jacobian(
positions.head<3>(), positions.segment<3>(3), positions.segment<3>(6),
positions.tail<3>());
}
Expand Down
Loading