Author
Topic: Geometry extensions (Read 12785 times)

I already posted this at TheSwamp.It will be my contribution to give a start to this new website.

These are some geometry extensions methods for Point2d, Point3d, CircularArc2d, Polyline and Polyline2d classes and two little classes: Triangle2d, Triangle3d.I hope someones find them usefull and expect it shows a little basic OOP concepts as the creation of new types and the extension of already existing ones.

All these classes work together and have to be compiled in a single DLL.

The extension methods requires to reference System.Core (.NET Framework 3.5) and are available for these objects as native methods while GeometryExtensions.dll is referenced:

I expanded a little the GeometryExtensions library.There're two more classes: PolylineSegment and PolylineSegmentCollection (which inherits from List<PolylineSegment>) and a new extension method: Ellipse.ToPolyline().I hope these classes make easier some work with polylines or to create polylines from other entities.

Here's a quick and dirty example (will give unexpected result with entities which don't lies on the WCS XY plane).The MJOIN command joins the selected entities: line, arc, polyline, ellipse and spline (A2010 or later for spline) into one or more polyline(s).

The main new things are Polyline, Polyline2d and Polyline3d extensions methods : GetProjectedPolyline and GetOrthoProjectedPolyline.

These methods create a new Polyline object and may replace the GetProjectedCurve and GetOrthoProjectedCurve methods which do not give expected results with Polyline and Polyline2d entities.The elliptical arcs resulting of the polyline arcs projection are approximated using the PolylineSegmentCollection(Ellipse ellipse) constructor. This constructor uses the same geometric method as the 'old' AutoCAD native approximation of ellipses (i.e. PELLIPSE = 1).

Hi Gile,If anyone can help you're the one.I few years ago i wrote a VBA program for AutoCAD doing Geometric calculations on Boundaries -- Polylines including Polylines.Part of the program involved the creation of the closed polylines, which you have elegantly solved in c#.Another Part is the calculation of the Moments of Inertia and the the Centroids also solved in the Geometry Extensions class.I've tried to include the Moments of Inertia calculation but because of too little experience in c# not succeeded yet.

The problem is that to my knowledge the Moments of Inertia can exactly be determined for (rotated) arc shaped contours using a Cone(Segment+Triangle), not a Segment. (see GeoCalcArc)

I like the way you calculate the area dividing everything in triangles and Arc Segment, it's far more elegant than my way of dividing everything in cones and trapezoid.

Have you any experience with the Inertia calculations, and if so can you help me out here.

But for the more advanced contours like profile3 the conversion to regions often fails. That's why i implemented that VBA solution a few years ago.

Currently i try to implement any of the following solutions:1. conversion of the VBA program Circle Cone + trapezoid calculations;2. circle segments + triangles calculations following you're code in PlineAlgebraicArea(...);3. circle segments + "cross section defined as polygon" from http://en.wikipedia.org/wiki/Second_moment_of_area

The second one is my favorite because of the simplicity(== elegance) of your code, however the implementation of the Inertia calculation for rotated non symmetrical triangles is a bit tricky. It requires additional Ixy calculations.

Hi Gile,Thank you for posting this new version. Currently i am working on the Paperspace to Modelspace transformation and testing code for these calculations. But i can't get it right.This is the scenario:Simple Viewport rotated and zoomed to a rectangle in modelspace, see attachment.When executing the command MSPVP1 an exact matching rectangle presenting the Paperspace Viewport border will be created in Modelspace.When executing the command msPVPByGile there is a small displacement.I suppose there is a problem with the order of the Matrix transformation in Matrix3d ps2wcs = pvp2.PSDCS2DCS() * pvp2.DCS2WCS();

As you say the matrix multiplication is not comutative.When multiplying two matrices, the resulting matrix can be considered as the combination of the right hand matrix transformation first and then, the left hand one.This is the way the * operator works (as in maths).

So to transform from paper space coordinates to model space coordinates, you have to write: