Community
I want to add fillet of radius 90 at each corner of polyline as shown in image, how can i do it programatically using .Net
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Hi,
You can use or get inspiration from these extension methods from the GeometryExtensions library.
/// <summary>
/// Adds an arc (fillet), when possible, at each vertex.
/// </summary>
/// <param name="pline">The instance to which this method applies.</param>
/// <param name="radius">The arc radius.</param>
/// <exception cref="ArgumentNullException">ArgumentException is thrown if <paramref name="pline"/> is null.</exception>
public static void FilletAll(this Polyline pline, double radius)
{
ArgumentNullException.ThrowIfNull(pline);
int n = pline.Closed ? 0 : 1;
for (int i = n; i < pline.NumberOfVertices - n; i += 1 + pline.FilletAt(i, radius))
{ }
}
/// <summary>
/// Adds an arc (fillet), when possible, at specified vertex.
/// </summary>
/// <param name="pline">The instance to which this method applies.</param>
/// <param name="index">The vertex index.</param>
/// <param name="radius">The arc radius.</param>
/// <returns>1, if the operation succeded; 0, if it failed</returns>
/// <exception cref="ArgumentNullException">ArgumentException is thrown if <paramref name="pline"/> is null.</exception>
public static int FilletAt(this Polyline pline, int index, double radius)
{
ArgumentNullException.ThrowIfNull(pline);
int prev = index == 0 && pline.Closed ? pline.NumberOfVertices - 1 : index - 1;
if (pline.GetSegmentType(prev) != SegmentType.Line ||
pline.GetSegmentType(index) != SegmentType.Line)
{
return 0;
}
LineSegment2d seg1 = pline.GetLineSegment2dAt(prev);
LineSegment2d seg2 = pline.GetLineSegment2dAt(index);
Vector2d vec1 = seg1.StartPoint - seg1.EndPoint;
Vector2d vec2 = seg2.EndPoint - seg2.StartPoint;
double angle = (Math.PI - vec1.GetAngleTo(vec2)) / 2.0;
double dist = radius * Math.Tan(angle);
if (dist == 0.0 || dist > seg1.Length || dist > seg2.Length)
{
return 0;
}
Point2d pt1 = seg1.EndPoint + vec1.GetNormal() * dist;
Point2d pt2 = seg2.StartPoint + vec2.GetNormal() * dist;
double bulge = Math.Tan(angle / 2.0);
if (Clockwise(seg1.StartPoint, seg1.EndPoint, seg2.EndPoint))
{
bulge = -bulge;
}
pline.AddVertexAt(index, pt1, bulge, 0.0, 0.0);
pline.SetPointAt(index + 1, pt2);
return 1;
}
Can't find what you're looking for? Ask the community or share your knowledge.