Draw an arc between two points with a center

Draw an arc between two points with a center

adrian_sieradzki
Contributor Contributor
1,834 Views
8 Replies
Message 1 of 9

Draw an arc between two points with a center

adrian_sieradzki
Contributor
Contributor

Hi there I can't figure out how to use the arc constructor to create arc between two points

public static Arc CreateArcFromCenterAndTwoPoints(Point3d center, Point3d startPoint, Point3d endPoint)
        {
            var referenceVector = new Vector3d(0, -1, 0);
            var startAngle = (startPoint - center).GetAngleTo(referenceVector, Vector3d.ZAxis);
            var endAngle = (endPoint - center).GetAngleTo(referenceVector, Vector3d.ZAxis);

            var arc = new Arc(center, center.DistanceTo(startPoint), startAngle, endAngle);


            return arc;
        }

When I draw arc in autocad the reference vector points straight down and angle is counted counter-clockwise from there, when I try to code this nothing works I get random arcs in random places with random lengths. 

0 Likes
Accepted solutions (2)
1,835 Views
8 Replies
Replies (8)
Message 2 of 9

_gile
Consultant
Consultant
Accepted solution

Hi,

If I do not misunderstand the goal, this should work:

        public static Arc CreateArcFromCenterAndTwoPoints(Point3d center, Point3d startPoint, Point3d endPoint)
        {
            var startVector = startPoint - center;
            var endVector = endPoint - center;
            var startAngle = Vector3d.XAxis.GetAngleTo(startVector, Vector3d.ZAxis);
            var endAngle = Vector3d.XAxis.GetAngleTo(endVector, Vector3d.ZAxis);

            return new Arc(center, startVector.Length, startAngle, endAngle);
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 9

adrian_sieradzki
Contributor
Contributor

Thanks for pointing in the right direction. You are AutoCAD king

It ends up being

public static Arc CreateArcFromCenterAndTwoPoints(Point3d center, Point3d startPoint, Point3d endPoint)
        {
            var startVector = startPoint - center;
            var endVector = endPoint - center;
            var startAngle = Vector3d.XAxis.GetAngleTo(startVector, Vector3d.ZAxis);
            var endAngle = Vector3d.XAxis.GetAngleTo(endVector, Vector3d.ZAxis) - Math.PI;

            return new Arc(center, startVector.Length, startAngle, endAngle);
        }
0 Likes
Message 4 of 9

adrian_sieradzki
Contributor
Contributor

I still observe something weird with this. Looks like end point of my arc is moving around as I move the center, which I cannot expain since center is always the same distance from both points..

0 Likes
Message 5 of 9

_gile
Consultant
Consultant

You do not show how you use this method (i.e. how do you get the 3 points).

In this method the radius is the distance between the center and the start point. The end point is only used to get the end angle.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 6 of 9

adrian_sieradzki
Contributor
Contributor
CreateArcFromCenterAndTwoPoints(centerPoint, innerStartPoint, innerEndPoint )


I dont see how moving the centerPoint around should change where my arc ends, but this happens. 
0 Likes
Message 7 of 9

adrian_sieradzki
Contributor
Contributor
I am starting to notice there is something wrong with your solution, it always draws a semi-circle and doesnt react well to where the endpoint is, some kind of bug in AutoCAD? you should try it
0 Likes
Message 8 of 9

_gile
Consultant
Consultant

@adrian_sieradzki  a écrit :
I am starting to notice there is something wrong with your solution, it always draws a semi-circle

I do not think there's something wrong. An AutoCAD Arc entity is a "semi-circle", and this is what you create in the first code you posted.
An arc is defined by a center, a radius, a normal, a start angle and an end angle. If you specify the center and the start point, the end point have to at the same distance of the center than the start point. As I said upper, the supplied end point is only used to get the end angle direction.

 

If the distance from center to start point is different from the one to end point, may be you wnat to draw an elliptical arc. in this case center, start and end points are not sufficient data.

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 9 of 9

norman.yuan
Mentor
Mentor
Accepted solution
If you want the arc still passes through the 2 points (or ends at the 2 points) while moving the center point, the center point MUST BE MOVED to keep the same distance to the 2 points (i.e. a long a line that divides the arc's angle evenly). That is, you CANNOT freely move the center and have the 2 points always on the arc.

Norman Yuan

Drive CAD With Code

EESignature