.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Check the drawing direction of a polyline

4 REPLIES 4
Reply
Message 1 of 5
autodesk.subscription
1996 Views, 4 Replies

Check the drawing direction of a polyline

Hi,
how can I find the drawing direction of a (closed) polyline with c#? Is there a property or method available or does one have a code snippet 🙂

TIA
Herbert
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: autodesk.subscription

h.putz@eurogis.de wrote:

> how can I find the drawing direction of a (closed) polyline with c#?
> Is there a property or method available or does one have a code
> snippet 🙂

Calculate the area (yourself), I think it's called Double Meridian
Distance. If the result is negative, your polyline is counterclockwise.

Terry
Message 3 of 5
Anonymous
in reply to: autodesk.subscription

Terry,

Am Thu, 24 Sep 2009 15:22:17 +0000 schrieb Terry W. Dotson:

> h.putz@eurogis.de wrote:
>
>> how can I find the drawing direction of a (closed) polyline with c#?
>> Is there a property or method available or does one have a code
>> snippet 🙂
>
> Calculate the area (yourself), I think it's called Double Meridian
> Distance. If the result is negative, your polyline is counterclockwise.

thank you for your hint,

this is working:

///
/// Methode GetAreaDMD( Polyline oPoly)
/// Berechnet die Fläche eines geschlossenen Polygons nach der
/// DoubleMeridianDistance-Methode
/// (-(x1*y2)-(x2*y3)-...(xn*y1)+(y1*x2)+(y2*x3)+...(yn*x1))/2
///

///
/// oPoly ist eine AutoCAD-Polylinie
///
///
/// Flächenwert als Double
/// nArea > 0 --> Fläche im Uhrzeigersinn gezeichnet
/// nArea < 0 --> Fläche gegen den Urzeigersinn gezeichnet
///

private double GetAreaDMD(Polyline oPoly)
{
int nPoints;
double nArea;
nPoints = oPoly.NumberOfVertices-1; // -1 weil Nullbasiert
nArea = 0.00;

for (int i=0; i < nPoints; i++)
{
nArea -= (oPoly.GetPoint2dAt(i).X*oPoly.GetPoint2dAt(i+1).Y);
nArea += (oPoly.GetPoint2dAt(i).Y*oPoly.GetPoint2dAt(i+1).X);
} // for ...
nArea -= (oPoly.GetPoint2dAt(nPoints).X*oPoly.GetPoint2dAt(0).Y);
nArea += (oPoly.GetPoint2dAt(nPoints).Y*oPoly.GetPoint2dAt(0).X);

return nArea/2;
} // GetAreaDMD()

Bye
Herbert
Message 4 of 5

Herbert your formula has 1 too many loops.
You are getting the area of triangles and the total should be double the actual area of the pline.
The divide by 2 step is not needed for this function, so is not used

int count=pline.NumberOfVertices-1;
Point2d p1, p2;
for(int i = 0;i < count;i++)
{
p1=pline.GetPoint2dAt(i);
p2=pline.GetPoint2dAt(i+1);
Sum = Sum + ((p1.X * p2.Y) - (p1.Y * p2.X));
}
p1 = p2;
p2 = pline.GetPoint2dAt(0);
Sum = Sum + ((p1.X * p2.Y) - (p1.Y * p2.X));
Message 5 of 5

Hi,

this one works with polyline arc segments too

{code}public double PlineAlgebraicArea(Polyline pl)
{
Point2d p0 = pl.GetPoint2dAt(0);
double area = 0.0;
double bulge = pl.GetBulgeAt(0);
int last = pl.NumberOfVertices - 1;
double tmpArea;

if (bulge != 0.0)
{
CircularArc2d arc = pl.GetArcSegment2dAt(0);
double arcRadius = arc.Radius;
double arcAngle = 4.0 * Math.Atan(bulge);
area += ArcAlgebraicArea(arcRadius, arcAngle);
}
for (int i = 1; i < last; i++)
{
area += TriangleAlgebricArea(p0, pl.GetPoint2dAt(i), pl.GetPoint2dAt(i + 1));
bulge = pl.GetBulgeAt(i);
if (bulge != 0.0)
{
CircularArc2d arc = pl.GetArcSegment2dAt(i);
double arcRadius = arc.Radius;
double arcAngle = 4.0 * Math.Atan(bulge);
area += ArcAlgebraicArea(arcRadius, arcAngle);
}
}
bulge = pl.GetBulgeAt(last);
if (bulge != 0.0)
{
CircularArc2d arc = pl.GetArcSegment2dAt(last);
double arcRadius = arc.Radius;
double arcAngle = 4.0 * Math.Atan(bulge);
area += ArcAlgebraicArea(arcRadius, arcAngle);
}
return area;
}

public double TriangleAlgebraicArea(Point2d p0, Point2d p1, Point2d p2)
{
return (((p1.X - p0.X) * (p2.Y - p0.Y)) - ((p2.X - p0.X) * (p1.Y - p0.Y))) / 2.0;
}

public double ArcAlgebraicArea(double rad, double ang)
{
return rad * rad * (ang - Math.Sin(ang)) / 2.0;
}{code}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost