Question Math / Geometry / CAD .net Advice Please!

cadnewb

New member
Joined
Dec 16, 2018
Messages
2
Programming Experience
10+
I am working with CAD .NET library (cadsofttools) and hoping others have an insight for a solution and potentially know of other libraries (open source) that can help. The CAD library provides all access to entities so lines, arcs, circles, etc. To eliminate any issues we provide functionality to remove layers/entities of no interest and manual editing if contours aren't properly closed off (ie 4 lines don't fully connect, they have to otherwise it's not a closed shape). And shapes are irregular, so most of the time we look at the X and Y of the rectangle area the irregular shape occupies to make it easier. They have a good demo editor which I've customized and began mocking up the algorithm(s) for the concept I am explaining below and realizing this could get a little interesting.

Since I have access to all basic geometry, I believe I just need a series of formulas and calculations to begin post processing the entities and doing things like,

1) Group them into shapes (ie 50 entities but really 4 rectangles, 6 circles, and etc.)
- ie. if I find 4 lines that intersect to form a rectangle,remove 4 entities from a list and build a single shape that maps to the 4 individual entities
2) Calculating distance of all line segments is very straight forward looking at entities individually - done
3) Identify if lines intersect, one shape or entity is within another, and some kind of hierarchy of shapes
4) Be able to identify areas of new shapes we find, ideally leads towards finding true area of irregular shape (like someone normally would in a math exercise)

I don't think the algorithm would be perfect, there's some messy drawings. So each step my UI allows intervention and manual override to "correct" things or help make decisions with an editor and context menu options + selecting entities. So you can easily just select 4 entities and add it to a shape list, that's very easy. But the more automatic algorithm I am looking to do is to post process CAD Entities and based on the information above I think it's just a collection of math libraries and pretty common stuff to build more of a auto detection feature in.

I have sample code / pseudo code of what I am starting to do with CAD library but was hoping someone with experience could weigh in if this is just a waste of time, if my logic and explanation makes sense. To me I am not writing proprietary code at all so sharing my pseudo code or final solution doesn't matter to me I more so want opinions, guidance, and to understand if there's any available libraries to help me instead of re-writing all of my junior high mathematics learning into classes for rectangles, circles, and etc. I'll probably spend time cleaning it up, putting it on github, or sending it back to the cadsofttools team to incorporate as helper code with their library.

Someone who knows CAD would help too because I realize when you have an arc + 3 lines and get an irregular shape, you now have to do things like 1 shape (break into two, calculate area, combine as one shape and combine areas) so there can potentially be edge cases.

Or if what I am doing already sounds like something out there why re-invent the wheel...or if it's a waste of time just let me know that too! Any help, advice, or suggestions would be greatly appreciated.
 
I have most of the shape analysis complete, however my algorithm generates distinct shapes for things that don't physically touch. This is fine, ie shapes inside of shapes. However, I still want to try and form a relationship between these shapes (one is inside the other, so it's the parent). I am trying to think of a simpler generic way to take lines, arcs, circles, and identify if the irregular or regular shape I identified is inside.

One idea I had, was that I already know a shape is either inside or outside because if at any point they intersected or touched each other my algorithm would have picked them up as one shape. So, I've tested the code and the other shape(s) are either inside or outside. Maybe I can just take key points if line/arc or if a circle just extrapolate lines to see if they all would touch (meaning it's inside) or only some or none, meaning it's outside.

Or is this too simple of an assumption?
 
Back
Top Bottom