compute Newell vector from Point3dVector, direction is same as outward normal magnitude is twice the area
| 40 | // compute Newell vector from Point3dVector, direction is same as outward normal |
| 41 | // magnitude is twice the area |
| 42 | OptionalVector3d getNewellVector(const Point3dVector& points) { |
| 43 | OptionalVector3d result; |
| 44 | const size_t N = points.size(); |
| 45 | if (N >= 3) { |
| 46 | Vector3d vec; |
| 47 | for (unsigned i = 1; i < N - 1; ++i) { |
| 48 | const Vector3d v1 = points[i] - points[0]; |
| 49 | const Vector3d v2 = points[i + 1] - points[0]; |
| 50 | vec += v1.cross(v2); |
| 51 | } |
| 52 | result = vec; |
| 53 | } |
| 54 | return result; |
| 55 | } |
| 56 | |
| 57 | // compute outward normal from Point3dVector |
| 58 | OptionalVector3d getOutwardNormal(const Point3dVector& points) { |