TheSwamp
Code Red => .NET => Topic started by: wannabe on June 19, 2009, 07:57:12 AM
-
I'm working on a small application that will get points at specified locations along a polyline utilising the functionality available in the abstract Curve class.
At the moment I'm not having any luck in finding a method that will get points along my polyling ignoring its depth value. Rather than creating a 2d version of my 3D polyline, is there a method that will treat my 3D poly as 2D and ignore all the Z values?
Cheers
-
Use this method
GetOrthoProjectedCurve(Autodesk.AutoCAD.Geometry.Plane planeToProjectOn)
-
Use this method
GetOrthoProjectedCurve(Autodesk.AutoCAD.Geometry.Plane planeToProjectOn)
Will do. Thanks.
-
Use this method
GetOrthoProjectedCurve(Autodesk.AutoCAD.Geometry.Plane planeToProjectOn)
If my X axis is running horizontal, my Y running vertical and I want to select a polyline and convert it to a 2D version how do I configure this method? So far it's hitting me with errors each time.
Cheers
-
Actually ignore my last post.
For anyone else's potential benefit, this method will only return a 2D representation if you pass it an actual 3D polyline. My testing was based on a 2D which was giving me the errors.
-
Actually ignore my last post.
For anyone else's potential benefit, this method will only return a 2D representation if you pass it an actual 3D polyline. My testing was based on a 2D which was giving me the errors.
This unfortunately means processing polycurves with arcs (bulges) is not possible with those Database Curve methods. It was one of the reasons I used that DBCurve to GeometryCurve Helper class. The Geometry namespace CompositeCurve can be projected even if it contains arcs.
-
Actually ignore my last post.
For anyone else's potential benefit, this method will only return a 2D representation if you pass it an actual 3D polyline. My testing was based on a 2D which was giving me the errors.
This unfortunately means processing poly”curves” with arcs (bulges) is not possible with those Database Curve methods. It was one of the reasons I used that DBCurve to GeometryCurve Helper class. The Geometry namespace CompositeCurve can be projected even if it contains arcs.
Do you have a snippet of code I could take a look at or a reference to some, please?
-
public static Autodesk.AutoCAD.DatabaseServices.Polyline ToPolyline(CompositeCurve3d cc3d)
{
Autodesk.AutoCAD.DatabaseServices.Polyline pl = new Autodesk.AutoCAD.DatabaseServices.Polyline();
pl.Elevation = cc3d.StartPoint[2];
Plane plane = pl.GetPlane();
Point2d endver = Point2d.Origin;
int i = 0;
foreach (Curve3d c3d in cc3d.GetCurves())
{
if (c3d is CircularArc3d)
{
CircularArc3d ca3d = (CircularArc3d)c3d;
double b = Math.Tan(0.25 * (ca3d.EndAngle - ca3d.StartAngle)) * ca3d.Normal[2];
pl.AddVertexAt(i, c3d.StartPoint.Convert2d(plane), b, 0, 0);
endver = c3d.EndPoint.Convert2d(plane);
}
else
{
pl.AddVertexAt(i, c3d.StartPoint.Convert2d(plane), 0, 0, 0);
endver = c3d.EndPoint.Convert2d(plane);
}
i++;
}
pl.AddVertexAt(i, endver, 0, 0, 0);
return pl;
}
public static CompositeCurve3d ToCompositeCurve3d(Autodesk.AutoCAD.DatabaseServices.Polyline pl)
{
List<Curve3d> c3ds = new List<Curve3d>();
for (int i = 0; i < pl.NumberOfVertices; i++)
{
switch (pl.GetSegmentType(i))
{
case SegmentType.Line:
c3ds.Add(pl.GetLineSegmentAt(i));
break;
case SegmentType.Arc:
c3ds.Add(pl.GetArcSegmentAt(i));
break;
default:
break;
}
}
return new CompositeCurve3d(c3ds.ToArray());
}
[CommandMethod("t8")]
public static void Test8()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
Autodesk.AutoCAD.DatabaseServices.Polyline pl = new Autodesk.AutoCAD.DatabaseServices.Polyline();
pl.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0);
pl.AddVertexAt(1, new Point2d(10, 0), 0.5, 0, 0);
pl.AddVertexAt(2, new Point2d(20, 0), 0, 0, 0);
pl.Elevation = 10;
CompositeCurve3d cc3d = ToCompositeCurve3d(pl);
cc3d = (CompositeCurve3d)cc3d.GetOrthoProjectEntity(new Plane());
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
pl = ToPolyline(cc3d);
btr.AppendEntity(pl);
tr.AddNewlyCreatedDBObject(pl, true);
tr.Commit();
}
-
Actually ignore my last post.
For anyone else's potential benefit, this method will only return a 2D representation if you pass it an actual 3D polyline. My testing was based on a 2D which was giving me the errors.
This unfortunately means processing poly”curves” with arcs (bulges) is not possible with those Database Curve methods. It was one of the reasons I used that DBCurve to GeometryCurve Helper class. The Geometry namespace CompositeCurve can be projected even if it contains arcs.
Do you have a snippet of code I could take a look at or a reference to some, please?
The thread over at CadTutor (post 22) has a start (similar to the process posted by xsfhlzh above). I have an updated version that includes a few more curve types. I’ll post the update when I get a chance.
http://www.cadtutor.net/forum/showthread.php?t=33523
-
Excellent, as always.
-
This version could still use some refinement. Quadratic- and CubicFit Polys are still not implemented, nor is the error checking mechanism finalized.
Eventually Id like to incorporate a similar process for 3d entities such as the primitives Sphere, Cylinder, Torus, etc.
Edit: Outdated code removed.
-
This version could still use some refinement. Quadratic- and CubicFit Polys are still not implemented, nor is the error checking mechanism finalized.
Eventually I’d like to incorporate a similar process for 3d entities such as the primitives Sphere, Cylinder, Torus, etc.
EllipticalArc3d's Angle is Ellipse's Param,
public static EllipticalArc3d ToEllipticalArc3d(Ellipse ell)
{
return
new EllipticalArc3d(
ell.Center,
ell.MajorAxis.GetNormal(),
ell.MinorAxis.GetNormal(),
ell.MajorRadius,
ell.MinorRadius,
ell.StartParam,
ell.EndParam);
}
Quadratic- and CubicFit Polys,Convert it to NurbCurve3d
public static NurbCurve3d ToNurbCurve3d(Polyline2d pl2d)
{
switch (pl2d.PolyType)
{
case Poly2dType.SimplePoly:
case Poly2dType.FitCurvePoly:
Polyline pl = new Polyline();
pl.ConvertFrom(pl2d, false);
return ToNurbCurve3d(pl);
default:
return ToNurbCurve3d(pl2d.Spline);
}
}
-
Good catch with the -Angle/-Param switch. :-)
I have to admit that the EllipticalArc3d is trickier than I first assumed. After further testing, Ive found that the Ellipse.MinorRadius is not reliable, and should, instead, be replaced by Ellipse.MajorRadius * Ellipse.RadiusRatio.
With regard to the splined polys: I wasnt sure the best way to proceed given that the curve within AutoCADs drawing editor is actually straight line segments (driven by SPLINESEGS system variable) inscribed to a control spline.