Skip to content

Convex hull algorithm fails in some cases #498

@sixFingers

Description

@sixFingers

Hi, i noticed that, in rare cases, jarvis_march fails to produce a valid hull. Instead, it keeps looping around the supplied point list. I have a really hard time understanding the problem (shouldn't be co-planarity, since it works in other cases). Anyway, i applied a patch that works for me. Not sure a PR is worth it, here my addition (which is admittedly not really mathematic-ish):

local checked = 1

while(visited[q]) do
    checked = checked + 1
    q = points[q + 1] and q + 1 or 1

    if (checked == #points) then
        return hull
    end
end

.. which goes right at line 40, before the loop. This at least prevents the algo to loop over infinitely, while still supplying a valid hull (at least, it looks to me in a test case with ~ 200 procedurally generated point clouds). I'm bothering to write here because it looks @Yonaba's Lua implementation is the landing page for people with convex-hull needs :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions