# Fit circle through tangents

#1

Hello,

I know that if a user defines 3 points (say A, B, C), the command “fit circle” fits a circle going through all 3 points. Does anyone know how to fit an inscribed circle: tangent at A and C but not going through C?

#2

Good day Olivier!

tangent at A and C but not going through C?

Sorry but I don’t understand this definition.

Let’s say given are two straight lines that intersect at point B, then there exists an infinite number of circles that have both lines as tangents.

Regards

Herbie

#3

Hello Herbie. True. What I meant is tangent in A and C.

#4

I think your problem is not properly stated. This is not an inscribed circle but I think this is a circle defined by tangents passing from the same external point.
This might help:
https://www.mathopenref.com/consttangents.html

#5

Yes, this is what I am looking for. Your link shows how to build the tangents but what I am after is kind of the opposite: I have the 3 points and want to fit a circle through the tangents in A and C…

#6

If you are up for reading some Clojure code, then there is some code in this script that solves for an inscribed circle (among other functionality):

It is a messy prototype that was designed to fit a star shape to detected objects, which involves solving for circumscribing and inscribing circles.

#7

Many thanks Kephale. I will look it up. In the mean time, thanks to the hint from Gabriel I was able to get to the right direction by finding the intersection of the perpendicular lines to the tangents at A and B, to get the centre of the cercle I am interested in.

#8

hi, I’m newbie in code writing but have other idea to solve both problems with geometry, which could be easily adapted to macro

(I assume that coordinates for these points are known and may be used in macro or code)

Circle through A and B and C
center of circle (name it X) is equaly distant to all three points - so if you scan every pixel (coordinates of points) of your picture in search for points that lengths AX, BX and CX are the same you will get the center od circle
(but scanning pixels in pictures are quite slow, and in case of bigger analyses I would look for other faster solutions)

Circle through A and C not B
similarly, if AB and BC are tangents then the angle between AB-AX and BC- CX should be equal and equal to 90o.
So scanning of all points in picture and measuring angles should give you coordinates of X

of course such macros will give error when point X is outside of picture, which should be overcome in more complex and processive codes

I hope I have described it clearly

#9

Thanks m.lacki! This is in fact the approach that I am taking now.

#10

Hi @Olivier ,

I think the conditions of your problem are ill-defined: there will only exist a circle that is tangent to AB at A and to BC at C if and only if the lengths of AB and AC are equal. In other words, any three points A, B and C will not necesarily have a circle that meets the tangent conditions you are looking for.

What you can always find, instead, is one, and only one, circle that is both: 1) tangent to AB at A and 2) tangent to the line defined by BC. In this case, the second tangent point D will be equidistant to B as compared to A.

If this modified definition suits you, it is relatively straightforward to find the analytical solution of the problem and use it in a macro to construct the circle.

Best,
Nico

#11

Thanks @NicoDF. Just to be sure, don’t you mean that D should be equidistant to B and C, instead of A?

#12

Hi, @Olivier. Maybe my phrasing came out a little awkward. What I meant is that the segments AB and BD will have the same length. Here’s a graphical example, with the original segments AB and BC differing notably in length:

#13

C is not a on the tangent of the circle, so I think that is not what the OP is looking for.

#14

Hi @gabriel,

Was I was pointing out is that C cannot satisfy tangency* on the same circle as A does, unless AB and BC are of equal length. In other words, what the OP was trying to achieve was impossible in the general case.

Best,
Nico

* i.e. being a contact point and belonging to a segment starting at B that is perpendicular to a radius of the circle.

#15

Thanks @NicoDF and @gabriel. You are both right. One thing that I forgot to mention though (I actually didn’t think about it before @NicoDF’s comment: the ABC angle is always obtuse in my data. So, the way I solved this in the script so far was by getting the equations of the segments perpendicular to AB and BC in A and C, respectively, and by calculating the coordinates of the intersection point of these segments (ie the centre of the circle).
Edit #1: Actually, I just realised that the above does not work either if the segments have a different length…
Edit #2: I have solved (worked around) the problem by setting point B equidistant from A and C. In the analysis requirements, the position of A and C is fixed, as are the slopes of AB and BC, but I can place B arbitrarily.