<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Excessively elaborate eggs etc]]></title><description><![CDATA[<p dir="auto">Hi all - first post.</p>
<p dir="auto">My name is Nick Taylor - and I am an the ultimate newbie when it comes to JScad, although I did start programming in 1979, have the degree, and a couple of decades of commercial experience... which is a fancy way of saying I am a recovering web-dev.</p>
<p dir="auto">I now do manufacturing and design etc... and am building an electric guitar which is based on a flattened egg shape.</p>
<p dir="auto">So.... this is what i have so far, which generates the egg.... it is basically a parabola sitting upside down on top of a circle, joined then rotated into a 3D shape.</p>
<p dir="auto">I am experiencing all sorts of weirdness to do with unexpected boolean behaviour (eg: intersect does what a union should do), and I look at this code and despair.... there has GOT to be a more concise way of doing this.</p>
<p dir="auto">If anyone has any help or advice, I would be most eternally, tearfully grateful.</p>
<p dir="auto">If there is a better way of presenting this code (eg: giving it a main function), let me know.</p>
<pre><code>
//
// egg_shape
// ---------------------------------------------------------------------------------

function egg_shape(resolution, radius, parabola_top) {

    const a = findTangentA(radius, parabola_top, resolution);
    const tangentPoints = findTangentPoints(a, parabola_top, radius, resolution);

    const circlePoints = [];
    const rSquared = radius * radius;
    const xMax = Math.sqrt(rSquared);
    const step = 0.5;
    
    // Top half of circle
    for (let x = -xMax; x &lt;= xMax; x += step) {
        const y = Math.sqrt(rSquared - x * x);
        circlePoints.push([x, y]);
    }
    
    // Bottom half of circle (reverse direction)
    for (let x = xMax; x &gt;= -xMax; x -= step) {
        const y = -Math.sqrt(rSquared - x * x);
        circlePoints.push([x, y]);
    }
    
    const circleGeom = polygon({ points: circlePoints });

    const { xLeft, xRight } = tangentPoints;
    const parabolaPoints = [];
 
    
    for (let x = xLeft; x &lt;= xRight; x += step) {
        const y = -a * x * x + parabola_top;
        parabolaPoints.push([x, y]);
    }
    
    const parabolaGeom = polygon({ points: parabolaPoints });

    // intersect does what a union should do
    const eggProfile = intersect(circleGeom, parabolaGeom);

    // Create 3D egg by rotating the 2D profile
    return extrudeRotate({
        segments: resolution,
        angle: Math.PI * 2
    }, eggProfile);
}



//
// findTangentA
// ---------------------------------------------------------------------------------

function findTangentA(radius, h, resolution) {
    const R2 = radius * radius
    const stepA = 0.00001 
    const tolerance = 0.1
    const searchStep = 0.5 
    
    for (let a = 0.005; a &lt; 0.02; a += stepA) {
        let count = 0
        for (let x = -radius; x &lt;= radius; x += searchStep) {
            const y = -a * x * x + h
            const dist = x * x + y * y
            if (Math.abs(dist - R2) &lt; tolerance) count++
        }
        if (count === 2) return a  
    }
    
    return 0.0095  // Fallback value
}



//
// findTangentPoints
// ---------------------------------------------------------------------------------

function findTangentPoints(a, h, radius, resolution) {
    const R2 = radius * radius
    const points = []
    const dx = 0.01 
    const tolerance = 0.001  
    
    for (let x = -radius; x &lt;= radius; x += dx) {
        const y = -a * x * x + h
        const d = x * x + y * y
        if (Math.abs(d - R2) &lt; tolerance) points.push(x)
    }
    
    if (points.length &gt;= 2) {
        return { xLeft: Math.min(...points), xRight: Math.max(...points) }
    }
    return { xLeft: -radius * 0.8, xRight: radius * 0.8 }
}


</code></pre>
]]></description><link>https://openjscad.nodebb.com/topic/444/excessively-elaborate-eggs-etc</link><generator>RSS for Node</generator><lastBuildDate>Fri, 07 Aug 2026 18:07:03 GMT</lastBuildDate><atom:link href="https://openjscad.nodebb.com/topic/444.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 03 Aug 2025 23:49:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Excessively elaborate eggs etc on Sat, 20 Sep 2025 10:52:25 GMT]]></title><description><![CDATA[<p dir="auto">The booleans are working fine but the orientation of the polygons are super important. You can check the orientation your self, but one of the easiest checks if volume().</p>
<p dir="auto">Hope that helps</p>
]]></description><link>https://openjscad.nodebb.com/post/1479</link><guid isPermaLink="true">https://openjscad.nodebb.com/post/1479</guid><dc:creator><![CDATA[z3dev]]></dc:creator><pubDate>Sat, 20 Sep 2025 10:52:25 GMT</pubDate></item><item><title><![CDATA[Reply to Excessively elaborate eggs etc on Tue, 05 Aug 2025 15:14:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/nick-taylor" aria-label="Profile: Nick-Taylor">@<bdi>Nick-Taylor</bdi></a> this script looks incomplete, it is better to share a full script.</p>
<p dir="auto">also if you have discord we have a channel there  <a href="https://discord.gg/6PB7qZ4HC7" rel="nofollow ugc">https://discord.gg/6PB7qZ4HC7</a></p>
]]></description><link>https://openjscad.nodebb.com/post/1473</link><guid isPermaLink="true">https://openjscad.nodebb.com/post/1473</guid><dc:creator><![CDATA[hrgdavor]]></dc:creator><pubDate>Tue, 05 Aug 2025 15:14:01 GMT</pubDate></item></channel></rss>