Coder Social home page Coder Social logo

Bug in hull() about openjscad.org HOT 6 CLOSED

jscad avatar jscad commented on July 28, 2024
Bug in hull()

from openjscad.org.

Comments (6)

Spiritdude avatar Spiritdude commented on July 28, 2024

Note to myself:

function main() {
   return hull(
        CAG.circle({radius:2}).translate([-1,0]),
        CAG.circle().translate([1,0]),
        CAG.circle().translate([0,1.01])
    );
}

works.

Problem: in this.ccw and stack calculation (x1==x2 or y1==y2)

from openjscad.org.

Spiritdude avatar Spiritdude commented on July 28, 2024

More simple case:

function main() {
   return hull(
        CAG.circle().translate([0,1]),
        CAG.circle().translate([0,-1])
    );
}

gives error, the two circles have a common point, the moment they are apart hull() works.

from openjscad.org.

Axford avatar Axford commented on July 28, 2024

Perhaps recode the sort to use the faster isLeft() function described for the Graham scan algorithm:

http://geomalgorithms.com/a01-_area.html#isLeft()

via http://geomalgorithms.com/a10-_hull-1.html

Avoids the need for atan... looks partially implemented with the ccw function?

from openjscad.org.

Spiritdude avatar Spiritdude commented on July 28, 2024

isLeft() = ccw(), the problem lies in the stack operation while(this.ccw(...)<=0) ... and I already have tested prefiltering multiple points with same coords (not sure if it works as I still run the same problem). I did some more testing, it seems with most close (1e-5 or less) but not quite identical x1==x1 and y1==y2

from openjscad.org.

Axford avatar Axford commented on July 28, 2024

this quick hack to the ccw function sorts it:

this.ccw = function(p1, p2, p3) {
           var tmp = (this.points[p2].x - this.points[p1].x)*(this.points[p3].y - this.points[p1].y) - 
                (this.points[p2].y - this.points[p1].y)*(this.points[p3].x - this.points[p1].x);
           // look for close points
           if (tmp < 0.000001) tmp = 0;
           return tmp;
      }

from openjscad.org.

Spiritdude avatar Spiritdude commented on July 28, 2024

great, yes, it does it (thanks!)

from openjscad.org.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.