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

Add fillet to each corner of a polyline

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
1930331246064
191 Views, 2 Replies

Add fillet to each corner of a polyline

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 Screenshot 2024-06-06 202304.png

2 REPLIES 2
Message 2 of 3
_gile
in reply to: 1930331246064

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;
}

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 3

working! thanks

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

Post to forums  

Forma Design Contest


AutoCAD Beta