A block, the box from (−6, −6, −8) to (36, 26, 0), with a groove cut into its top face by a ball of radius 3 carried along a curve. The ball's center follows the cubic Bézier curve in the top face (z = 0) whose control points are (0, 0, 0), (10, 0, 0), (20, 20, 0) and (30, 20, 0), from its first end to its last. Cut from the block everything the ball passes through.
The groove is half of the tube of radius 3 about the curve, closed at each end by a quarter of the ball. The curve's tightest turn has a radius of about 7.5, more than the ball's, so the tube does not fold on itself.
expected
closed form
volume
10173.82871
no closed form (the Bézier's arc length is an integral): OCCT and cad-kernel, built independently from this description, agree to 9e-12 (10173.828705331523 and 10173.828705425067; the mean)
area
4026.639233
no closed form (the Bézier's arc length is an integral): OCCT and cad-kernel, built independently from this description, agree to 3e-11 (4026.6392330649683 and 4026.6392331656834; the mean)
Drawing
TopIsometricFrontRight
Third-angle projection, the three views at one scale. Drawn from occt's result, which passed.
† works around a missing feature. ✦ an elegant solution. ▦ a faceted solid: a mesh stored as B-rep faces. Pick an entry to see its solid, its measures and its code.
Drag to turn, scroll or pinch to zoom, right-drag to move. The solid as its STEP file has it, meshed in the browser by Open CASCADE (occt-import-js): each face colored by the kind of its surface, and the edges that bound each face drawn between them.
Drag to turn, scroll or pinch to zoom, right-drag to move. Black lines are where the surface turns sharply; red ones, seen through the solid, are open edges, where the mesh is not closed.
Time
133 ms; CPU time 141 ms; peak memory 15.2 MB
Notes
pass Its volume and area are the expected ones, and its mesh is closed.
Workaround † no sweep of a solid along a curve
Its volume and area are its STEP file's, as the harness measures them from the file's exact geometry (harness/mass/); its triangles are Open CASCADE's mesh of the file, for the pictures.
Data
its STEP's
expected
rel. error
volume
10173.8287
10173.82871
3.8e-11
area
4026.639233
4026.639233
6.4e-12
agrees with
occt, next.BREP, cadrs, springrep, geomsolver
mesh
19737 triangles, closed, 1 degenerate
centre of gravity
(15, 10, -4.15578) its STEP's solid
inertia
about it, of unit density: Ixx 939383; Iyy 1.58305e+06; Izz 2.41765e+06; Ixy 37340.5; Iyz -7.23116e-05; Izx 0.000229881
//! A block (−6, −6, −8)–(36, 26, 0) with a groove cut into its top face by a ball of radius 3//! whose centre runs along the cubic Bézier curve (0, 0, 0), (10, 0, 0), (20, 20, 0), (30, 20, 0)//! in the top face, from its first end to its last.usecrate::sketch::block;
use cad_kernel::boolean::{combined, Op};
use cad_kernel::build::{capped, seam};
use cad_kernel::family::{family, Run, Sheet, Stations, Wall, NODES};
use cad_kernel::geom::V;
use cad_kernel::nurbs::BSpline;
use cad_kernel::recipe::FamilyWall;
use cad_kernel::topo::Brep;
use cad_kernel::util::space::{cross, scale, unit};
use std::f64::consts::TAU;
use std::sync::Arc;
constCONTROL: [V; 4] = [[0., 0., 0.], [10., 0., 0.], [20., 20., 0.], [30., 20., 0.]];
constRADIUS: f64 = 3.;
/// The curve's plane's normal, the top face's.constUP: V = [0., 0., 1.];
/// How many pieces the curve's parameter is read in, six stations each: between them the disc's/// centre and its two radius vectors are the degree-five polynomials through their solved values.constPIECES: usize = 24;
pubfnbuild() -> Result<Brep, String> {
let stock = block([-6., -6., -8.], [36., 26., 0.])?;
// the path as cad-kernel holds a Bézier segment: a cubic B-spline on clamped knotslet knots = vec![0., 0., 0., 0., 1., 1., 1., 1.];
let path = BSpline::new(3, knots, CONTROL.to_vec())?;
// a ball carried along a path no closed form carries sweeps the ball's disc square to the// path, a face family over the path's parameter, closed by the half ball beyond each end disc// (cad-kernel's `capped`): the parameter in pieces, each with six stations at the// Gauss–Lobatto nodeslet step = 1. / PIECESas f64;
let spans: Vec<[f64; 2]> =
(0..PIECES).map(|j| [step * j as f64, step * (j + 1) as f64]).collect();
let at = spans.iter().map(|&[a, b]| NODES.map(|t| (a + b) / 2. + t * (b - a) / 2.)).collect();
let stations = Arc::new(Stations::new(spans, at)?);
// at each station the disc's whole circle: centred on the path, square to its tangent, its// first radius vector turned off the top face by the kernel's `seam`, so the wall's seam and// the end balls' poles stay out of the plane the groove is cut fromlet nodes: Vec<Vec<f64>> = stations.at.iter().flatten().map(|&t| {
let (centre, tangent) = path.d1(t);
let along = unit(tangent);
let first = scale(seam(along, unit(cross(UP, along))), RADIUS);
let quarter = cross(along, first);
[centre, first, quarter].concat().into_iter().chain([TAU]).collect()
}).collect();
let sheet = Sheet::new(Run::Round, stations.clone(), nodes.clone(), true)?;
let tube = family(&[vec![Wall { sheet: Arc::new(sheet), name: "groove".into() }]], 0., None)?;
let wall = FamilyWall { name: "groove".into(), run: Run::Round, closed: true, nodes };
let swept = capped(tube, &[vec![wall]], RADIUS, "groove")?;
Ok(combined(&stock, &swept, Op::Cut, 0.)?)
}
Time
697 ms; CPU time 697 ms; peak memory 370.2 MB
Notes
pass Its volume and area are the expected ones, and its mesh is closed.
Workaround † no sweep of a solid
Its volume and area are its STEP file's, as the harness measures them from the file's exact geometry (harness/mass/); its triangles are Open CASCADE's mesh of the file, for the pictures.
"""A groove carried along a spline by a ball. A block, the box from (−6, −6, −8) to (36, 26, 0),
with a groove cut into its top face by a ball of radius 3 carried along a curve. The ball's centre
follows the cubic Bézier curve in the top face (z = 0) whose control points are (0, 0, 0),
(10, 0, 0), (20, 20, 0) and (30, 20, 0), from its first end to its last. Cut from the block
everything the ball passes through.
The groove is half of the tube of radius 3 about the curve, closed at each end by a quarter of the
ball. The curve's tightest turn has a radius of about 7.5, more than the ball's, so the tube does
not fold on itself."""fromOCP.BRepAdaptorimportBRepAdaptor_CurvefromOCP.BRepAlgoAPIimportBRepAlgoAPI_CutfromOCP.BRepBuilderAPIimportBRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeWirefromOCP.BRepOffsetAPIimportBRepOffsetAPI_MakePipeShellfromOCP.BRepPrimAPIimportBRepPrimAPI_MakeBox, BRepPrimAPI_MakeSpherefromOCP.GeomimportGeom_BezierCurvefromOCP.collections importArray1_gp_PntfromOCP.gp import gp_Ax2, gp_Circ, gp_Dir, gp_Pnt, gp_Vec
from bench importRefusedBLOCK_LOW, BLOCK_HIGH = (-6, -6, -8), (36, 26, 0)
CONTROL = [(0, 0, 0), (10, 0, 0), (20, 20, 0), (30, 20, 0)]
BALL_RADIUS = 3defbezier(points):
poles = Array1_gp_Pnt(1, len(points))
for i, p inenumerate(points):
poles.SetValue(i + 1, gp_Pnt(*p))
returnBRepBuilderAPI_MakeEdge(Geom_BezierCurve(poles)).Edge()
defbuild():
path = bezier(CONTROL)
curve = BRepAdaptor_Curve(path)
start, tangent = gp_Pnt(), gp_Vec()
curve.D1(curve.FirstParameter(), start, tangent)
end = curve.Value(curve.LastParameter())
# OCCT has no sweep of a solid along a path: BRepOffsetAPI_MakePipe takes no solid ("profile# contains solids"), and given the ball's faces it stops in BRepFill_Sweep (Standard_OutOfRange)# whatever the path. So the ball's sweep is built from what elementary geometry says it is.# A point p of the ball, centre c, moving with the ball has velocity v + ω × (p − c), and# (ω × (p − c))·(p − c) = 0, so it runs along the sphere exactly where v·(p − c) = 0: on the# great circle square to the path. What the ball passes through is therefore the tube those# circles sweep, the circle of radius 3 kept square to the curve, with the ball where it# starts and where it ends; the curve never turns tighter than the ball, so the tube does not# fold.
section = BRepBuilderAPI_MakeEdge(gp_Circ(gp_Ax2(start, gp_Dir(tangent)), BALL_RADIUS)).Edge()
pipe = BRepOffsetAPI_MakePipeShell(BRepBuilderAPI_MakeWire(path).Wire())
# corrected Frenet: the curve has an inflection, where the Frenet frame would flip over
pipe.SetMode(False)
# the tube's surface is a B-spline fitted by the sweep: ask for it within 1e-8, not the 1e-4# it settles for by default
pipe.SetTolerance(1e-8, 1e-8, 1e-6)
pipe.Add(BRepBuilderAPI_MakeWire(section).Wire())
pipe.Build()
ifnot pipe.IsDone():
raiseRefused("BRepOffsetAPI_MakePipeShell could not sweep the circle along the curve")
ifnot pipe.MakeSolid():
raiseRefused("the swept tube did not close into a solid")
# Cut the sweep from the block a piece at a time, the tube and then the ball at each end, as# holes are cut one after another. Each ball touches the tube all round the circle at its end;# cut one after another, the pieces that touch are never fused to each other.
block = BRepPrimAPI_MakeBox(gp_Pnt(*BLOCK_LOW), gp_Pnt(*BLOCK_HIGH)).Shape()
pieces = [("the tube", pipe.Shape())] + [
(f"the ball at the {which}", BRepPrimAPI_MakeSphere(centre, BALL_RADIUS).Shape())
for which, centre in [("start", start), ("end", end)]]
for name, piece in pieces:
cut = BRepAlgoAPI_Cut(block, piece)
ifnot cut.IsDone():
raiseRefused(f"BRepAlgoAPI_Cut declined {name}")
block = cut.Shape()
return block
arris left no solid to show.
Time
174 ms; CPU time 174 ms; peak memory 11.5 MB
Notes
refused kernel bug: a geometry query failed: the section of the NURBS surface and the sphere surface is degenerate: turning points of the section that cannot be told apart
Workaround † no sweep of a solid, no sphere primitive
//! A block, the box from (−6, −6, −8) to (36, 26, 0), with a groove cut into its top face by a//! ball of radius 3 whose centre runs along the cubic Bézier curve in the top face with control//! points (0, 0, 0), (10, 0, 0), (20, 20, 0) and (30, 20, 0).//!//! arris has no sweep of a solid, so the ball's sweep is built from what it is by elementary//! geometry: every point within 3 of the curve. Where the curve turns no tighter than the ball's//! radius (its tightest turn is about 7.5), that is the tube the ball's great disc square to the//! curve fills as it runs, arris's sweep of the disc along the curve, with half a ball on each end//! bulging out of it: the ball's other half lies inside the tube.usecrate::Refusal;
use arris::geom::{FrameLaw, NurbsCurve, Path, PathSegment, Profile, ProfileLoop, ProfileSegment};
use arris::math::{Axis, Control, Frame, Point2, Point3, Vec3};
use arris::ops::{cut, fuse_many, primitive_box, revolve, sweep, OpError};
use arris::topo::{Body, Model};
use std::f64::consts::{FRAC_1_SQRT_2, TAU};
constBLOCK_LOW: [f64; 3] = [-6.0, -6.0, -8.0];
constBLOCK_HIGH: [f64; 3] = [36.0, 26.0, 0.0];
constCONTROL: [[f64; 3]; 4] =
[[0.0, 0.0, 0.0], [10.0, 0.0, 0.0], [20.0, 20.0, 0.0], [30.0, 20.0, 0.0]];
constBALL_RADIUS: f64 = 3.0;
/// A half ball of `radius` on the disc about `centre` square to `outward`, bulging along it: the/// quarter disc in a plane through `outward`, turned about it.fnhalf_ball(m: &mutModel, centre: Point3, outward: Vec3, radius: f64) -> Result<Body, OpError> {
let across = Frame::from_z(centre, outward)?.x().into_inner();
let (r, h) = (radius, radius * FRAC_1_SQRT_2);
let quarter_disc = Profile {
plane: Frame::new(centre, across.cross(&outward), across)?,
outer: ProfileLoop::Path {
start: Point2::origin(),
segments: vec![
ProfileSegment::LineTo(Point2::new(r, 0.0)),
ProfileSegment::ArcTo { to: Point2::new(0.0, r), via: Point2::new(h, h) },
ProfileSegment::LineTo(Point2::origin()),
],
},
holes: vec![],
};
Ok(revolve(m, &quarter_disc, Axis::new(centre, outward)?, TAU, &Control::NONE)?.0)
}
pubfnbuild(m: &mutModel) -> Result<Body, Refusal> {
let [x0, y0, z0] = BLOCK_LOW;
let [x1, y1, z1] = BLOCK_HIGH;
let (block, _) =
primitive_box(m, Point3::new(x0, y0, z0), Point3::new(x1, y1, z1), &Control::NONE)?;
let points: Vec<Point3> = CONTROL.iter().map(|&[x, y, z]| Point3::new(x, y, z)).collect();
// a Bézier curve leaves its first point along its first leg and reaches its last along its// last leglet (start, end) = (points[0], points[3]);
let (leaving, arriving) = (points[1] - points[0], points[3] - points[2]);
let bezier = vec![0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0];
let curve = NurbsCurve::new(3, bezier, points, vec![1.0; 4]).map_err(|e| e.to_string())?;
let path = Path { start, segments: vec![PathSegment::Nurbs(curve)] };
// the ball's great disc square to the curve where it starts; a disc, so how the// rotation-minimising frame turns it about the curve does not matterlet disc = Profile {
plane: Frame::new(start, leaving, Vec3::z()).map_err(OpError::from)?,
outer: ProfileLoop::Circle { center: Point2::origin(), radius: BALL_RADIUS },
holes: vec![],
};
let (tube, _) = sweep(m, &disc, &path, FrameLaw::RotationMinimizing, &Control::NONE)?;
// the halves of the ball outside the tube where it starts and where it endslet back = half_ball(m, start, -leaving, BALL_RADIUS)?;
let front = half_ball(m, end, arriving, BALL_RADIUS)?;
// the half balls' flat faces are the tube's end caps, which the fuse removes. Each ball's// sphere meets the tube's fitted NURBS wall along the end circle, tangent to it all round,// and arris 0.9.1 declines that section ("the section of the NURBS surface and the sphere// surface is degenerate: turning points of the section that cannot be told apart"), whether// the pieces are fused first or cut from the block one by one, half balls or whole.let (swept, _) = fuse_many(m, &[tube, back, front], &Control::NONE)?;
let (grooved, _) = cut(m, block, swept, &Control::NONE)?;
Ok(grooved)
}
Time
374 ms; CPU time 393 ms; peak memory 76.2 MB
Notes
pass Its volume and area are the expected ones, and its mesh is closed.
Its volume and area are its STEP file's, as the harness measures them from the file's exact geometry (harness/mass/); its triangles are Open CASCADE's mesh of the file, for the pictures.
Data
its STEP's
expected
rel. error
volume
10173.82874
10173.82871
3.9e-09
area
4026.639277
4026.639233
1.1e-08
agrees with
no other kernel
centre of gravity
(15, 10, -4.15578) its STEP's solid
inertia
about it, of unit density: Ixx 939383; Iyy 1.58305e+06; Izz 2.41765e+06; Ixy 37340.5; Iyz -0.000336198; Izx 9.69088e-05
STEP
B-rep advanced faces, each on a surface AUTOMOTIVE_DESIGN
//! A block, the box from (−6, −6, −8) to (36, 26, 0), with a groove cut into its top face by a//! ball of radius 3 whose centre follows the cubic Bézier curve in the top face with control//! points (0, 0, 0), (10, 0, 0), (20, 20, 0), (30, 20, 0): everything the ball passes through, cut.//!//! The ball is carried in the frame riding the curve (`shared::swept::bezier_frame`), its centre//! the curve's point (how the ball turns about its centre changes nothing it fills); the motion is//! given by its places (`sweep::RigidMotion::Carried`) for kentron's sweep of a solid//! (`sweep::solid`), cut from the block.usecrate::bench::{frame, p};
usecrate::shared::swept::bezier_frame;
use kentron::math::Direction;
use kentron::primitives::{Cuboid, Sphere};
use kentron::sweep::{self, Carriage, RigidMotion};
use kentron::topology::{Model, Shape};
use std::sync::Arc;
pubfnbuild(m: &mutModel) -> kentron::Result<Shape> {
let block = Cuboid::from_corners(p(-6.0, -6.0, -8.0), p(36.0, 26.0, 0.0)).build(m)?;
let ball = Sphere::new(3.0).with_frame(frame(p(0.0, 0.0, 0.0), Direction::Z)).build(m)?;
let swept = sweep::solid(m, ball, &RigidMotion::Carried(Carriage(Arc::new(bezier_frame))))?;
kentron::boolean::difference(m, block, swept)
}
vcad left no solid to show.
Time
99.8 s; CPU time 100.2 s; peak memory 358.2 MB
Notes
wrong its STEP's faces do not close into a solid
Workaround † no sweep of a solid
Faceted ▦ 64066 faces, where the other kernels' solids have 10 (the median): a mesh stored as B-rep faces.
Data
No measures: it built no solid to measure.
STEP
open advanced faces, each on a surface AUTOMOTIVE_DESIGN
STEP faces
64066: 64066 plane; 63940 flat triangles
STEP edges
97810: 97810 line; 3548 not bounding exactly two sides of faces, so the shell is open
//! A block, the box from (−6, −6, −8) to (36, 26, 0), with a groove cut into its top face by a//! ball of radius 3 whose centre runs along the cubic Bézier curve in the top face with control//! points (0, 0, 0), (10, 0, 0), (20, 20, 0) and (30, 20, 0).//!//! vcad has no sweep of a solid (`Solid::sweep` moves a sketch profile), so the ball's sweep is//! built from what it is by elementary geometry: every point within 3 of the curve. Where the curve//! turns no tighter than the ball's radius (its tightest turn is about 7.5), that is the tube the//! ball's great disc square to the curve fills as it runs, vcad's sweep of the disc along the//! curve, with a ball at each end: half of each lies inside the tube.usecrate::solids::SEGMENTS;
use vcad_kernel::vcad_kernel_math::{Point3, Vec3};
use vcad_kernel::vcad_kernel_sketch::SketchProfile;
use vcad_kernel::vcad_kernel_sweep::SweepOptions;
use vcad_kernel::Solid;
use vcad_kernel_nurbs::BSplineCurve;
constBLOCK_MIN: [f64; 3] = [-6.0, -6.0, -8.0];
constBLOCK_MAX: [f64; 3] = [36.0, 26.0, 0.0];
constBALL_RADIUS: f64 = 3.0;
constCONTROL: [[f64; 3]; 4] =
[[0.0, 0.0, 0.0], [10.0, 0.0, 0.0], [20.0, 20.0, 0.0], [30.0, 20.0, 0.0]];
/// The disc's circle is cut into this many arcs, each into SEGMENTS / ARCS lines.constARCS: u32 = 4;
pubfnbuild() -> Result<Solid, crate::Refusal> {
let [x0, y0, z0] = BLOCK_MIN;
let [x1, y1, z1] = BLOCK_MAX;
let block = Solid::cube(x1 - x0, y1 - y0, z1 - z0).translate(x0, y0, z0);
// vcad-kernel-nurbs's B-spline implements the sweep's `Curve3d`; a cubic Bézier is the clamped// cubic B-spline on its four control points, knots (0, 0, 0, 0, 1, 1, 1, 1)let points = CONTROL.iter().map(|&[x, y, z]| Point3::new(x, y, z)).collect();
let path = BSplineCurve::new(points, vec![0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0], 3);
// the sweep reads the disc in sketch coordinates about the path: a circle about the origin.// vcad's sweep is faceted: the circle cut into SEGMENTS lines, as a primitive's is, and the// path sampled at SEGMENTS places along itlet disc = SketchProfile::circle(Point3::origin(), Vec3::z(), BALL_RADIUS, ARCS);
let options = SweepOptions {
path_segments: SEGMENTS,
arc_segments: SEGMENTS / ARCS,
..SweepOptions::default()
};
let tube = Solid::sweep(disc, &path, options)?;
let ball = |[x, y, z]: [f64; 3]| Solid::sphere(BALL_RADIUS, SEGMENTS).translate(x, y, z);
// the tube and the ball at each end, each cut in turnlet grooved = block.try_difference(&tube)?;
let grooved = grooved.try_difference(&ball(CONTROL[0]))?;
Ok(grooved.try_difference(&ball(CONTROL[3]))?)
}
solidcraft left no solid to show.
Time
968 ms; CPU time 968 ms; peak memory 100.6 MB
Notes
refused the operation failed: SMLib boolean: operation: solidcore: SmApiBoolean: intersect::surface_drop_curve::SurfaceDropCurve::boundary_start_points: the drop found no foot point
//! A block, the box from (−6, −6, −8) to (36, 26, 0), with a groove cut into its top face by a//! ball of radius 3 whose centre runs along the cubic Bézier curve in the top face through the//! control points (0, 0, 0), (10, 0, 0), (20, 20, 0) and (30, 20, 0).//!//! solidcraft-kernel has no sweep of a solid, so the ball's sweep is built by elementary geometry://! every point within 3 of the curve, which (the curve turning no tighter than about 7.5) is the//! ball's great disc square to the curve carried along it, with the ball at each end. Half of each//! end ball lies inside the tube; the other half is the half ball on the tube's end disc, as in//! `ball-swung-groove`. The tube and the half balls are cut from the block in turn.//!//! The tube is the disc swept along the curve itself (`PathSeg::Curve`, the sketch's Bézier).//!//! Where a half ball meets the B-spline tube's groove along its end disc's rim, the kernel's//! boolean works for minutes and then finds no result (joined to the tube first, as in//! `ball-swung-groove`, or whole balls, it fares no better).usesuper::ball_swung_groove::half_ball;
usecrate::solids::*;
use solidcore_record::Seg2;
use solidcraft_kernel::{PathSeg, sweep};
pubfnbuild() -> R<Body> {
let block = block((-6.0, -6.0, -8.0), (36.0, 26.0, 0.0))?;
// the curve, drawn in the top face (the xy plane at z = 0)let curve =
Seg2::Cubic { p0: v2(0.0, 0.0), p1: v2(10.0, 0.0), p2: v2(20.0, 20.0), p3: v2(30.0, 20.0) };
let path = [PathSeg::Curve { plane: Plane::XY, seg: curve }];
// the disc where the curve starts, square to it: the curve leaves (0, 0, 0) along +xlet start = Plane { origin: Vec3::ZERO, x: Vec3::Y, y: Vec3::Z };
letmut grooved = cut(&block, &sweep(&start, &disc((0.0, 0.0), 3.0), &path)?)?;
// the half balls beyond the tube's ends: the curve leaves its first end along +x and reaches// its last along +xfor (end, outward) in [(v3(0.0, 0.0, 0.0), -Vec3::X), (v3(30.0, 20.0, 0.0), Vec3::X)] {
grooved = cut(&grooved, &half_ball(end, outward, 3.0)?)?;
}
Ok(grooved)
}
Time
2.88 s; CPU time 2.88 s; peak memory 47.9 MB
Notes
wrong volume 10178.1342498 against 10173.8287054 (its STEP's); area 4025.76439089 against 4026.63923312 (its STEP's)
Workaround † no sweep of a solid
Faceted ▦ 1484 faces, where the other kernels' solids have 10 (the median): a mesh stored as B-rep faces.
Its volume and area are its STEP file's, as the harness measures them from the file's exact geometry (harness/mass/); its triangles are Open CASCADE's mesh of the file, for the pictures.
Data
its STEP's
expected
rel. error
volume
10178.13425
10173.82871
4.2e-04
area
4025.764391
4026.639233
2.2e-04
agrees with
no other kernel
mesh
2854 triangles, closed
centre of gravity
(15.0001, 10, -4.15479) its STEP's solid
inertia
about it, of unit density: Ixx 939701; Iyy 1.58352e+06; Izz 2.41838e+06; Ixy 37005.9; Iyz -0.99371; Izx -1.94825
//! A block grooved by a ball of radius 3 carried along a cubic Bézier curve in its top face.//! brepkit sweeps faces, not solids, so the ball's sweep is built by elementary geometry: a ball//! moving along a path fills the tube about its centre's path with a ball at each end. The tube//! is brepkit's sweep of the disc of radius 3, square to the curve where it starts, along the//! curve (on the case's control points); the balls are about its two ends, (0, 0, 0) and//! (30, 20, 0). The groove is cut from the box from (−6, −6, −8) to (36, 26, 0).use brepkit_operations::primitives::{make_box, make_sphere};
use brepkit_operations::sweep::sweep;
use brepkit_topology::solid::SolidId;
use brepkit_topology::Topology;
usecrate::solids::sweep::{bezier, disc};
usecrate::solids::{cut, fuse, moved, p, v};
usecrate::Refusal;
pubfnbuild(topo: &mutTopology) -> Result<SolidId, Refusal> {
let block = make_box(topo, 42.0, 32.0, 8.0)?;
let block = moved(topo, block, -6.0, -6.0, -8.0)?;
let path = bezier(&[
p(0.0, 0.0, 0.0),
p(10.0, 0.0, 0.0),
p(20.0, 20.0, 0.0),
p(30.0, 20.0, 0.0),
])?;
// the curve leaves (0, 0, 0) along +xlet section = disc(topo, p(0.0, 0.0, 0.0), v(1.0, 0.0, 0.0), 3.0)?;
let tube = sweep(topo, section, &path)?;
let ball = make_sphere(topo, 3.0, 64)?;
let start = moved(topo, ball, 0.0, 0.0, 0.0)?;
let ball = make_sphere(topo, 3.0, 64)?;
let end = moved(topo, ball, 30.0, 20.0, 0.0)?;
let swept = fuse(topo, tube, start)?;
let swept = fuse(topo, swept, end)?;
Ok(cut(topo, block, swept)?)
}
popkern left no solid to show.
Time
84.7 s; CPU time 84.7 s; peak memory 111.2 MB
Notes
refused FeatureFailed at ball_along_spline_groove.rhai:12:17: feature 'boolean-1' (boolean) failed: result validation failed: cellular result invalid: Half-edge HalfEdgeHandle(7v1) in loop LoopHandle(3v1) ends at VertexHandle(4v1) but its successor HalfEdgeHandle(9v1) starts at VertexHandle(3v1)
// A block with a groove cut by a ball of radius 3 whose centre follows a cubic Bézier curve in// the top face: the tube of radius 3 about the curve (a pipe along the Bézier wire), a ball at// each end, cut from the block.let m = model();
let block = m.box(42.0, 32.0, 8.0, #{ at: [-6.0, -6.0, -8.0], label: "block" });
let path = m.wire_spline([[0.0, 0.0, 0.0], [10.0, 0.0, 0.0], [20.0, 20.0, 0.0], [30.0, 20.0, 0.0]],
#{ control: true, label: "path" });
let groove = m.tool(|m| {
let tube = path.pipe(3.0, #{ label: "tube" });
let a = m.tool(|m| m.sphere(3.0, #{ label: "start" }));
let b = m.tool(|m| m.sphere(3.0, #{ at: [30.0, 20.0, 0.0], label: "end" }));
tube = tube.union(a);
tube.union(b)
});
block = block.subtract(groove, #{ label: "groove" });
m
aetheris left no solid to show.
Time
58 ms; CPU time 58 ms; peak memory 46.8 MB
Notes
refused Aetheris has no sweep of a solid and no general subtraction, and its one feature that cuts such a groove, Groove<Semicircular>, follows only a line or an arc: a CubicBezier2 is a span of a Profile, not a path a groove can follow.
// A ball carried along a Bézier curve in a block's top face, cutting a groove.//// Refused: Aetheris has no sweep of a solid and no general subtraction, and its one feature that// cuts such a groove, Groove<Semicircular>, follows only a line or an arc: a CubicBezier2 is a span// of a Profile, not a path a groove can follow.
Time
58 ms; CPU time 58 ms; peak memory 13 MB
Notes
pass Its volume and area are the expected ones, and its mesh is closed.
Its volume and area are its STEP file's, as the harness measures them from the file's exact geometry (harness/mass/); its triangles are Open CASCADE's mesh of the file, for the pictures.
Data
its STEP's
expected
rel. error
volume
10173.82871
10173.82871
4.3e-11
area
4026.639232
4026.639233
1.6e-10
agrees with
cad-kernel, occt, cadrs, springrep, geomsolver
mesh
21458 triangles, closed, 4 degenerate
centre of gravity
(15, 10, -4.15578) its STEP's solid
inertia
about it, of unit density: Ixx 939383; Iyy 1.58305e+06; Izz 2.41765e+06; Ixy 37340.5; Iyz 6.92571e-11; Izx -2.39305e-11
//! The box from (−6, −6, −8) to (36, 26, 0), less everything a ball of radius 3 passes through as//! its centre follows the cubic Bézier curve in its top face with control points (0, 0, 0),//! (10, 0, 0), (20, 20, 0) and (30, 20, 0).//!//! Through the kernel's whole sweep of a solid (`sweep_solid`): the ball, a solid of revolution//! whose meridian is the half disc of radius 3, carried along the curve by the frame riding it//! (`sweep_solid_along`), and cut from the block (`notch_less` where the kernel builds the cut directly).usecrate::solids::p;
usecrate::solids::swept::{less_all, revolved_tool, Piece};
usecrate::Refusal;
use brep_kernel::{make_box_brep, notch_less, sweep_solid_along, BrepSolid, FrameCurve};
use std::f64::consts::{FRAC_PI_2};
pubfnbuild() -> Result<BrepSolid, Refusal> {
let (x, z) = (p(1.0, 0.0, 0.0), p(0.0, 0.0, 1.0));
let block = make_box_brep(p(-6.0, -6.0, -8.0), 42.0, 32.0, 8.0)?;
let ball = revolved_tool(p(0.0, 0.0, 0.0), z, x, &[
Piece::Arc { centre: [0.0, 0.0], radius: 3.0, start: -FRAC_PI_2, end: FRAC_PI_2 },
Piece::Line { from: [0.0, 3.0], to: [0.0, -3.0] },
]);
let path = FrameCurve {
control: [p(0.0, 0.0, 0.0), p(10.0, 0.0, 0.0), p(20.0, 20.0, 0.0), p(30.0, 20.0, 0.0)],
up: z,
};
let swept = sweep_solid_along(&ball, &path)?;
// The block less the groove built directly where the kernel does (the sweep crosses only the// block's top face plane); else cut by the boolean.ifletSome(body) = notch_less(&block, &swept) {
returnOk(body);
}
less_all(block, vec![swept])
}
Time
2.51 s; CPU time 2.51 s; peak memory 20.2 MB
Notes
wrong volume 10173.1491047 against 10173.8287054 (its STEP's); area 4026.57791994 against 4026.63923312 (its STEP's)
Workaround † no sweep of a solid, no sphere primitive
Its volume and area are its STEP file's, as the harness measures them from the file's exact geometry (harness/mass/); its triangles are Open CASCADE's mesh of the file, for the pictures.
Data
its STEP's
expected
rel. error
volume
10173.1491
10173.82871
6.7e-05
area
4026.57792
4026.639233
1.5e-05
agrees with
no other kernel
mesh
25780 triangles, closed, 4 degenerate
centre of gravity
(15, 10, -4.15598) its STEP's solid
inertia
about it, of unit density: Ixx 939324; Iyy 1.58298e+06; Izz 2.41753e+06; Ixy 37396.4; Iyz -2.08498e-12; Izx 1.28111e-11
//! A block, the box from (−6, −6, −8) to (36, 26, 0), with a groove cut into its top by a ball of//! radius 3 whose centre runs along the cubic Bézier curve in the top face with control points//! (0, 0, 0), (10, 0, 0), (20, 20, 0) and (30, 20, 0).//!//! geop sweeps a profile, not a solid, so what the ball passes through is built as what it is://! the tube of radius 3 about its centre's path — the curve sketched on the xy plane as a spline of//! those control points, the circle on the yz plane, square to it at its start, swept along it —//! and the ball at each end of the path (turned from a half disc). Each is cut from the block.usecrate::shared::paths::{ball, path2d, sweep};
usecrate::shared::{Drawing, extrude, sketch, xy, yz};
usecrate::{Bench, Refusal};
use geop_ops_model::Combine;
pubfnbuild(b: &mutBench) -> Result<(), Refusal> {
letmut base = Drawing::new();
base.rectangle([-6.0, -6.0], [36.0, 26.0]);
sketch(b, "base", xy(), base)?;
extrude(b, "block", "base", -8.0, Combine::NewBody)?;
letmut path = Drawing::new();
let points = [[0.0, 0.0], [10.0, 0.0], [20.0, 20.0], [30.0, 20.0]].map(|p| path.point(p));
path.sketch.add_spline(points.to_vec());
sketch(b, "path", xy(), path)?;
letmut section = Drawing::new();
section.circle([0.0, 0.0], 3.0);
sketch(b, "section", yz(), section)?;
let block = b.solid()?;
sweep(b, "groove", "section", path2d("path"), Combine::cut(block))?;
for (id, centre) in [("first_end", [0.0, 0.0, 0.0]), ("last_end", [30.0, 20.0, 0.0])] {
let block = b.solid()?;
ball(b, id, centre, 3.0, Combine::cut(block))?;
}
Ok(())
}
Time
97 ms; CPU time 191 ms; peak memory 16.8 MB
Notes
pass Its volume and area are the expected ones, and its mesh is closed.
Its volume and area are its STEP file's, as the harness measures them from the file's exact geometry (harness/mass/); its triangles are Open CASCADE's mesh of the file, for the pictures.
//!//! The ball is cadrs's sphere primitive; what it passes through as it is carried along the curve//! (drawn on the Top plane) is cadrs's sweep of a solid along a path (`Kernel::cut_swept`), cut//! from the block.usecrate::bench::{ball, block, p3};
usecrate::shared::swept::{bezier_path, carry, cut_swept};
usecrate::Refusal;
use cadrs_kernel::{BodyId, DefaultKernel};
pubfnbuild(k: &mutDefaultKernel) -> Result<BodyId, Refusal> {
let body = block(k, p3(-6.0, -6.0, -8.0), p3(36.0, 26.0, 0.0))?;
let tool = ball(k, p3(0.0, 0.0, 0.0), 3.0)?;
let path = bezier_path([(0.0, 0.0), (10.0, 0.0), (20.0, 20.0), (30.0, 20.0)]);
cut_swept(k, body, tool, &carry(path))
}
smlib left no solid to show.
Time
It has not run.
Notes
missing no implementation
Data
No measures: it built no solid to measure.
Implementation
No implementation yet.
Time
940 ms; CPU time 939 ms; peak memory 21 MB
Notes
pass Its volume and area are the expected ones, and its mesh is closed.
Workaround † its sweep of a solid declines it
Its volume and area are its STEP file's, as the harness measures them from the file's exact geometry (harness/mass/); its triangles are Open CASCADE's mesh of the file, for the pictures.
Data
its STEP's
expected
rel. error
volume
10173.82871
10173.82871
2.4e-12
area
4026.639233
4026.639233
7.7e-12
agrees with
cad-kernel, occt, next.BREP, cadrs, geomsolver
mesh
12540 triangles, closed, 2 degenerate
centre of gravity
(15, 10, -4.15578) its STEP's solid
inertia
about it, of unit density: Ixx 939383; Iyy 1.58305e+06; Izz 2.41765e+06; Ixy 37340.5; Iyz 7.45925e-12; Izx -2.22655e-06
//! The box (−6, −6, −8)–(36, 26, 0) less everything a ball of radius 3 passes through as its//! center runs along the cubic Bézier curve with control points (0, 0, 0), (10, 0, 0), (20, 20, 0)//! and (30, 20, 0).//!//! springrep's sweep of a solid declines this one (it takes no motion whose velocity changes over a//! sphere face). A ball's sweep is the tube about its center's path, the circle of its radius//! carried square to the curve (springrep's path sweep), with the ball at each end; the curve turns//! no tighter than the ball, so the tube does not fold.use springrep::boolean::difference;
use springrep::geom::{BSpline, Curve};
use springrep::math::Vec2;
use springrep::primitive::sphere;
use springrep::profile::Profile;
use springrep::sweep::along_curve;
use springrep::topo::Brep;
usecrate::shared::swept::{boxed, unite, v3};
usecrate::shared::{at, e, frame};
pubfnbuild() -> Result<Brep, String> {
let block = boxed([-6.0, -6.0, -8.0], [36.0, 26.0, 0.0], "block")?;
let ctrl = vec![v3(0.0, 0.0, 0.0), v3(10.0, 0.0, 0.0), v3(20.0, 20.0, 0.0), v3(30.0, 20.0, 0.0)];
let path = Curve::BSpline(
BSpline::new(3, vec![0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0], ctrl).map_err(e)?,
);
// the ball's great circle square to the curve where it starts, along +xlet start = frame([0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0])?;
let tube = along_curve(&Profile::circle(Vec2::ZERO, 6.0), &start, &path, (0.0, 1.0), 0.0, "groove")
.map_err(e)?;
let first = sphere(&at([0.0, 0.0, 0.0]), 3.0, "ball").map_err(e)?;
let last = sphere(&at([30.0, 20.0, 0.0]), 3.0, "ball").map_err(e)?;
difference(&block, &unite(&[&first, &tube, &last])?).map_err(e)
}
Time
691 ms; CPU time 1.47 s; peak memory 52.1 MB
Notes
pass Its volume and area are the expected ones, and its mesh is closed.
Elegant ✦ the ball as a set carried by a frame riding the spline: the groove is one line of set notation
Its volume and area are its STEP file's, as the harness measures them from the file's exact geometry (harness/mass/); its triangles are Open CASCADE's mesh of the file, for the pictures.
Data
its STEP's
expected
rel. error
volume
10173.8287
10173.82871
4.1e-11
area
4026.639233
4026.639233
1.0e-11
agrees with
cad-kernel, occt, next.BREP, cadrs, springrep
mesh
19783 triangles, closed, 1 degenerate
centre of gravity
(15, 10, -4.15578) its STEP's solid
inertia
about it, of unit density: Ixx 939383; Iyy 1.58305e+06; Izz 2.41765e+06; Ixy 37340.5; Iyz -7.23395e-05; Izx 0.000229991
// A block, the box from (-6, -6, -8) to (36, 26, 0), its top in the top plane; a ball of radius 3// whose centre rides a frame along the cubic Bezier through the control points (0, 0), (10, 0),// (20, 20) and (30, 20) of the top face, and everything it passes through cut from the block.unit mm
use std
use std.sets
use std.solids
use std.solids (cut)
use std.stations
in std.top {
a := point
b := point hint((36, -6))
c := point hint((36, 26))
d := point hint((-6, 26))
outline := horizontal line(a, b) -> vertical line(b, c) ->
horizontal line(c, d) -> vertical line(d, a) -> close
fix((-6, -6)) a
a distance(42) b
b distance(32) c
// the path, a spline over its four control points
k0 := point
k1 := point hint((10, 0))
k2 := point hint((20, 20))
k3 := point hint((30, 20))
fix((0, 0)) k0
fix((10, 0)) k1
fix((20, 20)) k2
fix((30, 20)) k3
route := spline(k0, k1, k2, k3)
}
part := solid(std.solids.Prism(outline, from: -8mm, to: 0mm))
// the ball, about the path's start; the frame that carries it along the whole spline
ball := solid(std.sets.Ball(std.origin, r: 3mm))
along := std.stations.Along(route, up: std.z)
groove := solid({ p | some t in (0rad, 1rad): p in ball at(under: along.f) t })
groove cut part
anvilcad left no solid to show.
Time
1.2 ms; CPU time 990 µs; peak memory 3.5 MB
Notes
refused anvil-brep has no sweep of a solid, and no spline curve to carry anything along: its sweeps follow lines and arcs only
//! A groove carried along a spline by a ball.use anvil_brep::Solid;
pubfnbuild() -> Result<Solid, String> {
Err("anvil-brep has no sweep of a solid, and no spline curve to carry anything along: its sweeps follow lines and arcs only".into())
}