Skip to content
Snippets Groups Projects

Fix point distance calculation

Merged Stephan Schulz requested to merge all_point_fix into master
3 files
+ 41
22
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 19
22
@@ -220,31 +220,17 @@ public:
@@ -220,31 +220,17 @@ public:
throw PointDimensionMissmatchException(__FILE__, __func__, __LINE__);
throw PointDimensionMissmatchException(__FILE__, __func__, __LINE__);
// vectors spanning the plane from vertex 'a'
// vectors spanning the plane from vertex 'a'
T vb[3];
Point<T> vb = B - A;
T vc[3];
Point<T> vc = C - A;
for (int i = 0; i < 3; ++i) {
vb[i] = B[i] - A[i];
vc[i] = C[i] - A[i];
}
// normal vector of plane
// normal vector of plane
T n[3];
Point<T> n = vb.cross(vc);
n = n/n.norm();
n[0] = vb[1] * vc[2] - vb[2] * vc[1];
n[1] = vb[2] * vc[0] - vb[0] * vc[2];
n[2] = vb[0] * vc[1] - vb[1] * vc[0];
// length of normal vector
T dn = n.norm();
// distance from origin
// return r.n - A.n = (r-A).n as distance from plane to r
T d = n * A;
return std::abs( (coordinates.at(0) - A[0]) * n[0] +
(coordinates.at(1) - A[1]) * n[1] +
// compute distance of test vertex to plane
(coordinates.at(2) - A[2]) * n[2] );
return std::abs((n[0] * coordinates.at(0) + n[1] * coordinates.at(1) +
n[2] * coordinates.at(2) - d) /
dn);
}
}
/// operator for the addition of two point objects
/// operator for the addition of two point objects
@@ -301,6 +287,17 @@ public:
@@ -301,6 +287,17 @@ public:
return result;
return result;
}
}
 
/// operator to scale the local point object by a provided factor
 
/// @param rhs scaling factor
 
/// @return scaled point object
 
Point<T> operator/(const T &rhs) const {
 
Point<T> result(dimension);
 
for (int d = 0; d < dimension; ++d) {
 
result[d] = coordinates.at(d) / rhs;
 
}
 
return result;
 
}
 
/// operator to compute the cross product between two point objects
/// operator to compute the cross product between two point objects
/// @param rhs point object to compute the cross product with
/// @param rhs point object to compute the cross product with
/// @return cross product between the two point objects
/// @return cross product between the two point objects
Loading