jscad / csg.js

DEPRECATED: CSG Library for JSCAD (See the link below)
https://github.com/jscad/OpenJSCAD.org/tree/master/packages/modeling
MIT License
218 stars 56 forks source link

I tried to get the cross section of a 3D object, but it seemed wrong. #140

Closed hurryhuang1007 closed 5 years ago

hurryhuang1007 commented 5 years ago

I created a tetrahedron and used a plane to intercept it. But there seems to be an additional bounding box in the result.

the dome: Edit p9o6wzlzrq

in my project like this: image

z3dev commented 5 years ago

@hurryhuang1007 thanks for the information.

Can you supply a quick code snippet? There are several ways to get the cross section. I want to know the functions being used.

hurryhuang1007 commented 5 years ago

@z3dev The code in the demo that I posted was my implementation in my project

hurryhuang1007 commented 5 years ago

@z3dev the “edit on code sandbox” is a link

hurryhuang1007 commented 5 years ago

@z3dev Excuse me, can u tell me is it I used the wrong API or it was a bug?

z3dev commented 5 years ago

The tetrahedron seems to be created with opposing faces, so I reversed the face definitions to create a valid solid. let faces = [[0, 1, 2], [0, 3, 1], [0, 2, 3], [1, 3, 2]]; Now, the section cut seems to work, but has some rotation issues due to the basis. Please review.

hurryhuang1007 commented 5 years ago

yeah, thx for ur answer, it's work. But I don't understand the difference define faces by [[0, 1, 2], [0, 3, 1], [0, 2, 3], [1, 3, 2]] or [[0, 1, 3], [0, 2, 1], [0, 3, 2], [1, 2, 3]] . Should there be a difference?

z3dev commented 5 years ago

Basically, the order of the vertices controls not just the shape, but also the 'normal' of the polygon. The normal is very important when performing union, intersection, difference. As well as, rendering the polygon.

https://en.wikipedia.org/wiki/Normal_(geometry)

If you look at the contents of each Polygon, you will find there's a list of vertices AND a plane. The plane is calculated form the order of the vertices.

Hope that helps.

z3dev commented 5 years ago

@hurryhuang1007 Please close if satisfied. Thanks.

hurryhuang1007 commented 5 years ago

very thx, I close it now.