Identify Sides of an exploded object


I am coding up a plugin in C# to add perpendicular lines to all the edge of a selected shape (assuming shape is a 4 sided). I could not find anything to identify the edges of a select shape, so my approach is, exploding the selected shape and getting the objects for individual side and converting the objects to lines so that I can easily find the edges for the sides.

Now my problem is I cannot identify which object belongs to which side after exploding, so I am unable to proceed from here.

Example shape which I am working with

What would be the best way to identify which object belongs to which side or is my approach wrong?



There probably is no best way, but the solution depends on what you want to achieve.

If your shapes always have four sides and are all drawn from the same start point (not position, but i.e. top left corner) in the same direction (clockwise or counter clockwise), you could simply select and categorise them by order of the exploded lines. For example, if all your polylines are staring at the top left corner and are drawn in a counter clockwise manner, the first curve after explosion would be the left, vertical line at index 0, the second, the bottom line at index 1 and so fourth. This would be relative to their position, meaning that sides of neighbouring, rotated polylines - drawn in the same manner - would be in the same, correct order, but would not have the same direction as the same lines of a differently rotated objects.

Furthermore, if you want to categorise sides by their global position, meaning that left, bottom, right, top (west, south, east, north) is applied to all sides, independent of their position and rotation in space, than you could define a set of 4 vectors, describing each main direction. By calculating the cross product of the tangent and normal at - let’s say - the center point of each line, you would be able to compare this cross product vector to your predefined set of direction vectors. Each line could thus be categorised as top, bottom, left or right side line. Oblique sides would have to be treated a little different. They would merit from a sub categorisation, - let’s say - by their similarity to one direction. I guess this would be feasible, by comparing angles.

1 Like