To ICTARI: ICTARI 8 and 12. From Leslie W. Dewhurst. Calculating the coordinates of the point of tangency, the slope and the length of the tangent from a point to a curve, is quite easy when the curve is a circle, but the method serves as an introduction to the case when the curve is not a circle. In the case of a circle, suppose A is the point from which the tangent is drawn, B is the point of tangency, and C is the centre of the circle. It is assumed that the rectangular coordinates of points A and C are known, but not those of point B. The lines AC, BC and AB form a triangle. The length of AC can be calculated from the coordinates of A and C; the length BC is the radius of the circle. Since the curve is a circle, the angle ABC is a right-angle. Thus there is enough information about this triangle to calculate all of its angles and the length of all of its sides. From these can be calculated the coordinates of point B, and and the slope of the line AB with respect to the X- and Y-axes. However, even with circles, there are a few problems. Firstly there are two possible tangents to a circle from a point outside it, so you have to make certain that you get the one you want. Secondly beware of a user choosing a point inside the circle! In the case of circular arcs, the same method can be used, but the point of tangency may not be on a part of the circle which comprises the arc! Obviously this is an error condition. In the case of non-circular curves, an iterative process is unavoidable, so far as I am aware. One possible method starts by guessing a point B on the curve, and finding its coordinates. A good book on Differential Calculus will tell you how to find the slope and radius of curvature of the curve at this point. From these can be calculated the coordinates of the centre of curvature (analogous to the centre of a circle); call this point C, and call the point from which the desired tangent is to be drawn point A. As with a circle, lines AC, BC and AB form a triangle. Since we know the coordinates of A, B, and C, we can calculate the length of all three sides of the triangle, from which we can calculate the angle ABC. Only if this angle is a right-angle, is line AB a tangent to the curve. If it is sufficiently near to a right-angle, we have found a solution and can calculate the slope of the tangent with respect to the X- and Y-axes; otherwise we have to have another guess at the point of tangency, and go through the whole process again. However, if the curve is not well-behaved, there can be problems. In addition to those mentioned by John Phillips, there are curves which have such things as cusps and self-crossing loops (which may have more than one slope or radius of curvature at some point or points), curves with singularities, wavy lines (to which there may be more than one tangent from certain points) etc. There may be problems similar to those which occur with circles when point A is inside the circle, but now much more difficult to foresee. There is also a similar problem with arcs. I shudder to think of the complexities of dealing with a curve consisting of a sequence of Bezier or other curves, or even a single Bezier curve! (Incidentally, can anyone tell me the mathematical equation of a Bezier curve?). Supposing none of these problems apply to the curve we are dealing with (at least not within the region of interest), what iterative process shall we apply to make our successive guesses at the point of tangency converge to that point? Suppose we can choose two points such that the point we want must lie somewhere between them and that there can only be one such point (i.e. so that there is one and only one tangent in this interval). Let us call these two points the "bounds" for B. Then if the absolute value of the difference of the X- coordinates at the bounds is greater than that of the difference between the Y-coordinates at the bounds, then choose a new point with X-coordinate half way between the X-coordinates at the bounds; otherwise choose a point with Y-coordinate half way between the Y-coordinates at the bounds. Then calculate the other coordinate of the new point. The value of the angle ABC at the new point should be nearer a right-angle than at either of the bounds. If it is sufficiently near a right-angle, the problem has been solved; otherwise replace the appropriate bound by the new point, so that the angle at one of the bounds is still less than a right-angle and at the other bound is still greater than a right-angle, and repeat the whole process. This method of iteration is analogous to the well-known "Binary Search". There are other methods which may be quicker, but some cannot be guaranteed to converge under all circumstances, so if you choose another method, beware! There is now the problem of choosing suitable initial points for the bounds. They need not necessarily be close together, provided that they meet the above mentioned criteria. Whether it is possible to choose two such points, and if so, how one does it, depends on the nature of the curve. With real-time interactive graphics, it may be possible to ask the user to drag a temporary line from his chosen point so that it intersects the curve at two points along it. The equation for this line and that for the curve are a pair of simultaneous equations which need to be solved to find the points of intersection. But would these two points satisfy the required criteria? If all this sounds horribly complicated, that is because it is so! Some curves may be amenable (perhaps an ellipse), but one may well find that the process takes far too long for use in interactive graphics, which is probably the kind of application the enquirer had in mind. The traditional advice said to be given to young men thinking of getting married is "Don't"! In my view, this certainly applies to handling tangents from a point to anything but a circle!