rofCPLsmalldist
by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Geometric Queries
Introduced first in SolidGeometry 5.4, Creation date: 2024-08-15, Last change: 2025-09-15
returns the smallest distance between two contours in CPL
Description
In contrast to CPLdistancewall, this function is a linear search function, that call several times CPLfindsmalldist. It is may be slow, but helpful for automatic design based on existing STLs
See Also: CPLdistancewall
Example Illustration
Syntax
rmin=rofCPLsmalldist(CPL,[])
Input Parameter
Output Parameter
rmin: | | smallest distance between contours in CPL |
Examples
rofCPLsmalldist(PLcircle(4))
Copyright 2024-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This function, rofCPLsmalldist, calculates the smallest distance between contours in a given contour list (CPL). It is a linear search function that repeatedly calls CPLfindsmalldist.
Input Parameters
- CPL: The contour list for which the smallest distance between contours is to be calculated.
Output Results
- rmin: The smallest distance between contours in the CPL.
Algorithm Steps
- Initialize
res to 0.1, which is the resolution for the search.
- Calculate the bounding box of the CPL using
BBofCPL and determine its size with sofBB.
- Set
thr to 0.16 (0.4 squared) as a threshold for area comparison.
- Initialize
ar with the size of the bounding box and d as a quarter of ar.
- Set
AOLD to infinity to store the previous area for comparison.
- Enter a while loop that continues as long as
ar is greater than or equal to res:
- Call
CPLfindsmalldist with CPL and ar to find a cut.
- Calculate the area of the cut using
CPLarea and take the absolute value of the area.
- If the absolute area is less than
thr, adjust ar and d accordingly:
- Increase
ar by half the absolute value of d.
- Halve
d.
- If
d is less than res, break the loop.
- If the new area
AA is greater than or equal to AOLD, adjust ar and d:
- Decrease
ar by d.
- If
ar is less than or equal to res, adjust ar and d further.
- Otherwise, store the current cut as
ccut.
- Update
AOLD with AA.
- Set
rmin to the final value of ar.
- If no output is requested, plot the CPL and the final cut using
SGfigure and CPLplot.
Algorithm explaination created using ChatGPT on 2025-08-19 06:47. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21