How can I extrude a list of 2DPoints to a Mesh and subtract these extrusions in C#? [Constructive Solid Geometry]

346 Views Asked by At

I am struggling already a couple of days with a problem regarding Constructive Solid Geometry. Actually I start from a list of 2DLines (with 2DPoints) that I have to extrude in the 3D-space. That is something I manage to do with a triangulation algorithm and I can visualize is with Helix Toolkit. Than I tried several open source library's to do the boolean operation "subtract", the one I have the best results is with this library (but I am open for other libraries of course). The example I will give is with the points below in this question.

The code I am using to do the subtraction is an extrusion where I already expiremented a lot to change the direction of the vertices in counterclockwise to get the correct normals, but it is still not working.

CSCSG_Solid lovToolSolid = Extrude_Element_List_To_Solid(ElementList, 0, 70);
CSCSG_Matrix4x4 lovTransform = CSCSG_Matrix4x4.RotationY(270) * CSCSG_Matrix4x4.Translation(new CSCSG_Vector3D(0.01, 0.01, -0.01));
var lovHornSolid = Extrude_Element_List_To_Solid(HornList, -200, 200);
var lovHorn_Transformed = lovHornSolid.Transform(lovTransform);
modelGroup.Children.Add(Convert_Solid_To_GeometryModel3D(Colors.Gray, lovToolSolid.Substract(lovHorn_Transformed)));

You see that the triangles that I get as a result are not entirely correct and that is a bit frustrating.

I already experimented with multiple libraries (e.g. this one as well: Net3dBool from Sebastian Loncar aka 'arakis') and tried with the vertices of the polygons of the solids, multiple algorithms to determine if it is counterclockwise or clockwise... No solution.

Is there someone who has done something similar and wants to share how (s)he solved the problem? Which library did you use, how did you extrude the list of 2DPoints?

Regards from Belgium, Joachim

HornList
Count = 26
    [0]: {[X=-10][Y=37] [X=0][Y=37]}
    [1]: {[X=0][Y=37] [X=0][Y=14,000000000089]}
    [2]: {[X=0][Y=14,000000000089] [X=0,01][Y=13,997320508164]}
    [3]: {[X=0,01][Y=13,997320508164] [X=15,82][Y=9,761043775828]}
    [4]: {[X=15,82][Y=9,761043775828] [X=15,84][Y=9,75568479198]}
    [5]: {[X=15,84][Y=9,75568479198] [X=15,97][Y=9,720851396963]}
    [6]: {[X=15,97][Y=9,720851396963] [X=15,99][Y=9,715492413115]}
    [7]: {[X=15,99][Y=9,715492413115] [X=19,25][Y=8,841978045789]}
    [8]: {[X=19,25][Y=8,841978045789] [X=19,27][Y=8,836619061941]}
    [9]: {[X=19,27][Y=8,836619061941] [X=27,04][Y=6,754653836751]}
    [10]: {[X=27,04][Y=6,754653836751] [X=27,06][Y=6,749294852902]}
    [11]: {[X=27,06][Y=6,749294852902] [X=34,99][Y=4,624457756924]}
    [12]: {[X=34,99][Y=4,624457756924] [X=34,99][Y=-163,798514080966]}
    [13]: {[X=34,99][Y=-163,798514080966] [X=27,06][Y=-168,37690171564]}
    [14]: {[X=27,06][Y=-168,37690171564] [X=27,04][Y=-168,388448721024]}
    [15]: {[X=27,04][Y=-168,388448721024] [X=19,27][Y=-172,874460312627]}
    [16]: {[X=19,27][Y=-172,874460312627] [X=19,25][Y=-172,886007318011]}
    [17]: {[X=19,25][Y=-172,886007318011] [X=15,99][Y=-174,768169195569]}
    [18]: {[X=15,99][Y=-174,768169195569] [X=15,97][Y=-174,779716200953]}
    [19]: {[X=15,97][Y=-174,779716200953] [X=15,84][Y=-174,854771735948]}
    [20]: {[X=15,84][Y=-174,854771735948] [X=15,82][Y=-174,866318741332]}
    [21]: {[X=15,82][Y=-174,866318741332] [X=0,01][Y=-183,99422649722]}
    [22]: {[X=0,01][Y=-183,99422649722] [X=0][Y=-183,999999999911]}
    [23]: {[X=0][Y=-183,999999999911] [X=0][Y=-193,999999999911]}
    [24]: {[X=0][Y=-193,999999999911] [X=-10][Y=-193,999999999911]}
    [25]: {[X=-10][Y=-193,999999999911] [X=-10][Y=37]}
    
