src/utilities/geometry/Geometry.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #ifndef UTILITIES_GEOMETRY_GEOMETRY_HPP | ||
| 7 | #define UTILITIES_GEOMETRY_GEOMETRY_HPP | ||
| 8 | |||
| 9 | #include "../UtilitiesAPI.hpp" | ||
| 10 | |||
| 11 | #include <vector> | ||
| 12 | #include <boost/optional.hpp> | ||
| 13 | |||
| 14 | namespace openstudio { | ||
| 15 | |||
| 16 | class Point3d; | ||
| 17 | class PointLatLon; | ||
| 18 | class Vector3d; | ||
| 19 | |||
| 20 | /// convert degrees to radians | ||
| 21 | UTILITIES_API double degToRad(double degrees); | ||
| 22 | |||
| 23 | /// convert radians to degrees | ||
| 24 | UTILITIES_API double radToDeg(double radians); | ||
| 25 | |||
| 26 | // Forces an angle in degrees to be in the [0,360[ range | ||
| 27 | 69 | UTILITIES_API constexpr double normalizeAngle0to360(double angleDegrees) { | |
| 28 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 69 times.
|
83 | while (angleDegrees < 0.0) { |
| 29 | 14 | angleDegrees += 360.0; | |
| 30 | } | ||
| 31 | |||
| 32 | // This is twice as fast as using std::fmod(angleDegrees, 360.0) | ||
| 33 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 69 times.
|
77 | while (angleDegrees >= 360.0) { |
| 34 | 8 | angleDegrees -= 360.0; | |
| 35 | } | ||
| 36 | 69 | return angleDegrees; | |
| 37 | } | ||
| 38 | |||
| 39 | /// compute area from surface as Point3dVector | ||
| 40 | UTILITIES_API boost::optional<double> getArea(const std::vector<Point3d>& points); | ||
| 41 | |||
| 42 | /// compute Newell vector from surface as Point3dVector, direction is same as outward normal | ||
| 43 | /// magnitude is twice the area | ||
| 44 | UTILITIES_API boost::optional<Vector3d> getNewellVector(const std::vector<Point3d>& points); | ||
| 45 | |||
| 46 | /// compute outward normal from surface as Point3dVector | ||
| 47 | UTILITIES_API boost::optional<Vector3d> getOutwardNormal(const std::vector<Point3d>& points); | ||
| 48 | |||
| 49 | /// compute centroid from surface as Point3dVector | ||
| 50 | UTILITIES_API boost::optional<Point3d> getCentroid(const std::vector<Point3d>& points); | ||
| 51 | |||
| 52 | /// reorder points to upper-left-corner convention | ||
| 53 | UTILITIES_API std::vector<Point3d> reorderULC(const std::vector<Point3d>& points); | ||
| 54 | |||
| 55 | /// removes collinear points | ||
| 56 | UTILITIES_API std::vector<Point3d> removeCollinear(const std::vector<Point3d>& points, double tol = 0.001); | ||
| 57 | |||
| 58 | /// removes collinear points, tolerance is for length of cross product after normalizing each line segment | ||
| 59 | UTILITIES_API std::vector<Point3d> removeCollinearLegacy(const std::vector<Point3d>& points, double tol = 0.001); | ||
| 60 | |||
| 61 | /// return distance between two points | ||
| 62 | UTILITIES_API double getDistance(const Point3d& point1, const Point3d& point2); | ||
| 63 | |||
| 64 | /// return distance squared between two points | ||
| 65 | /// faster than getDistance; can be used to compare distances | ||
| 66 | UTILITIES_API double getDistanceSquared(const Point3d& point1, const Point3d& point2); | ||
| 67 | |||
| 68 | /// return distance between a point and a line segment | ||
| 69 | /// returns 0 if lineSegment does not have length 2 | ||
| 70 | UTILITIES_API double getDistancePointToLineSegment(const Point3d& point, const std::vector<Point3d>& lineSegment); | ||
| 71 | |||
| 72 | /// return distance between a point and a triangle | ||
| 73 | /// returns 0 if triangle does not have length 3 | ||
| 74 | UTILITIES_API double getDistancePointToTriangle(const Point3d& point, const std::vector<Point3d>& triangle); | ||
| 75 | |||
| 76 | /// return angle (in radians) between two vectors | ||
| 77 | UTILITIES_API double getAngle(const Vector3d& vector1, const Vector3d& vector2); | ||
| 78 | |||
| 79 | /// check if two vectors of points are equal (within tolerance) irregardless of initial ordering. | ||
| 80 | UTILITIES_API bool circularEqual(const std::vector<Point3d>& points1, const std::vector<Point3d>& points2, double tol = 0.001); | ||
| 81 | |||
| 82 | /// if point3d is within tol of any existing points then returns existing point | ||
| 83 | /// otherwise adds point3d to allPoints and returns point3d | ||
| 84 | UTILITIES_API Point3d getCombinedPoint(const Point3d& point3d, std::vector<Point3d>& allPoints, double tol = 0.001); | ||
| 85 | |||
| 86 | /// compute triangulation of vertices, holes are removed in the triangulation | ||
| 87 | /// requires that vertices and holes are in clockwise order on the z = 0 plane (i.e. in face coordinates but reversed) | ||
| 88 | UTILITIES_API std::vector<std::vector<Point3d>> computeTriangulation(const std::vector<Point3d>& vertices, | ||
| 89 | const std::vector<std::vector<Point3d>>& holes, double tol = 0.001); | ||
| 90 | |||
| 91 | /// move all vertices towards point by distance, pass negative distance to move away from point | ||
| 92 | /// no guarantee that resulting polygon will be valid | ||
| 93 | UTILITIES_API std::vector<Point3d> moveVerticesTowardsPoint(const std::vector<Point3d>& vertices, const Point3d& point, double distance); | ||
| 94 | |||
| 95 | /// reverse order of vertices | ||
| 96 | UTILITIES_API std::vector<Point3d> reverse(const std::vector<Point3d>& vertices); | ||
| 97 | |||
| 98 | /// Sets view and daylighting window, overhang and light shelf vertices by reference. Returns true if successful, false otherwise. | ||
| 99 | UTILITIES_API bool applyViewAndDaylightingGlassRatios(double viewGlassToWallRatio, double daylightingGlassToWallRatio, | ||
| 100 | double desiredViewGlassSillHeight, double desiredDaylightingGlassHeaderHeight, | ||
| 101 | double exteriorShadingProjectionFactor, double interiorShelfProjectionFactor, | ||
| 102 | const std::vector<Point3d>& surfaceVertices, std::vector<Point3d>& viewVertices, | ||
| 103 | std::vector<Point3d>& daylightingVertices, std::vector<Point3d>& exteriorShadingVertices, | ||
| 104 | std::vector<Point3d>& interiorShelfVertices); | ||
| 105 | |||
| 106 | // Checks that a point is **almost** equal to another (with some tolerance) | ||
| 107 | UTILITIES_API bool isAlmostEqual3dPt(const Point3d& lhs, const Point3d& rhs, double tol = 0.0127); | ||
| 108 | |||
| 109 | UTILITIES_API bool isPointOnLineBetweenPoints(const Point3d& start, const Point3d& end, const Point3d& test, double tol = 0.0127); | ||
| 110 | |||
| 111 | } // namespace openstudio | ||
| 112 | |||
| 113 | #endif //UTILITIES_GEOMETRY_GEOMETRY_HPP | ||
| 114 |