MCPcopy Create free account
hub / github.com/SimVascular/SimVascular / PyUtilComputeNormalFromlPoints

Function PyUtilComputeNormalFromlPoints

Code/Source/PythonAPI/PyUtils.cxx:608–644  ·  view source on GitHub ↗

-------------------------------- PyUtilComputeNormalFromlPoints -------------------------------- Compute a normal from a list of points.

Source from the content-addressed store, hash-verified

606// Compute a normal from a list of points.
607//
608std::array<double,3>
609PyUtilComputeNormalFromlPoints(const std::vector<std::array<double,3>>& points)
610{
611 std::array<double,3> normal;
612
613 if (points.size() < 3) {
614 throw std::runtime_error("[PyUtilComputeNormalFromlPoints] The number of points is < 3.");
615 }
616
617 int numPoints = points.size();
618 double nx = 0.0, ny = 0.0, nz = 0.0, mag;
619 int j;
620
621 for (int i = 0; i < numPoints; i++) {
622 if (i == (numPoints - 1)) {
623 j = 0;
624 } else {
625 j = i + 1;
626 }
627
628 nx += points[j][2]*points[i][1] - points[j][1]*points[i][2];
629 ny += points[j][0]*points[i][2] - points[j][2]*points[i][0];
630 nz += points[j][1]*points[i][0] - points[j][0]*points[i][1];
631 }
632
633 mag = sqrt(nx*nx + ny*ny + nz*nz);
634
635 if (mag == 0.0) {
636 throw std::runtime_error("[PyUtilComputeNormalFromlPoints] Points produced a magnitude zero normal.");
637 }
638
639 normal[0] = nx / mag;
640 normal[1] = ny / mag;
641 normal[2] = nz / mag;
642
643 return normal;
644}
645
646//------------------------
647// PyUtilSetupApiFunction

Callers 3

PyPolygonGenerateDataFunction · 0.85
PyContourGenerateDataFunction · 0.85

Calls 1

sizeMethod · 0.80

Tested by

no test coverage detected