.NET

Reply
Active Member
amit_cad
Posts: 7
Registered: ‎08-06-2010
Message 1 of 5 (2,052 Views)
Accepted Solution

Drawing a tangent to circle from a point outside the circle

2052 Views, 4 Replies
08-06-2010 04:26 AM

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..........?

 

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

 

 

 

*Expert Elite*
_gile
Posts: 2,106
Registered: ‎04-29-2006
Message 2 of 5 (2,048 Views)

Re: Drawing a tangent to circle from a point outside the circle

08-06-2010 05:49 AM 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
*Expert Elite*
_gile
Posts: 2,106
Registered: ‎04-29-2006
Message 3 of 5 (2,025 Views)

Re: Drawing a tangent to circle from a point outside the circle

08-07-2010 02:14 AM 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
Active Member
amit_cad
Posts: 7
Registered: ‎08-06-2010
Message 4 of 5 (2,005 Views)

Re: Drawing a tangent to circle from a point outside the circle

08-08-2010 12:01 PM 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?

 

*Expert Elite*
_gile
Posts: 2,106
Registered: ‎04-29-2006
Message 5 of 5 (1,993 Views)

Re: Drawing a tangent to circle from a point outside the circle

08-08-2010 09:56 PM 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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.