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

Drawing a tangent to circle from a point outside the circle

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
amit_cad
4410 Views, 7 Replies

Drawing a tangent to circle from a point outside the circle

Hi All,

 

I want to draw a tangent to a circle from a point outside the cirle using vb.net.

I have following data....

Radius of circle

Coordinate of center of circle

coordinate of external point from where tangent has to draw.

 

Can u help me..........?

 

7 REPLIES 7
Message 2 of 8
_gile
in reply to: amit_cad

Hi,

 

The tangent points from a point to a circle are the intersection points betwenn the circle and another one wich center is the middle of the line between the circle center and the point and which radius is the half of this line length (see picture).

Programatically, create a temporary circle as discribe, get the intersection points, delete the circle...

Appologies for my poor English.181iA264E068CCD127F7



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 8
_gile
in reply to: _gile

Here's a little 'quick and dirty' C# sample

 

 

// Creates two lines from a point tangent to a circle
private void TangentsToCircle(ObjectId id, Point3d pt)
{
    Document doc = acadApp.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        BlockTableRecord btr = 
            tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
        Circle c = tr.GetObject(id, OpenMode.ForRead) as Circle;
        if (c == null)
        {
            ed.WriteMessage("\nIncorrect ObjectId");
            return;
        }
        if (pt.DistanceTo(c.Center) <= c.Radius)
        {
            ed.WriteMessage("\nUnavailable tangents");
            return;
        }
        Vector3d vec = pt.GetVectorTo(c.Center) / 2.0;
        double rad = vec.Length;
        CircularArc3d c3d = new CircularArc3d(c.Center, c.Normal, c.Radius);
        CircularArc3d tmp = new CircularArc3d(pt + vec, c.Normal, rad);
        Point3d[] inters = c3d.IntersectWith(tmp);
        foreach (Point3d p in inters)
        {
            Line l = new Line(pt, p);
            btr.AppendEntity(l);
            tr.AddNewlyCreatedDBObject(l, true);
        }
        tr.Commit();
    }
}

 

 

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 8
amit_cad
in reply to: _gile

Hi

this is helpful

 

can u explain the syntax of .IntersectWith

In the Syntax of intersectWith there r more parameter , but u have use only one?

 

Message 5 of 8
_gile
in reply to: amit_cad

Hi,

 

The DatabaseServices.Entity.IntersectWith() method requires more than one parameter.

I'm using the Geometry.CircularArc3d.IntersectWith() one.

The CircularArc3d as others Geometry namespace classes define 'abstract' geometrical objects which aren't database entities.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 6 of 8
sapch
in reply to: _gile

Can you use "GetTangent" to do this? thank you

public Line3d GetTangent(Point3d pointValue, Tolerance tolerance);

 

Message 7 of 8
Washingtonn
in reply to: amit_cad

A tangent is always perpendicular to the radius of a circle.  And given that for every external point to a curcle, there are two tangent lines, the tangents will not be located on a radius that passes through the center of the circle.

 

The way to find the tangents is to use the pythagorean theorem.

The hypotenuse of the right triangle is the distance between the external point and the circle's center point.

The short leg of the triangle is the radius of the circle.

The remaining leg (b) is then easily found.  It is the square root  result of the hypotenuse square minus the radius squared. A circle with this radius "b" having its center located at the external point will pass through the tangent point on the original circle.   

 

Snag_d790893.png

Message 8 of 8
Washingtonn
in reply to: Washingtonn

my bad....gile is correct when taking the centerpoint of the circle at the midpoint of the line between original centerpoint and external point.  I should have read things more closely - sorry.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost