Originally Posted by
matt.worland
Thank you guys, I was in the middle of writing a GetVectorTo function. I was hoping Autodesk didnt leave out the little stuff.
I appreciate the examples
You're welcome; I'm happy to help.
Along the lines of 'examples', one could also implement a simple Extension Method, which would reduce my code above, to this:
Code:
using Autodesk.AutoCAD.Geometry;
namespace BlackBox.AutoCAD.Geometry
{
public class Sample
{
static object Foo(Point2d pt1, Point2d pt2, double length)
{
return pt1.PolarIf(pt2, length);
}
}
}
... And here's the dependent Extension Method:
Code:
using System;
namespace Autodesk.AutoCAD.Geometry
{
public static class Point2dExtensions
{
public static object PolarIf(this Point2d pt1, Point2d pt2, double length)
{
object ret = null;
if (pt1.X == pt2.X && pt1.Y < pt2.Y | // up
pt1.X < pt2.X && pt1.Y < pt2.Y | // up-right
pt1.X < pt2.X && pt1.Y == pt2.Y | // right
pt1.X < pt2.X && pt1.Y > pt2.Y // right-down
)
{
double ang = pt1.GetVectorTo(pt2).Angle;
ret = new Point2d(pt1.X + length * Math.Cos(ang),
pt1.Y + length * Math.Sin(ang));
}
return ret;
}
}
}
Cheers