# Tangent Lines strange behaviour

It’s ok if the component doesn’t run if the point is not in the plane of the circle, but it only happens if it’s in a positive direction from the normal direction of the plane, in a negative direction it does something strange.
``````private void RunScript(Circle circle, Point3d point, ref object A, ref object B)
{

Plane plane = circle.Plane;

point.Transform(Transform.PlanarProjection(plane));

Point3d pt = Point3d.Unset;
plane.RemapToPlaneSpace(point, out pt);
double dx = pt.X;
double dy = pt.Y;
double d = Math.Sqrt(dx * dx + dy * dy);
double a = Math.Asin(radius / d);
double b = Math.Atan2(dy, dx);
double ta = b + a;
double tb = b - a;

A = new Line(pa, point);
B = new Line(pb, point);

}``````

Could be related to tolerance:

Recently there was a post:

I don’t think so. It’s not a tolerance-dependent algorithm. It has an exact solution. And it’s also not related to whether it changes its behavior above or below the plane. It looks like a bug, or at least a partially handled invalid situation.

the point which touches the circle is dependent on tolerance, isn’t it?

No, it’s not done by making intersections, but by using trigonometry.

I believe all modeling software is highly dependent on the tolerance accepted in the approximation algorithms it has. Trigonometry or not, the values are approximated to a certain floating number. truncated at some point leading to errors. A slight move of the point on a circle (depending on rounding) could lead to big angle error. But I may as well be wrong.

As I understand it, the problems relating to tolerances are the problems relating to limits, mathematically speaking. Computationally you can’t approximate a solution infinitesimally, so you need a tolerance to set a threshold that makes the limit reasonable. Intersections need this to set a resolution or accuracy for it to be profitable to use them, they are numerical solutions. Mathematical operations like trigonometry, do not need this they are fast enough and are considered analytical solutions. Using System.double you have ~15-17 digits of accuracy, if you used System.decimal you would have 28-29 digits. If they run fast with such precision, you don’t need to catch your result before it temporarily explodes.

I don’t know what is the code behind that component. If you project the point on the plane of the circle before hooking it to the tangent line component it works fine.

There’s definitely sometging wrong there, though.

PS:
Trigonometry is also prone to errors due to precision:
http://www.extremeoptimization.com/Blog/index.php/2011/02/accurate-trigonometric-functions-for-large-arguments/

Well, good to remember that, but a difference in the eighth decimal place wasn’t going to change anything here.

Seems like it is only evaluating the distance from the center and the radius of the circle.

The out-of-plane point is at the same distance than the intersection of the found tangents…