Circle tangent to two lines and passing through a point (AutoCAD tan tan tan)

hello,

i am trying find a way to create a circle which is tangent to two faces and passing through a point in dynamo. This is very much easy using the autocad command circle by tan tan tan but not finding a way to do it in dynamo. can anyone please help me with this.

Thanks,
Shahid Shaikh

Hi all,

Found logic for above task, i am creating offset to the required curve with a certain distance and finding distance between intersection point of offsets and passing through point.

Now, For circle be tangent to two object and passing through a point, the distance between intersection point and offset distance should be equal. tried to find this distance/Point by running a loop and updating the offset distance but loop is taking too much time for run and not getting any result. Can anyone tell me what mistake i am doing or how can i code this looping to be faster in Python.

See if that helps,

Tan.dyn (18.8 KB)

@_Vijay thanks for the reply …sorry this wont help as i can not fix the tangent point and draw a circle from 3 point. The goal is to find the tangent point and center of this circle with such a radius that it will be tangent as well as passing through a point.

//Increase num for higher precision
//Will fail if too low and take too long if too high
num = 15;

//Centers of circles that are tangential and equidistant to the input Curves
pt1 = c1.PointAtParameter(0..1..#num);
pt2 = c2.PointAtParameter(0..1..#num);
pl1 = Plane.ByThreePoints(c1.CenterPoint,c1.CenterPoint.Translate(0,0,1),pt1);
vc1 = Vector.ByTwoPoints(c2.CenterPoint,pt2);
pt3 = Point.PruneDuplicates(List.Flatten(pt2.Project(pl1<1>,vc1<2>),-1),0.01);
ds1 = Math.Round(pt3<1>.DistanceTo(pt1<2>),1);
ds2 = Math.Round(pt3<1>.DistanceTo(pt2<2>),1);
pt4 = List.FilterByBoolMask(pt3,List.AllFalse((ds1==ds2)<1>))["out"];

//Centers that are equidistant to the input Curves and Point
ds3 = Math.Round(pt4<1>.DistanceTo(c1<2>),1);
ds4 = Math.Round(pt4<1>.DistanceTo(c2<2>),1);
ds5 = Math.Round(pt4<1>.DistanceTo(p1<2>),1);
pt5 = List.FilterByBoolMask(pt4,ds3==ds5 && ds4==ds5)["in"];
ds6 = pt5.DistanceTo(p1);
cr1 = Circle.ByCenterPointRadius(pt5,ds6);

tanPntArc.dyn (13.0 KB)

2 Likes

Thanks alot for the reply Vikram…you are the saviour.

Still trying to understand the code and error i am getting. Sure it will take time to understand totally and then can ask the right question. Meantime for your information, i am getting bellow warning message.

Warning: GeometryColor.ByGeometryColor operation failed.
Value cannot be null.
Parameter name: geometry
Internal error, please report: Dereferencing a non-pointer.
Internal error, please report: Dereferencing a non-pointer.
Cannot index into a null list, dictionary or string.
Null value cannot be cast to Double
Null value cannot be cast to Double
Null value cannot be cast to Double
Cannot index into a null list, dictionary or string.
Null value cannot be cast to Double
Null value cannot be cast to Double
Point.PruneDuplicates operation failed.
Object reference not set to an instance of an object.
Vector.ByTwoPoints operation failed.
Object reference not set to an instance of an object.
Plane.ByThreePoints operation failed.
Object reference not set to an instance of an object.

if needed can share autocad and dyn file also.

1 Like

Seems like there is some conflict in your Dynamo.
You shouldn’t have Circle as an input port in your code block.
Try replacing the line (before Geometry Color) with

cr1 = Autodesk.DesignScript.Geometry.Circle.ByCenterPointRadius(pt5,ds6);

Otherwise try doing this …

Usually helps understand the context and issue better when you do

tan_test.dwg (2.2 MB) Thanks for the quick reply …

tried both the methods but still getting bellow errors.

Apologies i should have shared the dwg and dyn. tan_test_1.dyn (44.4 KB)

Sorry, wasn’t able to import your DWG into Revit to test. (Apparently the objects are far away from the origin)

However from the error message I gather that you aren’t feeding in arcs, but polylines. That won’t work.
Please ensure that you feed two arcs into c1 and c2 respectively.
If required, trace over your geometry to create two clean arcs.

Hi @Vikram_Subbaiah, Thanks for letting me know the mistake.

Sorry but i can not create the arc as i am trying to make it generalized script and it will not have always curve-Curve-Point rather than it will be Curve - line/Curve - Point combination so thats why i was using polycurve.

To overcome this difficulty what logic i was following is create offset of the required geometry by say #num (D) then find the distance between intersection point (A) and given point say P1. Run a loop till offset distance and P1 to A distance is same. once we got this distance then intersection point will be center of circle and D will be the radius, with this it will be generalized for curve or line.

Apologies if i was not clear at the beginning. Anyway thanks alot for the code and i am trying to understand it fully to be able to customize as per need. I now know that loops can run faster if coded rather than using the default loopWhile.

Could you consider creating Arcs by picking the start point, mid point and end point of the curves (for lines you could offset the mid point marginally) and feed those as inputs.
The center of the arcs are important to the workflow in the definition I’ve provided

Ok will taste it for arc as you suggested and let you know if it works. Thanks alot for all the help and for the code too.

1 Like

Here is a version that takes in lines and polycurves (provided they resemble arcs)

tanPntArc.dyn (14.5 KB)

//Increase num for higher precision
//Will fail if too low and take too long if too high
num = 15;

// Approximates (provided they are similar to arc) Polycurves Or Lines with Arcs
c1 = Autodesk.DesignScript.Geometry.Arc.ByThreePoints(a1.StartPoint,(a1.PointAtParameter(0.5)).Translate(Vector.ByTwoPoints(a1.PointAtParameter(0.5),p1),0.0001),a1.EndPoint);
c2 = Autodesk.DesignScript.Geometry.Arc.ByThreePoints(a2.StartPoint,(a2.PointAtParameter(0.5)).Translate(Vector.ByTwoPoints(a2.PointAtParameter(0.5),p1),0.0001),a2.EndPoint);

//Centers of circles that are tangential and equidistant to the input Curves
pt1 = c1.PointAtParameter(0..1..#num);
pt2 = c2.PointAtParameter(0..1..#num);
pl1 = Plane.ByThreePoints(c1.CenterPoint,c1.CenterPoint.Translate(0,0,1),pt1);
vc1 = Vector.ByTwoPoints(c2.CenterPoint,pt2);
pt3 = Point.PruneDuplicates(List.Flatten(pt2.Project(pl1<1>,vc1<2>),-1),0.01);
ds1 = Math.Round(pt3<1>.DistanceTo(pt1<2>),1);
ds2 = Math.Round(pt3<1>.DistanceTo(pt2<2>),1);
pt4 = List.FilterByBoolMask(pt3,List.AllFalse((ds1==ds2)<1>))["out"];

//Centers that are equidistant to the input Curves and Point
ds3 = Math.Round(pt4<1>.DistanceTo(c1<2>),1);
ds4 = Math.Round(pt4<1>.DistanceTo(c2<2>),1);
ds5 = Math.Round(pt4<1>.DistanceTo(p1<2>),1);
pt5 = List.FilterByBoolMask(pt4,ds3==ds5 && ds4==ds5)["in"];
ds6 = pt5.DistanceTo(p1);
cr1 = Autodesk.DesignScript.Geometry.Circle.ByCenterPointRadius(pt5,ds6);

//Geometry Color
[GeometryColor.ByGeometryColor(p1,Color.ByARGB(255,255,0,0)),
GeometryColor.ByGeometryColor(c1,Color.ByARGB(255,0,255,0)),
GeometryColor.ByGeometryColor(c2,Color.ByARGB(255,0,0,255)),
GeometryColor.ByGeometryColor(cr1[0],Color.ByARGB(255,255,0,255))];

Thanks alot @Vikram_Subbaiah. I know this must be really frustrating, but i am getting multiple input and not the same as seen in your image.

As suggested in a reply above you could prefix Circle and Arc with Autodesk.DesignScript.Geometry.
The code in the previous post has been updated to reflect this change.
Please see if the updated version works for you.

Thanks alot Vikram for update …

Sorry its still not working.

Seems like the code is working, but it isn’t able to find a circle that passes through the specified point.
Try moving the point a little. (The reconstructed arcs might not exactly match your original curves)
Sorry, can’t think of anything else right now.

1 Like