ElementList
Count = 26
    [0]: {[X=3,48943396645][Y=-185,7764239243] [X=1,94874012955][Y=-192,4499021086]}
    [1]: {[X=1,94874012955][Y=-192,4499021086] [X=-0][Y=-193,999999999911] [X=-1,94874012955][Y=-192,4499021086] [X=-0][Y=-191,999999999937]}
    [2]: {[X=-1,94874012955][Y=-192,4499021086] [X=-6,00939006965][Y=-174,8612948592]}
    [3]: {[X=-6,00939006965][Y=-174,8612948592] [X=-5,61964204375][Y=-174,7713144375]}
    [4]: {[X=-5,61964204375][Y=-174,7713144375] [X=-14,00000000005][Y=-138,4719961321]}
    [5]: {[X=-14,00000000005][Y=-138,4719961321] [X=-14,00000000005][Y=-3]}
    [6]: {[X=-14,00000000005][Y=-3] [X=-13,00000000005][Y=-2]}
    [7]: {[X=-13,00000000005][Y=-2] [X=-10,00000000005][Y=-2]}
    [8]: {[X=-10,00000000005][Y=-2] [X=-10,00000000005][Y=16,5]}
    [9]: {[X=-10,00000000005][Y=16,5] [X=-6,50000000005][Y=20]}
    [10]: {[X=-6,50000000005][Y=20] [X=-6,50000000005][Y=21,5]}
    [11]: {[X=-6,50000000005][Y=21,5] [X=-10,00000000005][Y=25]}
    [12]: {[X=-10,00000000005][Y=25] [X=-10,00000000005][Y=36]}
    [13]: {[X=-10,00000000005][Y=36] [X=-9,00000000005][Y=37]}
    [14]: {[X=-9,00000000005][Y=37] [X=8,99999999995][Y=37]}
    [15]: {[X=8,99999999995][Y=37] [X=9,99999999995][Y=36]}
    [16]: {[X=9,99999999995][Y=36] [X=9,99999999995][Y=25]}
    [17]: {[X=9,99999999995][Y=25] [X=6,49999999995][Y=21,5]}
    [18]: {[X=6,49999999995][Y=21,5] [X=6,49999999995][Y=20]}
    [19]: {[X=6,49999999995][Y=20] [X=9,99999999995][Y=16,5]}
    [20]: {[X=9,99999999995][Y=16,5] [X=9,99999999995][Y=-18]}
    [21]: {[X=9,99999999995][Y=-18] [X=5,85786437625][Y=-22,1421356237]}
    [22]: {[X=5,85786437625][Y=-22,1421356237] [X=1,522409349763][Y=-28,630602600119] [X=-5E-11][Y=-36,2842712474] [X=20,000000000194][Y=-36,284271247563]}
    [23]: {[X=-5E-11][Y=-36,2842712474] [X=-5E-11][Y=-168,3833127175]}
    [24]: {[X=-5E-11][Y=-168,3833127175] [X=0,12856288642][Y=-170,64737699287] [X=0,51259870425][Y=-172,8823338044] [X=20][Y=-168,383312717497]}
    [25]: {[X=0,51259870425][Y=-172,8823338044] [X=3,48943396645][Y=-185,7764239243]}   
1

There are 1 best solutions below

2
Lance H On

There are several libraries in c++, you can use c++ library and call from c# to process the mesh, then use helix toolkit for presentation. Usually these libraries are written in c++ for performance and cross platform reasons.