From 04be907cbba161af7eda231f8a6a1856fc3a6042 Mon Sep 17 00:00:00 2001 From: Franz Zotter Date: Sat, 25 Aug 2012 22:51:30 +0000 Subject: improved deterministic behavior of [mtx_qhull], however planar polygons do not fully work yet. svn path=/trunk/externals/iem/iemmatrix/; revision=16172 --- src/mtx_qhull/vectors.c | 139 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 125 insertions(+), 14 deletions(-) (limited to 'src/mtx_qhull/vectors.c') diff --git a/src/mtx_qhull/vectors.c b/src/mtx_qhull/vectors.c index 6cc3dd8..d9d3bd0 100644 --- a/src/mtx_qhull/vectors.c +++ b/src/mtx_qhull/vectors.c @@ -1,7 +1,4 @@ #include "vectors.h" -#include -#include -#include vector_t initVector (float x, float y, float z) { @@ -9,13 +6,16 @@ vector_t initVector (float x, float y, float z) { return vec; } +float lengthVector(vector_t v) { + return sqrtf(v.c[0]*v.c[0]+v.c[1]*v.c[1]+v.c[2]*v.c[2]); +} vector_t normalizeVector(vector_t v) { - float r=sqrtf(v.c[0]*v.c[0]+v.c[1]*v.c[1]+v.c[2]*v.c[2]); + float r=lengthVector(v); v.c[0]/=r; v.c[1]/=r; v.c[2]/=r; return v; -}; +} plane_t initPlane (vector_t normal, vector_t point) { plane_t plane; @@ -24,6 +24,13 @@ plane_t initPlane (vector_t normal, vector_t point) { return plane; } +line_t initLine (vector_t direction, vector_t point) { + line_t line; + line.point = point; + line.direction = normalizeVector(direction); + return line; +} + points_t initPoints (const float *x, const float *y, const float *z, size_t num_points) { @@ -63,11 +70,29 @@ float innerProduct (vector_t v1, vector_t v2) { return v1.c[0]*v2.c[0] + v1.c[1]*v2.c[1] + v1.c[2]*v2.c[2]; } +float distancePointPoint(const vector_t a, + const vector_t b) { + vector_t d=subtractVectors(b,a); + return lengthVector(d); +} + float distancePointPlane (vector_t point, plane_t plane) { return innerProduct(point, plane.normal) - innerProduct(plane.point, plane.normal); } +float distancePointLine (vector_t point, line_t line) { + return lengthVector(crossProduct(line.direction, + subtractVectors(point,line.point))); +} + +float distancePointLineOnPlane (vector_t point, + line_t line, plane_t plane) { + vector_t normal_in_plane = normalizeVector(crossProduct( + line.direction, plane.normal)); + return innerProduct(subtractVectors(point,line.point),normal_in_plane); +} + vector_t addVectors(vector_t v1, vector_t v2) { vector_t v3; v3.c[0]=v1.c[0]+v2.c[0]; @@ -92,31 +117,113 @@ vector_t scaleVector(vector_t v1, float f) { return v2; } +/* vector_t averagePoints(points_t points) { vector_t m = initVector(0.0f, 0.0f, 0.0f); size_t i; - for (i=0; i=0)&&(index