### Visualization Workflow Example Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/visualizations.md An end-to-end example demonstrating the creation of complex geometry (cylinder), its conversion to different representations (Voxels, Mesh), and visualization using various preview functions. It also shows how to analyze and visualize overhang angles. ```csharp using Leap71; using PicoGK; // Create complex geometry LocalFrame oFrame = new LocalFrame(new Vector3(0, 0, 0)); List aSpine = new List { new Vector3(0, 0, 0), new Vector3(20, 10, 20), new Vector3(40, 5, 40), new Vector3(60, -10, 60) }; Frames oFrames = new Frames(aSpine, oFrame); BaseCylinder oCyl = new BaseCylinder(oFrames, fRadius: 15); Voxels voxCyl = oCyl.voxConstruct(); // Construct mesh for analysis Mesh mshCyl = Sh.mshConstruct(oCyl); // Visualize multiple representations Sh.PreviewVoxels(voxCyl, Cp.clrBlue); Sh.PreviewMesh(mshCyl, Cp.clrGreen); Sh.PreviewFrames(oFrames, nFramesToShow: 10, fSize: 5); // Analyze and visualize overhang RainboxSpectrum oSpectrum = new RainboxSpectrum(0, 90); MeshPainter.PreviewOverhangAngle( mshCyl, oSpectrum, bShowOnlyDownFacing: true ); // Show bounding box BBox3 oBBox = voxCyl.oCalculateBoundingBox(); Sh.PreviewBBox(oBBox, Cp.clrRed); ``` -------------------------------- ### Coordinate Conversion Example Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/utilities.md Demonstrates converting between Cartesian, cylindrical, and spherical coordinate systems using utility functions. This example shows how to extract cylindrical and spherical components from a Cartesian point and convert back. ```csharp Vector3 vecCarthesian = new Vector3(10, 10, 20); // Convert to cylindrical float fR = VecOperations.fGetRadius(vecCarthesian); // ~14.14 float fPhi = VecOperations.fGetPhi(vecCarthesian); // ~π/4 float fZ = vecCarthesian.Z; // 20 // Convert back Vector3 vecBack = VecOperations.vecGetCylPoint(fR, fPhi, fZ); // Convert to spherical float fSphRadius = vecCarthesian.Length(); // ~24.49 float fTheta = VecOperations.fGetTheta(vecCarthesian); Vector3 vecSph = VecOperations.vecGetSphPoint(fSphRadius, fPhi, fTheta); ``` -------------------------------- ### Animation Preview Example Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/visualizations.md Demonstrates how to create rotation frames and preview them using Sh.PreviewFrame. This is useful for visualizing animation paths. ```csharp LocalFrame oFrame = new LocalFrame(new Vector3(0, 0, 0)); BaseSphere oSphere = new BaseSphere(oFrame, fRadius: 20); Voxels voxSphere = oSphere.voxConstruct(); // Create 36 rotation frames (10° increments) List aRotationFrames = RotationAnimator.aGetRotationFrames( oFrame, nFrames: 36, vecRotationAxis: new Vector3(0, 0, 1) // Rotate around Z ); // Preview at each frame (would be animated in viewer) foreach (LocalFrame oRotFrame in aRotationFrames) { Sh.PreviewFrame(oRotFrame, fSize: 10); } ``` -------------------------------- ### Example: Mesh and Surface Points Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/functions.md Demonstrates constructing a mesh from a sphere and retrieving a surface point using parametric ratios. ```csharp LocalFrame oFrame = new LocalFrame(new Vector3(0, 0, 0)); BaseSphere oSphere = new BaseSphere(oFrame, fRadius: 20); // Construct mesh Mesh mshSphere = Sh.mshConstruct(oSphere); // Get surface point (spherical coordinates) // Ratio 1 = phi (azimuthal), Ratio 2 = theta (polar), Ratio 3 = unused Vector3 vecSurfacePoint = Sh.vecGetSurfacePoint( oSphere, fRatio1: 0.5f, // 180° around fRatio2: 0.25f, // 45° up from bottom fRatio3: 0 // unused ); ``` -------------------------------- ### Example: Complete Visualization Workflow Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/functions.md Demonstrates a complete workflow for creating shapes, constructing voxels, performing boolean operations, and previewing the results and frames. ```csharp using Leap71; using PicoGK; // Create shapes LocalFrame oFrame = new LocalFrame(new Vector3(0, 0, 0)); BaseBox oBox = new BaseBox(oFrame, fLength: 50, fWidth: 30, fDepth: 20); BaseSphere oSphere = new BaseSphere(new LocalFrame(new Vector3(60, 0, 0)), fRadius: 20); // Construct voxels Voxels voxBox = oBox.voxConstruct(); Voxels voxSphere = oSphere.voxConstruct(); // Combine using Boolean operations Voxels voxCombined = voxBox.voxBoolAdd(voxSphere); // Preview results Sh.PreviewVoxels(voxBox, ColorFloat.clrCyan); Sh.PreviewVoxels(voxSphere, ColorFloat.clrMagenta); Sh.PreviewVoxels(voxCombined, ColorFloat.clrGreen); // Preview frames Frames oSpine = new Frames(fLength: 100, oFrame); Sh.PreviewFrames(oSpine, nFramesToShow: 10, fSize: 5); ``` -------------------------------- ### LineModulation Examples Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/modulations.md Demonstrates creating LineModulations with constant values, custom functions (linear taper, sinusoidal wave), and discrete point distributions. ```csharp // Constant width LineModulation oConstWidth = new LineModulation(fConstValue: 20f); // Linear taper from 30 to 10 LineModulation oLinearTaper = new LineModulation( fRatio => 30f - 20f * fRatio ); // Sinusoidal variation LineModulation oSinWave = new LineModulation( fRatio => 15f + 10f * MathF.Sin(fRatio * MathF.PI) ); // Discrete points: width increases from 10 at start to 30 in middle, back to 10 at end List aWidthProfile = new List { new Vector3(0.0f, 0, 10f), // position 0, value 10 new Vector3(0.5f, 0, 30f), // position 0.5, value 30 new Vector3(1.0f, 0, 10f) // position 1, value 10 }; LineModulation oProfileWidth = new LineModulation( aWidthProfile, eValues: ECoord.Z, eAxis: ECoord.X ); float fWidthAt50Percent = oSinWave.fGetModulation(0.5f); ``` -------------------------------- ### Curve Smoothing and Analysis Example Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/utilities.md Demonstrates spline manipulation, including reparametrization, fitting a smooth NURB spline, and computing tangent directions. This example shows how to process a raw set of points into a smoothed curve with associated tangents. ```csharp List aRawPoints = new List { new Vector3(0, 0, 0), new Vector3(10, 8, 10), new Vector3(20, 5, 20), new Vector3(30, 12, 30), new Vector3(40, 10, 40) }; // Reparametrize to 100 evenly-spaced points List aReparametrized = SplineOperations.aGetReparametrizedSpline(aRawPoints, 100); // Fit smooth NURB spline List aSmooth = SplineOperations.aGetNURBSpline(aRawPoints, 150); // Get tangent directions List aTangents = SplineOperations.aGetTangentDirections(aSmooth); ``` -------------------------------- ### Instantiate a new Lattice Source: https://github.com/leap71/leap71_shapekernel/blob/main/Documentation/README-ReadingDetails.md Creates a new, empty Lattice object. This is the starting point for building lattice-based geometries. ```csharp Lattice oLattice = new Lattice(); ``` -------------------------------- ### Initialize ShapeKernel and Run Task Source: https://github.com/leap71/leap71_shapekernel/blob/main/Documentation/README-GettingStarted.md This code snippet initializes the PicoGK library with a specified voxel size, calls a ShapeKernel example task, and sets an output folder. It includes error handling for robust execution. ```csharp using Leap71.ShapeKernel; using PicoGK; string strOutputFolder = "/Users/josefinelissner/Documents/Code++/Examples"; try { PicoGK.Library.Go( 0.1f, Leap71.ShapeKernelExamples.BaseLensShowCase.Task, strOutputFolder ); } catch (Exception e) { Console.WriteLine("Failed to run Task."); Console.WriteLine(e.ToString()); } ``` -------------------------------- ### SurfaceModulation Examples Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/modulations.md Demonstrates creating SurfaceModulations for constant radius, variable radius based on functions, extending line modulations, and spiral textures. Also shows usage within a BaseCylinder. ```csharp // Constant radius SurfaceModulation oConstRadius = new SurfaceModulation(fConstValue: 15f); // 2D function: radius varies with both angular and axial position SurfaceModulation oVarRadius = new SurfaceModulation( (fPhi, fLengthRatio) => 15f + 5f * MathF.Sin(3f * fPhi * 2f * MathF.PI) + 3f * fLengthRatio ); // Extend a 1D modulation to 2D LineModulation oLengthProfile = new LineModulation( fRatio => 10f + 10f * (fRatio - 0.5f) * (fRatio - 0.5f) * 4f ); SurfaceModulation oTapering = new SurfaceModulation(oLengthProfile, ELine.SECOND); // Spiral texture SurfaceModulation oSpiral = new SurfaceModulation( (fPhi, fLengthRatio) => 15f + 2f * MathF.Sin(fPhi * 8f * MathF.PI - fLengthRatio * 4f * MathF.PI) ); // Usage in BaseCylinder BaseCylinder oCyl = new BaseCylinder(new LocalFrame(), fLength: 50, fRadius: 15); oCyl.SetRadius(oVarRadius); Voxels voxCyl = oCyl.voxConstruct(); ``` -------------------------------- ### Custom Implicit Sphere Implementation Source: https://github.com/leap71/leap71_shapekernel/blob/main/Documentation/README-ReadingDetails.md Create a custom SDF by implementing the IImplicit interface. This example shows a custom ImplicitSphere class. ```csharp public class ImplicitSphere : IImplicit { protected Vector3 m_vecCentre; protected float m_fRadius; public ImplicitSphere(Vector3 vecCentre, float fRadius) { m_vecCentre = vecCentre; m_fRadius = fRadius; } public float fSignedDistance(in Vector3 vecPt) { return (vecPt - m_vecCentre).Length() - m_fRadius; } } ``` -------------------------------- ### Instantiate an Identity Local Frame Source: https://github.com/leap71/leap71_shapekernel/blob/main/Documentation/README-ReadingDetails.md Create a Local Frame that is aligned with the absolute coordinate system. No setup is required. ```csharp LocalFrame oFrame = new LocalFrame(); ``` -------------------------------- ### Integration Example: Swept Geometry along Spline Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/splines.md Demonstrates creating swept geometry (cylinder and box) that follows a complex B-spline path. This involves defining the path, generating spline samples, creating frames along the path, and then constructing the geometry. ```csharp // Define a complex curved path using a spline List aPathPoints = new List { new Vector3(0, 0, 0), new Vector3(10, 20, 10), new Vector3(30, 15, 25), new Vector3(50, 5, 30), new Vector3(60, -10, 25) }; // Create B-spline curve ControlPointSpline oPathSpline = new ControlPointSpline(aPathPoints, nDegree: 3); List aSplineSamples = oPathSpline.aGetPoints(200); // Create frames along the spline LocalFrame oStartFrame = new LocalFrame(aPathPoints[0]); Frames oSpineFrames = new Frames(aSplineSamples, oStartFrame); // Create geometry that follows the spline BaseCylinder oSpineFollower = new BaseCylinder(oSpineFrames, fRadius: 8); BaseBox oSpineBox = new BaseBox(oSpineFrames, fWidth: 12, fDepth: 12); Voxels voxCyl = oSpineFollower.voxConstruct(); Voxels voxBox = oSpineBox.voxConstruct(); ``` -------------------------------- ### Default LocalFrame Constructor Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/frames-and-coordinates.md Creates a LocalFrame at the origin (0,0,0) with default axes aligned to the world X, Y, and Z directions. No setup is required. ```csharp public LocalFrame() ``` -------------------------------- ### Global Linear Transformation Example Source: https://github.com/leap71/leap71_shapekernel/blob/main/Documentation/README-ReadingDetails.md Applies a global linear translation to a shape's points. Use this for simple positional adjustments. ```csharp public Vector3 vecTransformPoint(Vector3 vecPt) { Vector3 vecNewPt = vecPt + new Vector3(30, 0, 50); return vecNewPt; } ``` -------------------------------- ### Create Frames along a Straight Line with Constant Target Source: https://github.com/leap71/leap71_shapekernel/blob/main/Documentation/README-ReadingDetails.md Instantiate Frames along a straight line defined by a starting Local Frame and a number of segments. Useful for constant-orientation pipes. ```csharp LocalFrame oConstFrame = new LocalFrame( new Vector3(10, 30, 30), new Vector3(0, 1, 0), new Vector3(0, 0, 1)); Frames aFrames = new Frames(100, oConstFrame); ``` -------------------------------- ### Create and Sample a Control Point Surface Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/splines.md Defines a surface from a grid of control points and samples it to get a grid of points. Used for creating complex surfaces with specified degrees and end conditions. ```csharp List> aControlGrid = new List>(); for (int i = 0; i < 4; i++) { List aRow = new List(); for (int j = 0; j < 3; j++) { float fX = (float)i * 10; float fY = (float)j * 15; float fZ = (i - 1.5f) * (j - 1f) * 5f; // Saddle shape aRow.Add(new Vector3(fX, fY, fZ)); } aControlGrid.Add(aRow); } ControlPointSurface oSurface = new ControlPointSurface( aControlGrid, nDegreeU: 3, nDegreeV: 3, eEndsU: EEnds.OPEN, eEndsV: EEnds.OPEN ); // Sample the surface List> aSurfacePoints = oSurface.aGetGrid(nUSamples: 100, nVSamples: 80); // Get a single point Vector3 vecMidpoint = oSurface.vecGetPointAt(0.5f, 0.5f); ``` -------------------------------- ### Local Non-Linear Transformation Example Source: https://github.com/leap71/leap71_shapekernel/blob/main/Documentation/README-ReadingDetails.md Applies a local non-linear transformation to a shape's points, creating complex deformations. This example reshapes points into a helical or spiral form. ```csharp public Vector3 vecTransformPoint(Vector3 vecPt) { float fRadius = 50 + 20 * vecPt.Z; float fBogen = 2f * MathF.PI * fRadius; float fAlpha = 50f / fBogen * (vecPt.X); float fNewZ = 1.0f * vecPt.Y; float fNewX = fRadius * MathF.Cos(fAlpha); float fNewY = fRadius * MathF.Sin(fAlpha); Vector3 vecNewPt = new Vector3(fNewX, fNewY, fNewZ); return vecNewPt; } ``` -------------------------------- ### BaseCone Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/base-shapes.md Represents a cone with a linearly varying radius from start to end, implemented as a specialized BaseCylinder. ```APIDOC ## BaseCone **Namespace:** `Leap71.ShapeKernel` **Location:** `ShapeKernel/BaseShapes/BaseCone.cs` Cone with linearly varying radius from start to end. Implemented as a specialized BaseCylinder. ### Constructor ```csharp public BaseCone(LocalFrame oFrame, float fLength, float fStartRadius, float fEndRadius) ``` | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | oFrame | `LocalFrame` | — | Position and orientation | | fLength | `float` | — | Cone length in mm | | fStartRadius | `float` | — | Radius at start in mm | | fEndRadius | `float` | — | Radius at end in mm | ### Methods #### oGetBaseCylinder ```csharp public BaseCylinder oGetBaseCylinder() ``` Returns the underlying BaseCylinder for advanced manipulation. ``` -------------------------------- ### Get Lattice Beam Count Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/functions.md Returns the total number of beams present in a lattice structure. ```csharp public static uint uGetBeamCount(Lattice lat) ``` -------------------------------- ### Get LocalFrame Position Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/frames-and-coordinates.md Retrieves the position of the LocalFrame in world coordinates. This method is straightforward and requires no parameters. ```csharp public Vector3 vecGetPosition() ``` -------------------------------- ### Basic Shape Previews Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/api-reference.md Shows how to construct and preview voxels, meshes, and lattices with different colors. Supports previewing multiple objects of the same type. ```csharp Voxels vox = shape.voxConstruct(); Mesh msh = Sh.mshConstruct(meshShape); Lattice lat = Sh.latConstruct(latticeShape); // Single object Sh.PreviewVoxels(vox, Cp.clrBlue); Sh.PreviewMesh(msh, Cp.clrGreen); Sh.PreviewLattice(lat, Cp.clrRed); // Multiple objects Sh.PreviewVoxels(new List { vox1, vox2, vox3 }, clr); ``` -------------------------------- ### LineModulation: Linear Interpolation Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/modulations.md Creates a LineModulation using linear interpolation between a start and end value based on the ratio. ```csharp LineModulation oLinear = new LineModulation( fRatio => fStart + fRatio * (fEnd - fStart) ); ``` -------------------------------- ### Create Basic Shapes Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/index.md Demonstrates how to construct a box, sphere, and cylinder using the BaseShape classes. Ensure LocalFrame and Vector3 are imported. ```csharp LocalFrame oFrame = new LocalFrame(new Vector3(0, 0, 0)); BaseBox oBox = new BaseBox(oFrame, fLength: 50, fWidth: 30, fDepth: 20); Voxels voxBox = oBox.voxConstruct(); BaseSphere oSphere = new BaseSphere(oFrame, fRadius: 25); Voxels voxSphere = oSphere.voxConstruct(); BaseCylinder oCyl = new BaseCylinder(oFrame, fLength: 50, fRadius: 15); Voxels voxCyl = oCyl.voxConstruct(); ``` -------------------------------- ### Get Spine Position Along Length Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/frames-and-coordinates.md Retrieves the 3D position on the spine at a specified ratio of its total length. ```csharp public Vector3 vecGetSpineAlongLength(float fLengthRatio) ``` -------------------------------- ### Using Palette Colors and Random Colors for Visualization Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/visualizations.md Demonstrates how to create shapes (Box, Cylinder, Sphere) and visualize them using predefined palette colors and reproducible random colors. Ensure Leap71 and PicoGK namespaces are included. ```csharp using Leap71; using PicoGK; // Create several shapes with palette colors LocalFrame oFrame1 = new LocalFrame(new Vector3(0, 0, 0)); LocalFrame oFrame2 = new LocalFrame(new Vector3(50, 0, 0)); LocalFrame oFrame3 = new LocalFrame(new Vector3(100, 0, 0)); BaseBox oBox = new BaseBox(oFrame1, fLength: 30, fWidth: 20, fDepth: 20); BaseCylinder oCyl = new BaseCylinder(oFrame2, fLength: 40, fRadius: 12); BaseSphere oSphere = new BaseSphere(oFrame3, fRadius: 15); // Preview with different colors Sh.PreviewVoxels(oBox.voxConstruct(), Cp.clrBlue); Sh.PreviewVoxels(oCyl.voxConstruct(), Cp.clrGreen); Sh.PreviewVoxels(oSphere.voxConstruct(), Cp.clrRed); // Use reproducible random colors for a series of shapes for (int i = 0; i < 5; i++) { LocalFrame oFrame = new LocalFrame(new Vector3(i * 20, 0, 0)); BaseSphere oS = new BaseSphere(oFrame, fRadius: 10); Sh.PreviewVoxels(oS.voxConstruct(), Cp.clrRandom(i)); } ``` -------------------------------- ### Access Shapekernel API via Sh Class Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/index.md Demonstrates the primary entry point for the Shapekernel API, showing how to construct voxels, lattices, and meshes, and how to preview them using the static `Sh` class. ```csharp Voxels vox = Sh.voxConstruct(shape); Lattice lat = Sh.latConstruct(latticeShape); Mesh msh = Sh.mshConstruct(meshShape); Sh.PreviewVoxels(vox, Cp.clrBlue); ``` -------------------------------- ### Lattice Structure Generation and Analysis Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/api-reference.md Demonstrates creating a solid box, converting it into a lattice structure with a specified beam diameter, and checking its density. ```csharp // Create solid shape BaseBox oBox = new BaseBox(oFrame, 100, 50, 50); Voxels voxSolid = oBox.voxConstruct(); // Convert to lattice LatticeManifold oLat = new LatticeManifold(voxSolid, fBeamDiameter: 3); Lattice lat = Sh.latConstruct(oLat); // Check properties float fMass = Sh.fGetLatticeDensity(lat); Sh.PreviewLattice(lat, Cp.clrGreen); ``` -------------------------------- ### List Operations: Oversample, Subsample, and Find Extrema Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/api-reference.md Demonstrates how to interpolate between points (oversample), select every nth point (subsample), and find the indices of maximum and minimum values in a list. ```csharp // Oversample (interpolate between points) List aUpsampled = ListOperations.aOverSampleList(aValues, iSamplesPerStep: 4); // Subsample (keep every nth point) List aDownsampled = ListOperations.aSubsampleList(aValues, iSampleSize: 5); // Find extrema int iMaxIdx = ListOperations.iGetIndexOfMaxValue(aValues); int iMinIdx = ListOperations.iGetIndexOfMinValue(aValues); ``` -------------------------------- ### Get Column from Grid Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/utilities.md Extracts a specific column (constant Y index) from a 2D grid represented as a list of lists of Vector3. ```csharp public static List aGetListInY(List> aGrid, uint uIndexY) ``` -------------------------------- ### Get Lattice Density Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/functions.md Retrieves the volume fraction (density) of a given lattice structure. The value ranges from 0 to 1. ```csharp public static float fGetLatticeDensity(Lattice lat) ``` -------------------------------- ### Creating and Transforming Local Frames Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/frames-and-coordinates.md Demonstrates the creation of LocalFrame objects at the origin or specific positions, defining orientation using vectors, and applying transformations like translation and rotation. Also shows how to invert and mirror frames. ```csharp // Create a frame at origin LocalFrame oFrameA = new LocalFrame(); // Create a frame at specific position LocalFrame oFrameB = new LocalFrame(new Vector3(10, 20, 30)); // Create a frame pointing in Z direction with custom X Vector3 vecZ = new Vector3(0, 0, 1).Normalize(); Vector3 vecX = new Vector3(1, 0, 0).Normalize(); LocalFrame oFrameC = new LocalFrame(new Vector3(0, 0, 0), vecZ, vecX); // Transform the frame LocalFrame oFrameD = oFrameC.oTranslate(new Vector3(5, 5, 5)); LocalFrame oFrameE = oFrameC.oRotate(MathF.PI / 4, new Vector3(0, 0, 1)); // Mirror the frame LocalFrame oFrameF = LocalFrame.oGetInvertFrame(oFrameC, bMirrorZ: true, bMirrorX: false); ``` -------------------------------- ### Mesh Construction and Point Retrieval Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/api-reference.md Demonstrates constructing a mesh from a shape, retrieving surface points from a parametric shape, and obtaining points from a spine shape. Also shows converting a mesh to voxels. ```csharp // Construct mesh from shape Mesh msh = Sh.mshConstruct(shapeWithIMeshBaseShape); // Get surface point from parametric shape Vector3 vec = Sh.vecGetSurfacePoint(surfaceShape, fRatio1: 0.5f, fRatio2: 0.25f, fRatio3: 0); // Get spine point from spine shape Vector3 vec = Sh.vecGetSpinePoint(spineShape, fRatio: 0.5f); // Voxels from mesh Voxels vox = new Voxels(msh); ``` -------------------------------- ### Frame and Path Previews Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/api-reference.md Demonstrates previewing single frames, multiple frames along a spine, polylines, and bounding boxes. Useful for visualizing geometric structures and paths. ```csharp // Single frame (shows coordinate axes) Sh.PreviewFrame(oFrame, fSize: 10); // Frames along spine Sh.PreviewFrames(oSpineFrames, nFramesToShow: 15, fSize: 5); // Polyline path List aPath = new List { ... }; Sh.PreviewPolyline(aPath, Cp.clrYellow); // Bounding box BBox3 oBBox = vox.oCalculateBoundingBox(); Sh.PreviewBBox(oBBox, Cp.clrRed); ``` -------------------------------- ### Get Local Frame Source: https://github.com/leap71/leap71_shapekernel/blob/main/Documentation/README-ReadingDetails.md Retrieves a local frame based on a length ratio. This is useful for shapes that exclusively use local frames. ```cpp LocalFrame oFrame = aFrames.oGetLocalFrame(fLengthRatio); ``` -------------------------------- ### Create Simple Primitive Shapes Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/api-reference.md Instantiate basic 3D shapes like boxes, spheres, cylinders, cones, tori, pipes, and lenses at the origin. Requires a LocalFrame for positioning. ```csharp // Box at origin, 50×30×20 BaseBox oBox = new BaseBox(new LocalFrame(), 50, 30, 20); // Sphere at origin, radius 25 BaseSphere oSph = new BaseSphere(new LocalFrame(), 25); // Cylinder at origin, length 50, radius 15 BaseCylinder oCyl = new BaseCylinder(new LocalFrame(), 50, 15); // Cone from 20mm to 5mm BaseCone oCone = new BaseCone(oFrame, fLength: 50, fStartRadius: 20, fEndRadius: 5); // Torus (donut), inner 10mm, outer 25mm BaseRing oTorus = new BaseRing(oFrame, fInnerRadius: 10, fOuterRadius: 25); // Hollow pipe, inner 10mm, outer 20mm BasePipe oPipe = new BasePipe(oFrame, fLength: 50, fInnerRadius: 10, fOuterRadius: 20); // Optical lens, 30mm radius, 5mm front sag, 3mm back sag BaseLens oLens = new BaseLens(oFrame, fRadius: 30, fFrontSag: 5, fBackSag: 3); ``` -------------------------------- ### Get Row from Grid Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/utilities.md Extracts a specific row (constant X index) from a 2D grid represented as a list of lists of Vector3. ```csharp public static List aGetListInX(List> aGrid, uint uIndexX) ``` -------------------------------- ### Get Index of Minimum Value Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/utilities.md Returns the index of the minimum value within a list of floats. Useful for identifying trough values. ```csharp public static int iGetIndexOfMinValue(List aList) ``` -------------------------------- ### LocalFrame Initialization and Access Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/api-reference.md Shows how to create and access LocalFrame objects, which define local coordinate systems. Frames can be initialized with default settings, specific positions, or defined axes. ```csharp // Default: origin, axes aligned with world LocalFrame oDefault = new LocalFrame(); // At specific position LocalFrame oAtPos = new LocalFrame(new Vector3(10, 20, 30)); // Specified Z direction (X computed orthogonal) Vector3 vecZ = new Vector3(0, 0, 1); LocalFrame oWithZ = new LocalFrame(new Vector3(0, 0, 0), vecZ); // Fully specified (X, Y computed from Z × X) Vector3 vecZ = new Vector3(0, 1, 0); Vector3 vecX = new Vector3(1, 0, 0); LocalFrame oFull = new LocalFrame(new Vector3(0, 0, 0), vecZ, vecX); // From another frame at new position LocalFrame oCopy = new LocalFrame(oDefault, new Vector3(50, 0, 0)); // Access Vector3 pos = oFrame.vecGetPosition(); Vector3 x = oFrame.vecGetLocalX(); Vector3 y = oFrame.vecGetLocalY(); Vector3 z = oFrame.vecGetLocalZ(); ``` -------------------------------- ### Get Index of Maximum Value Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/utilities.md Returns the index of the maximum value within a list of floats. Useful for identifying peak values. ```csharp public static int iGetIndexOfMaxValue(List aList) ``` -------------------------------- ### Visualize Geometry with Colors and Overhang Analysis Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/index.md Provides various preview functions for different geometry types, including colored voxels, meshes, frames, and bounding boxes. Also includes mesh overhang analysis for 3D printing suitability. ```csharp // Preview with colors Sh.PreviewVoxels(voxBox, Cp.clrBlue); Sh.PreviewVoxels(voxSphere, Cp.clrRed); Sh.PreviewMesh(mshCyl, Cp.clrGreen); // Analyze mesh overhang for 3D printing RainboxSpectrum oSpectrum = new RainboxSpectrum(0, 90); MeshPainter.PreviewOverhangAngle(mesh, oSpectrum, bShowOnlyDownFacing: true); // Display frames along spine Sh.PreviewFrames(oFrames, nFramesToShow: 15, fSize: 5); // Show bounding box BBox3 oBBox = vox.oCalculateBoundingBox(); Sh.PreviewBBox(oBBox, Cp.clrYellow); ``` -------------------------------- ### Get Spine Point Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/functions.md Retrieves a point on a shape's spine or centerline at a specified ratio. The ratio ranges from 0 to 1. ```csharp public static Vector3 vecGetSpinePoint(ISpineBaseShape oShape, float fRatio) ``` -------------------------------- ### Instantiate a Local Frame with Custom Z and X Directions Source: https://github.com/leap71/leap71_shapekernel/blob/main/Documentation/README-ReadingDetails.md Create a Local Frame with a specified position, custom local z-axis, and custom local x-axis. The z and x vectors must be orthogonal and non-zero. ```csharp LocalFrame oFrame = new LocalFrame(new Vector3(2, 5, -3), new Vector3(0, 0, 1), new Vector3(1, 0, 0)); LocalFrame oFrame = new LocalFrame(new Vector3(2, 5, -3), new Vector3(0, 0, 1), new Vector3(0, 1, 0)); LocalFrame oFrame = new LocalFrame(new Vector3(2, 5, -3), new Vector3(0, 0, 1), new Vector3(3, -5, 0)); ``` -------------------------------- ### Get Surface Point Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/functions.md Retrieves a point on a shape's surface using parametric ratios. Ratios range from 0 to 1. ```csharp public static Vector3 vecGetSurfacePoint(ISurfaceBaseShape oShape, float fRatio1, float fRatio2, float fRatio3) ``` -------------------------------- ### Create a Lattice Structure from a Box Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/README.md Demonstrates generating a lattice structure from an existing voxelized box. This is useful for creating complex internal structures. Requires BaseBox, LatticeManifold, and Sh.latConstruct. ```csharp BaseBox oBox = new BaseBox(oFrame, 100, 50, 50); Voxels voxBox = oBox.voxConstruct(); LatticeManifold oLat = new LatticeManifold(voxBox, fBeamDiameter: 3); Lattice lat = Sh.latConstruct(oLat); Sh.PreviewLattice(lat, Cp.clrGreen); ``` -------------------------------- ### Create a Box with Linear Width Modulation Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/README.md Demonstrates creating a box and applying a linear modulation to its width. This is useful for creating tapered shapes. Requires BaseBox and LineModulation classes. ```csharp LocalFrame oFrame = new LocalFrame(new Vector3(0, 0, 0)); BaseBox oBox = new BaseBox(oFrame, fLength: 50, fWidth: 30, fDepth: 20); // Taper the width linearly LineModulation oTaper = new LineModulation(fRatio => 30 - 20 * fRatio); oBox.SetWidth(oTaper); Voxels voxBox = oBox.voxConstruct(); Sh.PreviewVoxels(voxBox, Cp.clrBlue); ``` -------------------------------- ### ISpline Interface: Get Points Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/frames-and-coordinates.md Implements the ISpline interface by returning a list of points sampled along the spine with a specified number of samples. ```csharp public List aGetPoints(uint nSamples) ``` -------------------------------- ### Implicit Conversions to/from Frame3d Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/frames-and-coordinates.md Demonstrates the implicit conversion capabilities between Leap71.ShapeKernel's LocalFrame and PicoGK's Frame3d. This allows seamless interoperability between the two types. ```csharp Frame3d frm = new Frame3d(pos, lz, lx); LocalFrame oFrame = frm; // implicit conversion from Frame3d Frame3d frm2 = oFrame; // implicit conversion to Frame3d ``` -------------------------------- ### vecGetSpinePoint Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/functions.md Gets a point on a shape's spine/centerline at the specified ratio (0 to 1). Ideal for operations along the central axis of a shape. ```APIDOC ## vecGetSpinePoint ### Description Gets a point on a shape's spine/centerline at the specified ratio (0 to 1). ### Method ```csharp public static Vector3 vecGetSpinePoint(ISpineBaseShape oShape, float fRatio) ``` ### Parameters - **oShape** (`ISpineBaseShape`): The shape to get the point from. - **fRatio** (`float`): The ratio along the spine/centerline (0 to 1). ``` -------------------------------- ### Basic Previews Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/api-reference.md Functions for previewing Voxels, Meshes, and Lattices with specified colors. Supports single objects and lists of objects. ```APIDOC ## Basic Previews ### Description Functions for previewing Voxels, Meshes, and Lattices with specified colors. Supports single objects and lists of objects. ### Methods - `shape.voxConstruct()`: Constructs Voxels from a shape. - `Sh.mshConstruct(meshShape)`: Constructs a Mesh from a mesh shape. - `Sh.latConstruct(latticeShape)`: Constructs a Lattice from a lattice shape. - `Sh.PreviewVoxels(voxels, color)`: Previews Voxels with a specified color. - `Sh.PreviewMesh(mesh, color)`: Previews a Mesh with a specified color. - `Sh.PreviewLattice(lattice, color)`: Previews a Lattice with a specified color. - `Sh.PreviewVoxels(voxelsList, color)`: Previews a list of Voxels with a specified color. ``` -------------------------------- ### Create and Modify BaseBox Shapes Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/base-shapes.md Demonstrates creating a simple box and a tapered box along a spline. Includes applying width modulation to the tapered box. ```csharp // Create a simple box LocalFrame oFrame = new LocalFrame(new Vector3(0, 0, 0)); BaseBox oBox = new BaseBox(oFrame, fLength: 50, fWidth: 30, fDepth: 20); Voxels voxBox = oBox.voxConstruct(); // Create a tapered box along a spline List aSpinePoints = new List { new Vector3(0, 0, 0), new Vector3(10, 5, 10), new Vector3(20, 10, 20) }; LocalFrame oStartFrame = new LocalFrame(new Vector3(0, 0, 0)); Frames oSpine = new Frames(aSpinePoints, oStartFrame); BaseBox oTapered = new BaseBox(oSpine, fWidth: 30, fDepth: 20); // Apply width modulation LineModulation oWidthMod = new LineModulation(fRatio => 20 + 10 * MathF.Sin(fRatio * MathF.PI)); oTapered.SetWidth(oWidthMod); Voxels voxTapered = oTapered.voxConstruct(); ``` -------------------------------- ### Get Local Axis Directions Along Length Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/frames-and-coordinates.md Returns the normalized local axis directions (X, Y, or Z) at a specified position along the spine. ```csharp public Vector3 vecGetLocalXAlongLength(float fLengthRatio) public Vector3 vecGetLocalYAlongLength(float fLengthRatio) public Vector3 vecGetLocalZAlongLength(float fLengthRatio) ``` -------------------------------- ### Create and Sample an Open Quadratic B-Spline Curve Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/splines.md Demonstrates creating an open quadratic B-spline curve with specified control points and sampling points along it. This spline passes through its first and last control points. ```csharp // Quadratic open spline (passes through first and last points) List aControlPoints = new List { new Vector3(0, 0, 0), new Vector3(10, 10, 10), new Vector3(20, 5, 20), new Vector3(30, 10, 30) }; ControlPointSpline oSpline = new ControlPointSpline( aControlPoints, nDegree: 2, eEnds: EEnds.OPEN ); // Sample 100 points along the curve List aSamples = oSpline.aGetPoints(100); // Use the spline as a spine for swept shapes Frames oFrames = new Frames(aSamples, new LocalFrame()); // Create a swept cylinder along the spline BaseCylinder oCyl = new BaseCylinder(oFrames, fRadius: 10); Voxels voxCyl = oCyl.voxConstruct(); ``` -------------------------------- ### vecGetSurfacePoint Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/functions.md Gets a point on a shape's surface using parametric ratios (0 to 1). This function is useful for sampling points on complex surfaces. ```APIDOC ## vecGetSurfacePoint ### Description Gets a point on a shape's surface using parametric ratios (0 to 1). ### Method ```csharp public static Vector3 vecGetSurfacePoint(ISurfaceBaseShape oShape, float fRatio1, float fRatio2, float fRatio3) ``` ### Parameters - **oShape** (`ISurfaceBaseShape`): The shape to get the point from. - **fRatio1** (`float`): The first parametric ratio (0 to 1). - **fRatio2** (`float`): The second parametric ratio (0 to 1). - **fRatio3** (`float`): The third parametric ratio (0 to 1, often unused for surfaces). ``` -------------------------------- ### Get Rotation Frames with Scale Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/visualizations.md Creates a sequence of frames that rotate and scale simultaneously. Ideal for creating zoom or dynamic scaling effects during animation. ```csharp public static List aGetRotationFramesWithScale(LocalFrame oBaseFrame, uint nFrames, Vector3 vecRotationAxis, float fScaleStart, float fScaleEnd) ``` -------------------------------- ### Implicit Conversions Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/frames-and-coordinates.md Demonstrates implicit conversion between LocalFrame and PicoGK's Frame3d. ```APIDOC ## Implicit Conversions LocalFrame implicitly converts to/from PicoGK's `Frame3d`: ```csharp Frame3d frm = new Frame3d(pos, lz, lx); LocalFrame oFrame = frm; // implicit conversion from Frame3d Frame3d frm2 = oFrame; // implicit conversion to Frame3d ``` ``` -------------------------------- ### LocalFrame Constructor with Position, Z, and X Axes Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/frames-and-coordinates.md Creates a fully defined LocalFrame using a specified position, Z-axis, and X-axis. Both axes are auto-normalized, and the Y-axis is computed. Throws an exception if either input axis vector has zero length. ```csharp public LocalFrame(Vector3 vecPos, Vector3 vecLocalZ, Vector3 vecLocalX) ``` -------------------------------- ### Static Factory: Get Rotated LocalFrame Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/frames-and-coordinates.md Provides a static method to create a rotated version of a given LocalFrame. This is the static equivalent of the `oRotate` instance method. ```csharp public static LocalFrame oGetRotatedFrame(LocalFrame oFrame, float dPhi, Vector3 vecAxis) ``` -------------------------------- ### Static Factory: Get Translated LocalFrame Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/frames-and-coordinates.md Provides a static method to create a translated version of a given LocalFrame. This is the static equivalent of the `oTranslate` instance method. ```csharp public static LocalFrame oGetTranslatedFrame(LocalFrame oFrame, Vector3 vecTranslate) ``` -------------------------------- ### Mesh Analysis: Volume, Surface Area, and Normals Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/api-reference.md Shows how to calculate the volume and surface area of a mesh, retrieve vertex normals, and filter meshes by bounding box intersection. ```csharp float fVolume = MeshUtility.fGetMeshVolume(msh); float fSurfaceArea = MeshUtility.fGetMeshSurfaceArea(msh); Vector3 vecNormal = MeshUtility.bGetVertexNormal(msh, nVertex, out vecNormal) ? vecNormal : vecDefault; // Filter mesh by bounding box Mesh mshSubset = MeshUtility.mshGetSubMeshByBoxIntersection(msh, oBBox); ``` -------------------------------- ### Get LocalFrame Axes Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/frames-and-coordinates.md Retrieves the normalized direction vectors for the local X, Y, and Z axes of the frame. These methods return Vector3 objects representing the orientation. ```csharp public Vector3 vecGetLocalX() ``` ```csharp public Vector3 vecGetLocalY() ``` ```csharp public Vector3 vecGetLocalZ() ``` -------------------------------- ### Create and Modify BaseSphere Shapes Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/base-shapes.md Shows how to create a simple sphere and a 'bumpy' sphere with radius modulation. Allows setting custom azimuthal and polar steps for mesh resolution. ```csharp // Create a simple sphere LocalFrame oFrame = new LocalFrame(new Vector3(0, 0, 0)); BaseSphere oSphere = new BaseSphere(oFrame, fRadius: 25); Voxels voxSphere = oSphere.voxConstruct(); // Create a bumpy sphere SurfaceModulation oRadiusMod = new SurfaceModulation( (fPhi, fTheta) => 15 + 5 * MathF.Sin(4 * fPhi) * MathF.Cos(3 * fTheta) ); oSphere.SetRadius(oRadiusMod); oSphere.SetAzimuthalSteps(720); oSphere.SetPolarSteps(360); ``` -------------------------------- ### fFindRoot Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/utilities.md Finds the root of a function within a specified range using the bisection method. It requires a start and end point for the range, the function to evaluate, and an optional tolerance. ```APIDOC ## fFindRoot ### Description Finds the root of a function within a specified range using bisection. ### Method Signature `public static float fFindRoot(float fStart, float fEnd, System.Func oFunc, float fTolerance = 0.00001f)` ### Parameters - **fStart** (float) - The starting point of the range. - **fEnd** (float) - The ending point of the range. - **oFunc** (System.Func) - The function for which to find the root. - **fTolerance** (float, optional) - The desired accuracy for the root. Defaults to 0.00001f. ``` -------------------------------- ### Get Radial Distance from Z Axis Source: https://github.com/leap71/leap71_shapekernel/blob/main/_autodocs/utilities.md Returns the radial distance (XY plane distance) from the Z axis for a given 3D point. This is equivalent to the `vec.R()` method. ```csharp public static float fGetRadius(Vector3 vecPt) ``` -------------------------------- ### Instantiate Base Shape with Frames Source: https://github.com/leap71/leap71_shapekernel/blob/main/Documentation/README-ReadingDetails.md Create a Base Cylinder using a collection of frames and a radius. ```csharp BaseCylinder oShape = new BaseCylinder(aFrames, 30); ```