brep_kernel/props/
mass_properties.rs1use crate::topology::{BrepSolid, EdgeRecord, FaceRecord, ShellRecord};
2use crate::{NurbsCurve, NurbsSurface, Vec3};
3use serde::Serialize;
4
5const GAUSS_X: [f64; 8] = [
6 -0.9602898564975363,
7 -0.7966664774136267,
8 -0.525532409916329,
9 -0.18343464249564978,
10 0.18343464249564978,
11 0.525532409916329,
12 0.7966664774136267,
13 0.9602898564975363,
14];
15const GAUSS_W: [f64; 8] = [
16 0.10122853629037669,
17 0.22238103445337445,
18 0.31370664587788727,
19 0.362683783378362,
20 0.362683783378362,
21 0.31370664587788727,
22 0.22238103445337445,
23 0.10122853629037669,
24];
25
26#[derive(Clone, Copy)]
27enum Integrand {
28 Area,
29 Volume,
30 VolumeAbout(Vec3),
31 MomentX,
33 MomentY,
34 MomentZ,
35 SecondXX,
37 SecondYY,
38 SecondZZ,
39 ProductXY,
41 ProductXZ,
42 ProductYZ,
43}
44
45#[derive(Clone, Copy, Debug, Serialize)]
46pub struct MassProperties {
47 pub surface_area: f64,
48 pub volume: f64,
49}
50
51#[derive(Clone, Copy, Debug, Serialize)]
52pub struct FullMassProperties {
53 pub surface_area: f64,
54 pub volume: f64,
55 pub centroid: Vec3,
57 pub inertia: [[f64; 3]; 3],
60 pub principal_moments: [f64; 3],
64 pub principal_axes: [[f64; 3]; 3],
70}
71
72#[derive(Clone, Copy, Debug, Serialize)]
79pub struct DensityMassProperties {
80 pub density: f64,
82 pub mass: f64,
84 pub surface_area: f64,
85 pub volume: f64,
86 pub centroid: Vec3,
88 pub inertia: [[f64; 3]; 3],
90 pub principal_moments: [f64; 3],
92 pub principal_axes: [[f64; 3]; 3],
94}
95
96impl FullMassProperties {
97 pub fn with_density(&self, density: f64) -> DensityMassProperties {
104 let scale = |matrix: [[f64; 3]; 3]| {
105 let mut out = [[0.0f64; 3]; 3];
106 for row in 0..3 {
107 for column in 0..3 {
108 out[row][column] = density * matrix[row][column];
109 }
110 }
111 out
112 };
113 DensityMassProperties {
114 density,
115 mass: density * self.volume,
116 surface_area: self.surface_area,
117 volume: self.volume,
118 centroid: self.centroid,
119 inertia: scale(self.inertia),
120 principal_moments: [
121 density * self.principal_moments[0],
122 density * self.principal_moments[1],
123 density * self.principal_moments[2],
124 ],
125 principal_axes: self.principal_axes,
126 }
127 }
128}
129
130
131#[path = "mass_properties/integration.rs"]
132mod integration;
133#[path = "mass_properties/measures.rs"]
134mod measures;
135#[path = "mass_properties/polygons.rs"]
136mod polygons;
137#[path = "mass_properties/solid_props.rs"]
138mod solid_props;
139#[path = "mass_properties/trimmed.rs"]
140mod trimmed;
141#[path = "mass_properties/winding.rs"]
142mod winding;
143use integration::*;
146use measures::*;
147use polygons::*;
148use trimmed::*;
149
150pub use integration::parameter_space_area;
151pub use measures::{
152 curve_arc_length, edge_arc_length, face_area, face_boundary_length,
153 face_volume_contribution, solid_edge_length_total,
154};
155pub use solid_props::{solid_mass_properties, solid_mass_properties_full, solid_signed_volume};
156pub(crate) use solid_props::shell_signed_volume;
157pub use polygons::trim_polygons;