Skip to content

Commit 24ac1fe

Browse files
author
mlund
committed
Add area calculation to example
1 parent a90dde3 commit 24ac1fe

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

examples/lookup.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use duello::IcoSphere;
22
use hexasphere::AdjacencyBuilder;
33
fn main() {
4-
let n_divisions = 0;
4+
let n_divisions = 1;
55
let icosphere = IcoSphere::new(n_divisions, |_| ());
66

77
let indices = icosphere.get_all_indices();
@@ -18,6 +18,17 @@ fn main() {
1818
for (i, triangle) in indices.chunks(3).enumerate() {
1919
println!("{} [{}, {}, {}]", i, triangle[0], triangle[1], triangle[2],);
2020
}
21+
22+
println!("\nFaces areas:");
23+
for (n, triangle) in indices.chunks(3).enumerate() {
24+
let a = vertices[triangle[0] as usize];
25+
let b = vertices[triangle[1] as usize];
26+
let c = vertices[triangle[2] as usize];
27+
let ab = b - a;
28+
let ac = c - a;
29+
println!("Area of face {}: {}", n, 0.5 * ab.cross(ac).length());
30+
}
31+
2132
let mut ab = AdjacencyBuilder::new(vertices.len());
2233
ab.add_indices(&indices);
2334
let adjency = ab.finish();

0 commit comments

Comments
 (0)