-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f309b6
commit 4bdf394
Showing
5 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ members = [ | |
|
||
"models/cuboid", | ||
"models/spacer", | ||
"models/star", | ||
|
||
"tools/autolib", | ||
"tools/automator", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "star" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies.fj] | ||
path = "../../crates/fj" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use std::f64::consts::PI; | ||
|
||
use fj::{ | ||
core::{ | ||
algorithms::sweep::Sweep, | ||
objects::{Cycle, Region, Sketch, Solid}, | ||
operations::{ | ||
BuildCycle, BuildRegion, BuildSketch, Insert, Reverse, | ||
UpdateRegion, UpdateSketch, | ||
}, | ||
services::Services, | ||
storage::Handle, | ||
}, | ||
math::Vector, | ||
}; | ||
|
||
pub fn model(num_points: u64, r1: f64, r2: f64, h: f64) -> Handle<Solid> { | ||
let mut services = Services::new(); | ||
|
||
let num_vertices = num_points * 2; | ||
let vertex_iter = (0..num_vertices).map(|i| { | ||
let angle_rad = 2. * PI / num_vertices as f64 * i as f64; | ||
let radius = if i % 2 == 0 { r1 } else { r2 }; | ||
(angle_rad, radius) | ||
}); | ||
|
||
let mut outer_points = Vec::new(); | ||
let mut inner_points = Vec::new(); | ||
|
||
for (angle_rad, radius) in vertex_iter { | ||
let (sin, cos) = angle_rad.sin_cos(); | ||
|
||
let x = cos * radius; | ||
let y = sin * radius; | ||
|
||
outer_points.push([x, y]); | ||
inner_points.push([x / 2., y / 2.]); | ||
} | ||
|
||
let sketch = Sketch::empty() | ||
.add_region( | ||
Region::polygon(outer_points, &mut services) | ||
.add_interiors([Cycle::polygon(inner_points, &mut services) | ||
.reverse(&mut services) | ||
.insert(&mut services)]) | ||
.insert(&mut services), | ||
) | ||
.insert(&mut services); | ||
|
||
let surface = services.objects.surfaces.xy_plane(); | ||
let path = Vector::from([0., 0., h]); | ||
(sketch, surface).sweep(path, &mut services) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use fj::handle_model; | ||
|
||
fn main() -> fj::Result { | ||
let model = star::model(5, 1., 2., 1.); | ||
handle_model(model)?; | ||
Ok(()) | ||
} |