Add SweptCurve::plane_from_coord_system

This commit is contained in:
Hanno Braun 2025-04-10 12:41:19 +02:00
parent dcc3f47415
commit c8b4c4be96
2 changed files with 21 additions and 8 deletions

View File

@ -8,6 +8,21 @@ pub struct SweptCurve {
}
impl SweptCurve {
pub fn plane_from_coord_system(
origin: impl Into<Point<3>>,
axes: [impl Into<Vector<3>>; 2],
) -> Self {
let origin = origin.into();
let [u, v] = axes.map(Into::into);
let line = Line::from_origin_and_direction(origin, u);
Self {
curve: Box::new(line),
path: v,
}
}
pub fn plane_from_points(points: [impl Into<Point<3>>; 3]) -> Self {
let [a, b, c] = points.map(Into::into);
@ -63,11 +78,10 @@ mod tests {
#[test]
fn project_point() {
let plane = SweptCurve::plane_from_points([
let plane = SweptCurve::plane_from_coord_system(
[1., 1., 1.],
[2., 1., 1.],
[1., 2., 1.],
]);
[[1., 0., 0.], [0., 1., 0.]],
);
assert_eq!(plane.project_point([2., 2., 2.]), Point::from([1., 1.]));
}

View File

@ -29,11 +29,10 @@ pub fn model(viewer: &Viewer) -> TriMesh {
// we're done here.
let surface = Handle::new(Surface {
geometry: Box::new(SweptCurve::plane_from_points([
geometry: Box::new(SweptCurve::plane_from_coord_system(
[0., 0., 1.],
[1., 0., 1.],
[0., 1., 1.],
])),
[[1., 0., 0.], [0., 1., 0.]],
)),
});
let face = sketch.to_face(surface);