Skip to content

Commit

Permalink
Fixed Cylinder, Cone, Geosphere subdivision
Browse files Browse the repository at this point in the history
The automatic calculation of subdivisions of the Cone, Cylinder, Geosphere Mesh helper functions produced different subdivision counts, dependent on voxel size. This reduced the quality massively at smaller voxel sizes. (These functions were not used outside tests, as the Shape Kernel has more advanced functionality).
  • Loading branch information
LinKayser committed Feb 7, 2024
1 parent a453807 commit ffd5b41
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions PicoGK_Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,17 @@ static public Mesh mshCreateCylinder( Vector3? vecScale = null,

if (iSides <= 0)
{
float fVoxA = fA / Library.fVoxelSizeMM;
float fVoxB = fB / Library.fVoxelSizeMM;
//Ramanujan's ellipse perimeter
//P ≈ π [ 3 (a + b) - √[(3a + b) (a + 3b) ]]
//P ≈ π(a + b) [ 1 + (3h) / (10 + √(4 - 3h) ) ], where h = (a - b)2/(a + b)2

float fP = MathF.PI * (3.0f * (fA + fB) - MathF.Sqrt((3.0f * fA + fB) * (fA + 3.0f * fB)));
iSides = 2 * (int)MathF.Ceiling(fP);
float fP = float.Pi * (3.0f * (fVoxA + fVoxB)
- float.Sqrt((3.0f * fVoxA + fVoxB)
* (fVoxA + 3.0f * fVoxB)));

iSides = 2 * (int) float.Ceiling(fP);
}

if (iSides < 3)
Expand Down Expand Up @@ -388,7 +393,13 @@ static public Mesh mshCreateCone(Vector3? vecScale = null,

if (iSides <= 0)
{
float fP = MathF.PI * (3.0f * (fA + fB) - MathF.Sqrt((3.0f * fA + fB) * (fA + 3.0f * fB)));
float fVoxA = fA / Library.fVoxelSizeMM;
float fVoxB = fB / Library.fVoxelSizeMM;

float fP = float.Pi * (3.0f * (fVoxA + fVoxB)
- float.Sqrt((3.0f * fVoxA + fVoxB)
* (fVoxA + 3.0f * fVoxB)));

iSides = 2 * (int)MathF.Ceiling(fP);
}

Expand Down Expand Up @@ -499,7 +510,10 @@ static public Mesh mshCreateGeoSphere(Vector3? vecScale = null,

if (iSubdivisions <= 0)
{
int iTargetTriangles = (int)MathF.Ceiling(fApproxEllipsoidSurfaceArea(vecRadii));
int iTargetTriangles = (int) MathF.Ceiling(
fApproxEllipsoidSurfaceArea(vecRadii)
/ Library.fVoxelSizeMM
/ Library.fVoxelSizeMM);

iSubdivisions = 1;
int iTriangles = 80;
Expand Down

0 comments on commit ffd5b41

Please sign in to comment.