diff --git a/PicoGK_Utils.cs b/PicoGK_Utils.cs index 0be3ef5..dadef83 100644 --- a/PicoGK_Utils.cs +++ b/PicoGK_Utils.cs @@ -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) @@ -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); } @@ -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;