File tree 5 files changed +38
-0
lines changed
5 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,8 @@ New measurement/analysis features:
72
72
* New option for displaying areas of closed contours.
73
73
* When calculating volume of the mesh, volume of the solid from the current
74
74
group is now shown alongside total volume of all solids.
75
+ * When calculating area, and faces are selected, calculate area of those faces
76
+ instead of the closed contour in the sketch.
75
77
* When selecting a point and a line, projected distance to current
76
78
workplane is displayed.
77
79
Original file line number Diff line number Diff line change @@ -1181,3 +1181,14 @@ double SMesh::CalculateVolume() const {
1181
1181
}
1182
1182
return vol;
1183
1183
}
1184
+
1185
+ double SMesh::CalculateSurfaceArea (const std::vector<uint32_t > &faces) const {
1186
+ double area = 0.0 ;
1187
+ for (uint32_t f : faces) {
1188
+ for (const STriangle &t : l) {
1189
+ if (f != t.meta .face ) continue ;
1190
+ area += t.Area ();
1191
+ }
1192
+ }
1193
+ return area;
1194
+ }
Original file line number Diff line number Diff line change @@ -87,6 +87,12 @@ double STriangle::SignedVolume() const {
87
87
return a.Dot (b.Cross (c)) / 6.0 ;
88
88
}
89
89
90
+ double STriangle::Area () const {
91
+ Vector ab = a.Minus (b);
92
+ Vector cb = c.Minus (b);
93
+ return ab.Cross (cb).Magnitude () / 2.0 ;
94
+ }
95
+
90
96
bool STriangle::IsDegenerate () const {
91
97
return a.OnLineSegment (b, c) ||
92
98
b.OnLineSegment (a, c) ||
Original file line number Diff line number Diff line change @@ -191,6 +191,7 @@ class STriangle {
191
191
bool Raytrace (const Vector &rayPoint, const Vector &rayDir,
192
192
double *t, Vector *inters) const ;
193
193
double SignedVolume () const ;
194
+ double Area () const ;
194
195
bool IsDegenerate () const ;
195
196
};
196
197
@@ -281,6 +282,7 @@ class SMesh {
281
282
void PrecomputeTransparency ();
282
283
void RemoveDegenerateTriangles ();
283
284
double CalculateVolume () const ;
285
+ double CalculateSurfaceArea (const std::vector<uint32_t > &faces) const ;
284
286
285
287
bool IsEmpty () const ;
286
288
void RemapFaces (Group *g, int remap);
Original file line number Diff line number Diff line change @@ -797,6 +797,23 @@ void SolveSpaceUI::MenuAnalyze(Command id) {
797
797
798
798
case Command::AREA: {
799
799
Group *g = SK.GetGroup (SS.GW .activeGroup );
800
+ SS.GW .GroupSelection ();
801
+ auto const &gs = SS.GW .gs ;
802
+ double scale = SS.MmPerUnit ();
803
+
804
+ if (gs.faces > 0 ) {
805
+ std::vector<uint32_t > faces;
806
+ faces.push_back (gs.face [0 ].v );
807
+ if (gs.faces > 1 ) faces.push_back (gs.face [1 ].v );
808
+ double area = g->displayMesh .CalculateSurfaceArea (faces);
809
+ Message (_ (" The surface area of the selected faces is:\n\n "
810
+ " %s\n\n "
811
+ " Curves have been approximated as piecewise linear.\n "
812
+ " This introduces error, typically of around 1%%." ),
Has comments. Original line has comments.
813
+ SS.MmToStringSI (area, /* dim=*/ 2 ).c_str ());
814
+ break ;
815
+ }
816
+
800
817
if (g->polyError .how != PolyError::GOOD) {
801
818
Error (_ (" This group does not contain a correctly-formed "
802
819
" 2d closed area. It is open, not coplanar, or self-"
You can’t perform that action at this time.