A rod, the cylinder of radius 5 about the z axis from z = 0 to z = 20, with a round-bottomed helical groove cut around it by a ball of radius 1. The ball's center follows a helix of radius 5 about the z axis, so it runs on the rod's surface: it starts at (5, 0, −2), turns right-handed (from +x toward +y) and rises 4 each turn, for six whole turns, ending at (5, 0, 22). The ball is clear of the rod at both ends. Cut from the rod everything the ball passes through.
Neighboring turns of the groove do not meet: they are 4 apart and the ball is 2 across.
no closed form (the groove's section is bounded by the tube's cut with the rod): arris and cad-kernel, built independently from this description, agree to 8e-11 (1343.0088855322617 and 1343.0088854208852; the mean); OCCT also agrees, to 2e-9
area
880.5540322
no closed form (the groove's section is bounded by the tube's cut with the rod): arris and cad-kernel, built independently from this description, agree to 6e-11 (880.5540321979142 and 880.554032252641; the mean); OCCT also agrees, to 2e-9
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
972 ms; CPU time 1.20 s; peak memory 42.6 MB
Notes
pass Its volume and area are the expected ones, and its mesh is closed.
Elegant ✦ the groove is one canal of the ball along six turns, cut from the rod; the only one built without a workaround
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 rod, the cylinder of radius 5 about z from z = 0 to 20, with a helical groove cut round it by//! a ball of radius 1 whose centre runs six right-handed turns of the helix of radius 5 rising 4 a//! turn, from (5, 0, −2) to (5, 0, 22).use cad_kernel::boolean::{combined, Op};
use cad_kernel::build::{canal, disc, prism};
use cad_kernel::topo::Brep;
use std::f64::consts::TAU;
constROD_RADIUS: f64 = 5.;
constROD_LENGTH: f64 = 20.;
constRADIUS: f64 = 1.;
constHELIX_RADIUS: f64 = 5.;
constRISE: f64 = 4.;
constTURNS: f64 = 6.;
constSTART_Z: f64 = -2.;
pubfnbuild() -> Result<Brep, String> {
let up = [0., 0., 1.];
let rod = prism(&disc([0., 0., 0.], up, ROD_RADIUS), 0., ROD_LENGTH)?;
// everything the ball passes through as it is screwed along z, by cad-kernel's own sweep of a// ball: the canal of six turns and a rise of 4 each, its disc square to the helix screwed// along it, with the half ball beyond each end disc (both ends clear of the rod)let start = [HELIX_RADIUS, 0., START_Z];
let swept = canal(start, RADIUS, [0., 0., 0.], up, TURNS * TAU, TURNS * RISE, "groove")?;
Ok(combined(&rod, &swept, Op::Cut, 0.)?)
}
Time
1.24 s; CPU time 1.23 s; peak memory 375.8 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.
Data
its STEP's
expected
rel. error
volume
1343.009273
1343.008885
2.9e-07
area
880.5541629
880.5540322
1.5e-07
agrees with
no other kernel
mesh
66729 triangles, closed, 1 degenerate
centre of gravity
(1.36605e-08, -6.92779e-08, 10) its STEP's solid
inertia
about it, of unit density: Ixx 52176.4; Iyy 52176.4; Izz 14818.7; Ixy 0.000111498; Iyz 471.158; Izx -0.00905251
"""A rod threaded by a ball. A rod, the cylinder of radius 5 about the z axis from z = 0 to
z = 20, with a round-bottomed helical groove cut round it by a ball of radius 1. The ball's centre
follows a helix of radius 5 about the z axis, so it runs on the rod's surface: it starts at
(5, 0, −2), turns right-handed (from +x towards +y) and rises 4 each turn, for six whole turns,
ending at (5, 0, 22). The ball is clear of the rod at both ends. Cut from the rod everything the
ball passes through.
Neighbouring turns of the groove do not meet: they are 4 apart and the ball is 2 across."""import math
fromOCP.BRepAdaptorimportBRepAdaptor_CurvefromOCP.BRepAlgoAPIimportBRepAlgoAPI_CutfromOCP.BRepBuilderAPIimportBRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeWirefromOCP.BRepLibimportBRepLibfromOCP.BRepOffsetAPIimportBRepOffsetAPI_MakePipeShellfromOCP.BRepPrimAPIimportBRepPrimAPI_MakeCylinder, BRepPrimAPI_MakeSpherefromOCP.GeomimportGeom_CylindricalSurfacefromOCP.Geom2dimportGeom2d_LinefromOCP.gp import gp, gp_Ax2, gp_Ax3, gp_Circ, gp_Dir, gp_Dir2d, gp_Pnt, gp_Pnt2d, gp_Vec
from bench importRefusedROD_RADIUS = 5ROD_LENGTH = 20HELIX_RADIUS = 5HELIX_START = -2# z of the ball's centre where it starts, at angle 0 (on +x)PITCH = 4# rise per turnTURNS = 6BALL_RADIUS = 1defhelix():
"""The helix as OCCT draws one: a straight line in the (angle, height) parameters of a
cylinder. The cylinder's frame stands at z = −2 with its x direction along +x, so angle 0 is
+x and the angle turns towards +y; each turn, the line climbs 2π in angle and PITCH in
height."""
frame = gp_Ax3(gp_Pnt(0, 0, HELIX_START), gp.DZ_s(), gp.DX_s())
cylinder = Geom_CylindricalSurface(frame, HELIX_RADIUS)
line = Geom2d_Line(gp_Pnt2d(0, 0), gp_Dir2d(2 * math.pi, PITCH))
length = TURNS * math.hypot(2 * math.pi, PITCH) # of the line, in the parameter plane
edge = BRepBuilderAPI_MakeEdge(line, cylinder, 0, length).Edge()
BRepLib.BuildCurves3d_s(edge, 1e-9) # the helix in space, from the line on the cylinderreturn edge
defbuild():
path = helix()
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 1 kept square to the helix, with the ball where it# starts and where it ends. The helix turns no tighter than radius 5 + (4/2π)²/5 ≈ 5.08, far# more than the ball's, and its turns are 4 apart, so the tube neither folds nor meets itself.
section = BRepBuilderAPI_MakeEdge(gp_Circ(gp_Ax2(start, gp_Dir(tangent)), BALL_RADIUS)).Edge()
pipe = BRepOffsetAPI_MakePipeShell(BRepBuilderAPI_MakeWire(path).Wire())
# corrected Frenet, as for any path: the section is a circle, so every frame that keeps it# square to the helix sweeps the same tube
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 helix")
ifnot pipe.MakeSolid():
raiseRefused("the swept tube did not close into a solid")
# Cut the sweep from the rod 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. (Both balls are# clear of the rod, so their cuts leave it as it is.)
rod = BRepPrimAPI_MakeCylinder(gp.XOY_s(), ROD_RADIUS, ROD_LENGTH).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(rod, piece)
ifnot cut.IsDone():
raiseRefused(f"BRepAlgoAPI_Cut declined {name}")
rod = cut.Shape()
return rod
Time
27.1 s; CPU time 27.1 s; peak memory 15 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 rod, the cylinder of radius 5 about the z axis from z = 0 to z = 20, with a helical groove//! cut round it by a ball of radius 1 whose centre runs along the helix of radius 5 about the//! z axis from (5, 0, −2), turning right-handed and rising 4 a turn, for six turns, to (5, 0, 22).//!//! arris has no sweep of a solid, so the ball's sweep is built from what it is by elementary//! geometry: every point within 1 of the helix. That is the tube the ball's great disc square to//! the helix fills as it runs, arris's sweep of the disc along the helix (its turns 4 apart, more//! than the ball's width 2, so it never meets itself), with half a ball on each end. The ball where//! it starts lies wholly below z = −1 and where it ends wholly above z = 21, and so do the tube's//! end discs (their centres 2 beyond the rod's ends, their radius 1), so the half balls are clear//! of the rod and what the sweep takes from it is the tube's alone: the tube is the tool cut here.use arris::geom::{FrameLaw, Path, PathSegment, Profile, ProfileLoop};
use arris::math::{Axis, Control, Frame, Point2, Point3, Vec3};
use arris::ops::{cut, primitive_cylinder, sweep, OpError};
use arris::topo::{Body, Model};
use std::f64::consts::TAU;
constROD_RADIUS: f64 = 5.0;
constROD_LENGTH: f64 = 20.0;
constBALL_RADIUS: f64 = 1.0;
constHELIX_RADIUS: f64 = 5.0;
constPITCH: f64 = 4.0;
constTURNS: f64 = 6.0;
/// The height the ball's centre starts at.constSTART_Z: f64 = -2.0;
pubfnbuild(m: &mutModel) -> Result<Body, OpError> {
let axis = Axis::z_at(Point3::origin());
let (rod, _) = primitive_cylinder(m, axis, ROD_RADIUS, ROD_LENGTH, &Control::NONE)?;
let start = Point3::new(HELIX_RADIUS, 0.0, START_Z);
// the helix as one arc of six turns: written turn by turn, six one-turn arcs, the tube sweeps// as well, but arris 0.9.1 then declines the cut ("the face arrangement is not a subdivision:// a section edge of f5 ends at a node nothing else reaches")let helix = Path {
start,
segments: vec![PathSegment::Helix { axis, pitch: PITCH, angle: TURNS * TAU }],
};
// the ball's great disc square to the helix where it starts: its tangent there is// (0, 2πr, pitch)let tangent = Vec3::new(0.0, TAU * HELIX_RADIUS, PITCH);
let disc = Profile {
plane: Frame::new(start, tangent, Vec3::x())?,
outer: ProfileLoop::Circle { center: Point2::origin(), radius: BALL_RADIUS },
holes: vec![],
};
// a spring's frame: the binormal held to the axis, so the disc turns with the helixlet law = FrameLaw::FixedBinormal(Vec3::z_axis());
let (tube, _) = sweep(m, &disc, &helix, law, &Control::NONE)?;
let (grooved, _) = cut(m, rod, tube, &Control::NONE)?;
Ok(grooved)
}
Time
8.67 s; CPU time 11.6 s; peak memory 4211.8 MB
Notes
pass Its volume and area are the expected ones, and its mesh is closed.
//! A rod, the cylinder of radius 5 about the z axis from z = 0 to z = 20, with a helical groove//! cut round it by a ball of radius 1 whose centre follows the helix of radius 5 about the z axis//! from (5, 0, −2), right-handed, rising 4 a turn, for six turns to (5, 0, 22): everything the//! ball passes through, cut.//!//! The ball carried along the screw about the z axis keeps its centre on that helix; its sweep is//! kentron's sweep of a solid (`sweep::solid`, one screw), cut from the rod.usecrate::bench::{frame, p};
use kentron::math::{Axis, Direction};
use kentron::primitives::{Cylinder, Sphere};
use kentron::sweep::{self, RigidMotion};
use kentron::topology::{Model, Shape};
use std::f64::consts::TAU;
pubfnbuild(m: &mutModel) -> kentron::Result<Shape> {
let rod = Cylinder::new(5.0, 20.0).build(m)?;
let ball = Sphere::new(1.0).with_frame(frame(p(5.0, 0.0, -2.0), Direction::Z)).build(m)?;
let screw = RigidMotion::Screw { axis: Axis::Z, lead: 4.0, from: 0.0, to: 6.0 * TAU };
let swept = sweep::solid(m, ball, &screw)?;
kentron::boolean::difference(m, rod, swept)
}
//! A rod, the cylinder of radius 5 about the z axis from z = 0 to z = 20, with a helical groove//! cut round it by a ball of radius 1 whose centre runs along the helix of radius 5 about the//! z axis from (5, 0, −2), turning right-handed and rising 4 a turn, for six turns, to (5, 0, 22).//!//! 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 1 of the helix. That is the//! tube the ball's great disc square to the helix fills as it runs, vcad's sweep of the disc along//! its helix (its turns 4 apart, more than the ball's width 2, so it never meets itself), with a//! ball at each end. The ball where it starts lies wholly below z = −1 and where it ends wholly//! above z = 21, and so do the tube's end discs, so the end balls are clear of the rod and what the//! sweep takes from it is the tube's alone: the tube is the tool cut here.usecrate::solids::SEGMENTS;
use vcad_kernel::vcad_kernel_math::{Point3, Vec3};
use vcad_kernel::vcad_kernel_sketch::SketchProfile;
use vcad_kernel::vcad_kernel_sweep::{Helix, SweepOptions};
use vcad_kernel::Solid;
constROD_RADIUS: f64 = 5.0;
constROD_LENGTH: f64 = 20.0;
constBALL_RADIUS: f64 = 1.0;
constHELIX_RADIUS: f64 = 5.0;
constSTART_Z: f64 = -2.0;
constPITCH: f64 = 4.0;
constTURNS: f64 = 6.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 rod = Solid::cylinder(ROD_RADIUS, ROD_LENGTH, SEGMENTS);
// vcad's helix is about the z axis through its centre, starts on +x and turns from +x towards// +y as it riseslet path = Helix::new(HELIX_RADIUS, PITCH, PITCH * TURNS, TURNS)
.with_center(Point3::new(0.0, 0.0, START_Z));
// 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// helix sampled at SEGMENTS places a turnlet disc = SketchProfile::circle(Point3::origin(), Vec3::z(), BALL_RADIUS, ARCS);
let options = SweepOptions {
path_segments: SEGMENTS * TURNSas u32,
arc_segments: SEGMENTS / ARCS,
..SweepOptions::default()
};
let tube = Solid::sweep(disc, &path, options)?;
Ok(rod.try_difference(&tube)?)
}
Time
1.21 s; CPU time 1.21 s; peak memory 59.1 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.
Data
its STEP's
expected
rel. error
volume
1343.008573
1343.008885
2.3e-07
area
880.553481
880.5540322
6.3e-07
agrees with
no other kernel
mesh
148550 triangles, closed
centre of gravity
(4.07568e-08, -1.25639e-08, 10) its STEP's solid
inertia
about it, of unit density: Ixx 52176.3; Iyy 52176.3; Izz 14818.7; Ixy 1.03473e-05; Iyz 471.165; Izx 0.000542937
//! A rod, the cylinder of radius 5 about the z axis from z = 0 to z = 20, grooved by a ball of//! radius 1 whose centre runs along the helix of radius 5 about the z axis from (5, 0, −2),//! right-handed and rising 4 a turn, for six turns.//!//! solidcraft-kernel has no sweep of a solid, so the ball's sweep is built by elementary geometry://! every point within 1 of the helix, which is the ball's great disc square to the helix carried//! along it (the helix turns no tighter than radius 5.08, so the tube does not fold), with the//! ball at each end. The screw that carries the helix along itself keeps the disc square to it,//! so the tube is the kernel's helical sweep of the disc (`sweep_helix`), whose turns, 4 apart,//! clear each other. The end balls, and the tube's end discs, lie wholly below z = −1 and above//! z = 21, clear of the rod, so the tube is what the sweep takes from the rod.usecrate::solids::*;
pubfnbuild() -> R<Body> {
let rod = zcyl(0.0, 0.0, 5.0, 0.0, 20.0)?;
let start = v3(5.0, 0.0, -2.0);
// the helix's direction where it starts: round the axis 5 a radian, up 4 a turnlet along = v3(0.0, 5.0, 4.0 / std::f64::consts::TAU);
let along = along * (1.0 / along.len());
// the disc's plane: square to the helix, its sketch x out from the axislet plane = Plane { origin: start, x: Vec3::X, y: along.cross(Vec3::X) };
// six turns about the z axis through the origin, rising 4 a turnlet section = disc((0.0, 0.0), 1.0);
let tube = solidcraft_kernel::sweep_helix(&plane, §ion, Vec3::ZERO, Vec3::Z, 4.0, 6.0)?;
cut(&rod, &tube)
}
Time
4.44 s; CPU time 4.44 s; peak memory 42.9 MB
Notes
wrong volume 1342.87540874 against 1343.00888548 (its STEP's); area 883.497207071 against 880.554032225 (its STEP's)
Workaround † no sweep of a solid
Faceted ▦ 2662 faces, where the other kernels' solids have 10.5 (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
1342.875409
1343.008885
9.9e-05
area
883.4972071
880.5540322
3.3e-03
agrees with
no other kernel
mesh
6688 triangles, closed
centre of gravity
(1.43714e-05, 1.91069e-06, 10) its STEP's solid
inertia
about it, of unit density: Ixx 52162.8; Iyy 52163; Izz 14805.8; Ixy -0.16659; Iyz 464.654; Izx 0.11367
//! A rod threaded by a ball of radius 1 whose centre follows a helix of radius 5 about the z axis,//! rising 4 a turn for six turns from (5, 0, −2). 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 balls at the ends, about (5, 0, −2) and (5, 0, 22),//! are clear of the rod, so only the tube cuts it: brepkit's helical sweep of a disc of radius 1,//! turned a quarter turn back about the z axis to start on +x (brepkit's helix starts on +y), cut//! from the cylinder of radius 5 from z = 0 to z = 20.use std::f64::consts::FRAC_PI_2;
use brepkit_math::mat::Mat4;
use brepkit_operations::helix::helical_sweep;
use brepkit_operations::primitives::make_cylinder;
use brepkit_topology::solid::SolidId;
use brepkit_topology::Topology;
usecrate::solids::sweep::disc;
usecrate::solids::{cut, p, placed, v};
usecrate::Refusal;
/// NURBS arcs per turn of the helix: how closely brepkit's helix follows the true one.constSEGMENTS_PER_TURN: usize = 64;
pubfnbuild(topo: &mutTopology) -> Result<SolidId, Refusal> {
let rod = make_cylinder(topo, 5.0, 20.0)?;
let section = disc(topo, p(0.0, 0.0, 0.0), v(0.0, 0.0, 1.0), 1.0)?;
let tube = helical_sweep(
topo,
section,
p(0.0, 0.0, -2.0),
v(0.0, 0.0, 1.0),
5.0,
4.0,
6.0,
SEGMENTS_PER_TURN,
)?;
let tube = placed(topo, tube, Mat4::rotation_z(-FRAC_PI_2))?;
Ok(cut(topo, rod, tube)?)
}
popkern left no solid to show.
Time
913 ms; CPU time 916 ms; peak memory 28.9 MB
Notes
refused FeatureFailed at ball_thread_groove.rhai:20:17: feature 'boolean-1' (boolean) failed: result validation failed: cellular result invalid: Half-edge HalfEdgeHandle(17v1) in loop LoopHandle(3v1) ends at VertexHandle(1v1) but its successor HalfEdgeHandle(4v1) starts at VertexHandle(7v1)
fnball(m, r) {
m.sphere(r)
}
// A rod of radius 5 on the z axis from z = 0 to 20, grooved by a ball of radius 1 whose centre// follows the helix of radius 5 that rises 4 per turn, six right-handed turns from (5, 0, -2) to// (5, 0, 22).//// popkern has no sweep of a solid; a ball's sweep is the tube about its centre's path with a ball// at each end: a circle of radius 1 swept along the helix, square to it, and the two balls.// popkern's helix about +z starts on +y, its frame's first direction, and winds towards -x:// started at -90° it starts on +x.let m = model();
let rod = m.profile(xy()).circle(5.0).sketch("rod").extrude(blind(20.0));
let swept = m.tool(|m| {
let tube = m.profile(xy()).circle(1.0).sketch("ball_section")
.helical_sweep(axis_at([0.0, 0.0, -2.0], [0.0, 0.0, 1.0]), 5.0, 4.0, 6.0,
#{ start_angle: -90.0, label: "track" });
let start = m.tool(|m| ball(m, 1.0).translate(5.0, 0.0, -2.0));
tube = tube.union(start);
let finish = m.tool(|m| ball(m, 1.0).translate(5.0, 0.0, 22.0));
tube.union(finish)
});
rod = rod.subtract(swept, #{ label: "groove" });
m
aetheris left no solid to show.
Time
58 ms; CPU time 57 ms; peak memory 47.1 MB
Notes
refused Aetheris has no sweep of a solid and no general subtraction. Its Helix makes a wire, not a cut, its Groove features cut a rod only along full circles (helical channels reject), and its Thread cuts only the metric 60° profile.
// A ball carried along a helix round a rod, cutting a round-bottomed thread.//// Refused: Aetheris has no sweep of a solid and no general subtraction. Its Helix makes a wire,// not a cut, its Groove features cut a rod only along full circles (helical channels reject), and// its Thread cuts only the metric 60° profile.
Time
112 ms; CPU time 111 ms; peak memory 20.9 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.
usecrate::solids::p;
usecrate::solids::swept::{less_all, revolved_tool, turn_about_z, Piece};
usecrate::Refusal;
use brep_kernel::{make_cylinder_brep, sweep_clip_less, sweep_solid, BrepSolid, OutlinePiece, ScrewStep, SolidMotion, SweepClip, SweptTool};
use std::f64::consts::{FRAC_PI_2, TAU};
pubfnbuild() -> Result<BrepSolid, Refusal> {
let (x, z) = (p(1.0, 0.0, 0.0), p(0.0, 0.0, 1.0));
// The ball's two ends keep clear of the rod (below z = 0 and above 20), so the kernel builds// the rod less the groove directly, without a boolean, where it does.let tool = SweptTool::Revolved {
axis_origin: p(5.0, 0.0, -2.0),
axis_direction: z,
radial: x,
meridian: vec![
OutlinePiece::Arc { centre: [0.0, 0.0], radius: 1.0, start: -FRAC_PI_2, end: FRAC_PI_2 },
OutlinePiece::Line { from: [0.0, 1.0], to: [0.0, -1.0] },
],
};
let screw = SolidMotion {
steps: vec![ScrewStep { axis_origin: p(0.0, 0.0, 0.0), axis_direction: z, turn: 1.0, advance: 4.0 / TAU }],
from: 0.0,
to: 6.0 * TAU,
};
let rod_clip = SweepClip { axis_origin: p(0.0, 0.0, 0.0), axis_direction: z, reference: x, radius: [0.0, 5.0], axial: [0.0, 20.0], angle: None };
ifletOk(Some(mut bodies)) = sweep_clip_less(&tool, &screw, &rod_clip) {
if bodies.len() == 1 {
returnOk(bodies.remove(0));
}
}
let rod = make_cylinder_brep(p(0.0, 0.0, 0.0), z, 5.0, 20.0)?;
let ball = revolved_tool(p(5.0, 0.0, -2.0), z, x, &[
Piece::Arc { centre: [0.0, 0.0], radius: 1.0, start: -FRAC_PI_2, end: FRAC_PI_2 },
Piece::Line { from: [0.0, 1.0], to: [0.0, -1.0] },
]);
less_all(rod, vec![sweep_solid(&ball, &turn_about_z(0.0, 6.0 * TAU, 4.0 / TAU))?])
}
Time
8.45 s; CPU time 8.45 s; peak memory 27.8 MB
Notes
wrong area 880.833747244 against 880.554032225 (its STEP's)
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.
Data
its STEP's
expected
rel. error
volume
1343.008885
1343.008885
6.6e-12
area
880.8337472
880.5540322
3.2e-04
agrees with
no other kernel
mesh
146248 triangles, closed
centre of gravity
(1.64328e-14, 6.74934e-12, 10) its STEP's solid
inertia
about it, of unit density: Ixx 52176.4; Iyy 52176.4; Izz 14818.7; Ixy 7.35774e-10; Iyz 473.24; Izx 1.16011e-07
//! A rod, the cylinder of radius 5 about the z axis from z = 0 to 20, with a helical groove cut//! round it by a ball of radius 1 whose centre runs along the helix of radius 5 about the z axis//! from (5, 0, −2), right-handed, rising 4 a turn, six turns to (5, 0, 22).//!//! geop sweeps a profile, not a solid, so what the ball passes through is built as what it is://! the tube of radius 1 about its centre's path — the helix drawn in a 3-D sketch, the circle on//! the plane square to it at its start, through (5, 0, −2) square to its tangent (0, 2π·5, 4),//! swept along it — and a ball at each end; the balls at the ends, below z = −1 and above z = 21,//! are clear of the rod, so only the tube is cut from it.usecrate::shared::paths::{at, path3d, plane_square_to, sketch3d, sweep};
usecrate::shared::{Drawing, extrude, n, sketch, xy};
usecrate::{Bench, Refusal};
use geop_ops_model::Combine;
use geop_ops_model::sketch3d::Sketch3d;
use std::f64::consts::PI;
pubfnbuild(b: &mutBench) -> Result<(), Refusal> {
letmut end = Drawing::new();
end.circle([0.0, 0.0], 5.0);
sketch(b, "end", xy(), end)?;
extrude(b, "rod", "end", 20.0, Combine::NewBody)?;
letmut route = Sketch3d::new();
let start = route.add_point(at([5.0, 0.0, -2.0]));
let base = route.add_point(at([0.0, 0.0, -2.0]));
let top = route.add_point(at([0.0, 0.0, 22.0]));
route.add_helix(start, base, top, n(6.0), false)?;
sketch3d(b, "helix", route)?;
let across = plane_square_to(b, "across", [5.0, 0.0, -2.0], [0.0, 2.0 * PI * 5.0, 4.0])?;
letmut section = Drawing::new();
section.circle([0.0, 0.0], 1.0);
sketch(b, "section", across, section)?;
let rod = b.solid()?;
sweep(b, "groove", "section", path3d("helix"), Combine::cut(rod))
}
Time
225 ms; CPU time 624 ms; peak memory 17.4 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.
//! A rod, the cylinder of radius 5 about the z axis from z = 0 to z = 20, with a helical groove//! cut by a ball of radius 1 whose center follows the helix of radius 5 about the z axis from//! (5, 0, −2), right-handed, rising 4 a turn, six whole turns to (5, 0, 22).//!//! The ball is cadrs's sphere primitive, centred where the helix starts; its screw is cadrs's//! sweep of a solid along a screw (`Kernel::cut_swept`: turned about the z axis from 0° to 2160°//! while rising 4 a turn), cut from the rod.usecrate::bench::{ball, p3};
usecrate::shared::swept::{cut_swept, rod, screw, z_axis};
usecrate::Refusal;
use cadrs_kernel::{BodyId, DefaultKernel};
pubfnbuild(k: &mutDefaultKernel) -> Result<BodyId, Refusal> {
let body = rod(k)?;
let tool = ball(k, p3(5.0, 0.0, -2.0), 1.0)?;
cut_swept(k, body, tool, &screw(z_axis(), 4.0, 0.0, 2160.0))
}
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
196 ms; CPU time 196 ms; peak memory 18.3 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 rod of radius 5 about the z axis from z = 0 to 20 less everything a ball of radius 1//! passes through as its center runs six turns of the helix of radius 5 rising 4 a turn, from//! (5, 0, −2).use springrep::boolean::difference;
use springrep::primitive::sphere;
use springrep::sweep::solid;
use springrep::topo::Brep;
usecrate::shared::e;
usecrate::shared::swept::{deg, rod, screwing};
pubfnbuild() -> Result<Brep, String> {
let ball = sphere(&crate::shared::at([5.0, 0.0, -2.0]), 1.0, "ball").map_err(e)?;
let swept = solid(&ball, &screwing(4.0, 0.0, deg(2160.0)), "screw").map_err(e)?;
difference(&rod()?, &swept).map_err(e)
}
Time
15.4 s; CPU time 15.8 s; peak memory 146.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.
// A rod, the cylinder of radius 5 about the z axis from z = 0 to z = 20; a ball of radius 1 about// (5, 0, -2), carried by a screw about the z axis that turns right-handed (from +x toward +y) and// rises 4 a turn, for six whole turns, and everything it passes through cut from the rod.unit mm
use std
use std.sets
use std.solids
use std.solids (cut)
use std.motion (screws)
in std.top {
centreline := point
fix((0, 0)) centreline
skin := circle(center: centreline) hint(r: 5)
radius(5) skin
}
part := solid(std.solids.Prism(face(skin), from: 0mm, to: 20mm))
o := point
fix((5, 0, -2)) o
ball := solid(std.sets.Ball(o, r: 1mm))
climb := frame
climb screws(4mm) std.z
groove := solid({ p | some t in (0deg, 6 * 360deg): p in ball at(under: climb) 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 helical curve: a body screwed along an axis sweeps envelopes of its surfaces under the screw, which it cannot make from its profile sweeps
//! A rod threaded by a ball.use anvil_brep::Solid;
pubfnbuild() -> Result<Solid, String> {
Err("anvil-brep has no sweep of a solid and no helical curve: a body screwed along an axis sweeps envelopes of its surfaces under the screw, which it cannot make from its profile sweeps".into())
}