[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41767] trunk/blender/source/blender: mathutils.geometry.distance_point_to_plane(pt, plane_co, plane_no) - utility function, BLI math version too.
Campbell Barton
ideasman42 at gmail.com
Sat Nov 12 11:06:56 CET 2011
Revision: 41767
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41767
Author: campbellbarton
Date: 2011-11-12 10:06:56 +0000 (Sat, 12 Nov 2011)
Log Message:
-----------
mathutils.geometry.distance_point_to_plane(pt, plane_co, plane_no) - utility function, BLI math version too.
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_math_geom.h
trunk/blender/source/blender/blenlib/intern/math_geom.c
trunk/blender/source/blender/python/mathutils/mathutils_geometry.c
Modified: trunk/blender/source/blender/blenlib/BLI_math_geom.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_geom.h 2011-11-12 09:02:24 UTC (rev 41766)
+++ trunk/blender/source/blender/blenlib/BLI_math_geom.h 2011-11-12 10:06:56 UTC (rev 41767)
@@ -60,6 +60,7 @@
float dist_to_line_segment_v2(const float p[2], const float l1[2], const float l2[2]);
void closest_to_line_segment_v2(float closest[2], const float p[2], const float l1[2], const float l2[2]);
+float dist_to_plane_v3(const float p[2], const float plane_co[3], const float plane_no[2]);
float dist_to_line_segment_v3(const float p[3], const float l1[3], const float l2[3]);
float closest_to_line_v3(float r[3], const float p[3], const float l1[3], const float l2[3]);
float closest_to_line_v2(float r[2], const float p[2], const float l1[2], const float l2[2]);
Modified: trunk/blender/source/blender/blenlib/intern/math_geom.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom.c 2011-11-12 09:02:24 UTC (rev 41766)
+++ trunk/blender/source/blender/blenlib/intern/math_geom.c 2011-11-12 10:06:56 UTC (rev 41767)
@@ -237,6 +237,18 @@
copy_v3_v3(closest, cp);
}
+/* signed distance from the point to the plane in 3D */
+float dist_to_plane_v3(const float p[2], const float plane_co[3], const float plane_no[2])
+{
+ float plane_no_unit[3];
+ float plane_co_other[3];
+
+ normalize_v3_v3(plane_no_unit, plane_no);
+ add_v3_v3v3(plane_co_other, plane_co, plane_no_unit);
+
+ return -line_point_factor_v3(p, plane_co, plane_co_other);
+}
+
/* distance v1 to line-piece v2-v3 in 3D */
float dist_to_line_segment_v3(const float v1[3], const float v2[3], const float v3[3])
{
Modified: trunk/blender/source/blender/python/mathutils/mathutils_geometry.c
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils_geometry.c 2011-11-12 09:02:24 UTC (rev 41766)
+++ trunk/blender/source/blender/python/mathutils/mathutils_geometry.c 2011-11-12 10:06:56 UTC (rev 41767)
@@ -420,7 +420,7 @@
return NULL;
}
- if ( BaseMath_ReadCallback(line_a) == -1 ||
+ if ( BaseMath_ReadCallback(line_a) == -1 ||
BaseMath_ReadCallback(line_b) == -1 ||
BaseMath_ReadCallback(plane_co) == -1 ||
BaseMath_ReadCallback(plane_no) == -1
@@ -559,7 +559,7 @@
return NULL;
}
- if ( BaseMath_ReadCallback(line_a) == -1 ||
+ if ( BaseMath_ReadCallback(line_a) == -1 ||
BaseMath_ReadCallback(line_b) == -1 ||
BaseMath_ReadCallback(sphere_co) == -1
) {
@@ -686,7 +686,7 @@
" Takes 5 vectors (using only the x and y coordinates): one is the point and the next 4 define the quad, only the x and y are used from the vectors. Returns 1 if the point is within the quad, otherwise 0.\n"
"\n"
" :arg pt: Point\n"
-" :type v1: :class:`mathutils.Vector`\n"
+" :type pt: :class:`mathutils.Vector`\n"
" :arg quad_p1: First point of the quad\n"
" :type quad_p1: :class:`mathutils.Vector`\n"
" :arg quad_p2: Second point of the quad\n"
@@ -717,6 +717,42 @@
return PyLong_FromLong(isect_point_quad_v2(pt_vec->vec, quad_p1->vec, quad_p2->vec, quad_p3->vec, quad_p4->vec));
}
+PyDoc_STRVAR(M_Geometry_distance_point_to_plane_doc,
+".. function:: distance_point_to_plane(pt, plane_co, plane_no)\n"
+"\n"
+" Returns the signed distance between a point and a plane "
+" (negative when below the normal).\n"
+"\n"
+" :arg pt: Point\n"
+" :type pt: :class:`mathutils.Vector`\n"
+" :arg plane_co: First point of the quad\n"
+" :type plane_co: :class:`mathutils.Vector`\n"
+" :arg plane_no: Second point of the quad\n"
+" :type plane_no: :class:`mathutils.Vector`\n"
+" :rtype: float\n"
+);
+static PyObject *M_Geometry_distance_point_to_plane(PyObject *UNUSED(self), PyObject* args)
+{
+ VectorObject *pt, *plene_co, *plane_no;
+
+ if (!PyArg_ParseTuple(args, "O!O!O!:distance_point_to_plane",
+ &vector_Type, &pt,
+ &vector_Type, &plene_co,
+ &vector_Type, &plane_no)
+ ) {
+ return NULL;
+ }
+
+ if ( BaseMath_ReadCallback(pt) == -1 ||
+ BaseMath_ReadCallback(plene_co) == -1 ||
+ BaseMath_ReadCallback(plane_no) == -1)
+ {
+ return NULL;
+ }
+
+ return PyFloat_FromDouble(dist_to_plane_v3(pt->vec, plene_co->vec, plane_no->vec));
+}
+
PyDoc_STRVAR(M_Geometry_barycentric_transform_doc,
".. function:: barycentric_transform(point, tri_a1, tri_a2, tri_a3, tri_b1, tri_b2, tri_b3)\n"
"\n"
@@ -1103,6 +1139,7 @@
{"intersect_line_plane", (PyCFunction) M_Geometry_intersect_line_plane, METH_VARARGS, M_Geometry_intersect_line_plane_doc},
{"intersect_line_sphere", (PyCFunction) M_Geometry_intersect_line_sphere, METH_VARARGS, M_Geometry_intersect_line_sphere_doc},
{"intersect_line_sphere_2d", (PyCFunction) M_Geometry_intersect_line_sphere_2d, METH_VARARGS, M_Geometry_intersect_line_sphere_2d_doc},
+ {"distance_point_to_plane", (PyCFunction) M_Geometry_distance_point_to_plane, METH_VARARGS, M_Geometry_distance_point_to_plane_doc},
{"area_tri", (PyCFunction) M_Geometry_area_tri, METH_VARARGS, M_Geometry_area_tri_doc},
{"normal", (PyCFunction) M_Geometry_normal, METH_VARARGS, M_Geometry_normal_doc},
{"barycentric_transform", (PyCFunction) M_Geometry_barycentric_transform, METH_VARARGS, M_Geometry_barycentric_transform_doc},
More information about the Bf-blender-cvs
mailing list