ImplicitCAD icon indicating copy to clipboard operation
ImplicitCAD copied to clipboard

Floating polygons in output

Open bgamari opened this issue 12 years ago • 10 comments

For some reason, this model seems to produce some very strange floating polygons. This appears to happen at all resolutions although the size of the polygons decreases with resolution; the attached image was taken of a mesh with a resolution of 1.

floating polygons

bgamari avatar May 08 '13 15:05 bgamari

It seems that the rotate on line 41 is responsible for the floating polygons: commenting this line out is sufficient to eliminate them.

bgamari avatar May 08 '13 21:05 bgamari

In fact, the following is sufficient to reproduce the issue,

rotate([0,30,0])
cylinder(r=10, h=20);

In general it seems that cylinders are extremely fragile under rotation.

bgamari avatar May 14 '13 18:05 bgamari

That's an interesting object!

Sorry I haven't been able to look into this before now. Super super busy.

I've seen issues similar to this before. They were related to mesh simplification and went away when I disabled it...

I'll try to look into this properly in a bit!

colah avatar May 15 '13 20:05 colah

I confirmed that if you comment out the tesseltateLoop case starting at line 43 of Graphics/Implicit/Export/Render/TesselateLoop.hs , which is responsible for generating squares (which are the merged if possible, and then converted into triangles) the problem goes away.

{-tesselateLoop res obj [[a,_],[b,_],[c,_],[d,_]] | centroid [a,c] == centroid [b,d] =
    let
        b1 = normalized $ a ^-^ b
        b2 = normalized $ c ^-^ b
        b3 = b1 `cross3` b2
    in [Sq (b1,b2,b3) (a ⋅ b3) (a ⋅ b1, c ⋅ b1) (a ⋅ b2, c ⋅ b2) ]-}

But disabling the square merging code doesn't fix it, so there are some cases in which squareToTris doesn't accurately turn squares into triangles. squareToTris (Graphics/Implicit/Export/Render/HandleSquares.hs

squareToTri (Sq (b1,b2,b3) z (x1,x2) (y1,y2)) =
    let
        zV = b3 ^* z
        (x1V, x2V) = (x1 *^ b1, x2 *^ b1)
        (y1V, y2V) = (y1 *^ b2, y2 *^ b2)
        a = zV ^+^ x1V ^+^ y1V
        b = zV ^+^ x2V ^+^ y1V
        c = zV ^+^ x1V ^+^ y2V
        d = zV ^+^ x2V ^+^ y2V
    in
        [(a,b,c),(c,b,d)]

Since they appear to be shifting along the normal, clearly b3 and its dot products are implicated. My suspicion is some sort of floating point error...

colah avatar May 16 '13 12:05 colah

I'm seeing holes, but no floating squares.

julialongtin avatar Mar 07 '17 21:03 julialongtin

Reproduced.

julialongtin avatar Aug 22 '19 18:08 julialongtin

Btw. Thank you @julialongtin for reviewing these bugs. I hope that after I get with speed on the project I will be able to help.

oneacik avatar Aug 29 '19 13:08 oneacik

I've confirmed that disabling the tesserateLoop above removes this failure. I'm going to leave it disabled, while i come up to speed on the math in those two functions.

julialongtin avatar Sep 29 '19 19:09 julialongtin

`width=88; height=6; length=6; center_offset=5.3;

linear_extrude (width/2, translate(z)=(0,-z/center_offset)) polygon ( [(0,0), (0,center_offset+length), (height, center_offset+length)]); `

produces the same problem as the initial reporter's issue, but is much shorter. the vertical squares are perfect, the squares not-quite-aligned with the Y axis are perfect, but the squares on the underside of the object are on the right plane, but off of their x-y position.

julialongtin avatar Sep 30 '19 08:09 julialongtin

those squares are more off the further from (0,0,0) they are.

julialongtin avatar Sep 30 '19 08:09 julialongtin