6

Is there any way to make a circle knowing just two points on its diameter?

Here's the complete problem I'm trying to solve: there is a segment MN (but points M and N are calculated as an intersection of other lines so I don't know their coordinates) and I want to construct the Thales circle (to find some right angles).

I've found some code for drawing part of the circumference, so I've modified it to

\coordinate (S_MN) at ($(M)!.5!(N)$);
\draw[red] (S_MN) let \p1 = ($(N)-(S_MN)$) in  ++({veclen(\x1,\y1)},0) arc (0:360:({veclen(\x1,\y1)}););

(I'm using the calc library), but the compilation runs into errors.

!package Tikz error: + or - expected. See the tikz documentation...

(Yeah, I admit that I dont know much about the TikZ construction I've used, unfortunately.)

I've also tried to compute the radius by $(M) - (N)$ (which I've seen somewhere), but without success.

---- edit ---

(...)

BUT I think I've found the problem - I've tried to remove packages form head of the doc and check if there is a problem

-> once \usepackage[czech]{babel} package is %commented, everything runs normally

\documentclass[12pt,a4paper]{report}

\usepackage[czech]{babel}

\usepackage[cp1250]{inputenc}
\usepackage{graphicx}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{epstopdf}

\usepackage{tikz}
\usetikzlibrary{calc}
\pgfmathsetseed{\pdfuniformdeviate 10000000}

\begin{document}
\begin{tikzpicture}
\draw[style=help lines] (0,0) grid[step=1cm] (3,3);
\coordinate (M) at (2,1);
\foreach \x in {1,...,5}{
\node (N) at ({random(0,3)},{random(0,3)}) {here};
\coordinate (S_MN) at ($(M)!.5!(N)$);
\draw[red] (S_MN)
 let \p1 = ($(N)-(M)$),\n1 = {0.5*veclen(\x1,\y1)} in  ++(\n1,0) arc (0:360:\n1);
}
\end{tikzpicture}  
\end{document}

edit2: I've used percusse's construction with cjorssen's "update" and it worked really fine. But now I've realized one problem - how coud I find that intersection with other line I've been talking about in first post? (summary: I've circle made by your way. There is also line, say, AB, which intersects the circle in two points. How could I detect them to draw that right angle for which I'm using Thales circle? Thanks in advance

3 Answers 3

7

With tkz-euclide

\documentclass{scrartcl}
\usepackage{tkz-euclide} 
\usetkzobj{all} 
\begin{document}

\begin{tikzpicture} 
  \tkzDefPoint(2,1){A}
  \tkzDefPoint(7,3){B} 
  \tkzDrawCircle[diameter,fill=yellow!50](A,B) 
  \tkzDefMidPoint(A,B) \tkzGetPoint{O} 
  \tkzCalcLength[cm](O,B) \tkzGetLength{rAB}
  \tkzGetRandPointOn[circle = center O radius \rAB cm]{C}
  \tkzDrawPolygon[fill=red!40](A,B,C) 
  \tkzLabelPoints(A,B,C,O)
  \tkzMarkRightAngle(A,C,B)
\end{tikzpicture}

\end{document}  

enter image description here

2
  • If you want to use only tikz, you need to determine the middle of AB, and then the radius with veclen. You can use Percusse's answer. Nov 9, 2012 at 12:23
  • thanks but I'd like to use just Calc solution if possible. But there are problems (see lower) so I'l be possibly forced to use tkz-euclide
    – Doxxik
    Nov 11, 2012 at 15:28
4

I've replaced one of the points with a random node. You can use the \n registers to do a calculation and use it on the path and also you can use a circle instead of the arc but I've kept the arc so that you can distinguish your own code from mine :)

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calc}
\pgfmathsetseed{\pdfuniformdeviate 10000000}

\begin{document}

\begin{tikzpicture}
\draw[style=help lines] (0,0) grid[step=1cm] (3,3);
\coordinate (M) at (2,1);
\foreach \x in {1,...,5}{
\node (N) at ({random(0,3)},{random(0,3)}) {here};
\coordinate (S_MN) at ($(M)!.5!(N)$);
\draw[red] (S_MN) let \p1 = ($(N)-(M)$),\n1 = {0.5*veclen(\x1,\y1)} in  ++(\n1,0) arc (0:360:\n1);
}
\end{tikzpicture}    
\end{document}

enter image description here

M is on the coord (2,1) but the N shows up as here text at each iteration.

6
  • Thanks but unforutnatelly this leads to same rror (mentioned in the first post).. Respectively, it works in blanc doc but when I add it to my original work it goes to that error. (I'm adding it as new figure to avoid conflicts with other stuf). I'm using just these packages: \usepackage[cp1250]{inputenc} \usepackage{graphicx} \usepackage{amsthm} \usepackage{amsmath} \usepackage{epstopdf} and language package (with babel) and of course Tikz and Calc Any ideas why is it wrong?
    – Doxxik
    Nov 11, 2012 at 15:24
  • @Doxxik Without a minimal working example (MWE) I can't see why you get an error.
    – percusse
    Nov 11, 2012 at 18:14
  • Yeah, i'm sorry. (this comment is too short so I¨ll add it as an answer)
    – Doxxik
    Nov 11, 2012 at 19:53
  • @Doxxik Answers are for, well, answers to the question. You should rather edit your question to include the code. Nov 11, 2012 at 20:04
  • Now I've realized one problem - how coud I find that intersection with other line I've been talking about in first post? (summary: I've circle made by your way. There is also line, say, AB, which intersects the circle in two points. How could I detect them to draw that right angle for which I'm using Thales circle? Thanks in advance
    – Doxxik
    Nov 11, 2012 at 20:57
4

When babel is used with the czech language, it makes - active. This makes tikz calc library unable to parse correctly the coordinates. That is why you get the error message

!package Tikz error: + or - expected. See the tikz documentation...

because tikz find a - with catcode 13 (\active) while it is looking for a - with catcode 12.

A workaround is to add \shorthandoff{-} before \begin{tikzpicture} and \shorthandon{-} after \end{tikzpicture}. Note however that you won't be able to use the babel feature related to - inside the tikzpicture.

1
  • thanks, now it's working! %also thanks to percusse & Alain Matthes!
    – Doxxik
    Nov 11, 2012 at 20:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .