The task is classical. Given 3 points A, B, C, find a circle (I, R) that IA = IB = IC = R.
It is my solution.
- First, calculate two midpoints of AB and AC.
- Second, create two medians of AB and AC according to found midpoints.
- Finally, find the intersection of the two lines.
The above solution forces me to declare a type named 'line' and write a boring code to find the intersection of two given lines.
I think that my solution is not the best. I want to find a better one.
Any suggestions would be appreciated.
The fastest way is to draw that circle.
Looking at name of this blog entry, my first thought was about fastest in terms of number of operations, not in terms of coding :)
Maybe I am wrong, but it seems that solving geometry without using structures is not the best idea. Yeah, I also like to write
pair<pair<int, int> ,pair<int, int> >
stuff, but it is a bad habit :)And what is so hard and boring in intersecting two lines? It is something like:
Or you may use
vector <Point>
instead, depending on which implementation of geometry is more comfortable for you and what is needed for given task (possible solution — one may return 2 points for same lines, 0 for parallel and 1 for intersecting).Of course, I also would be glad to see some even better solution :)
You can calculate coordinate of point I at complex plane. To make equations easier, put A in 0.
My teacher said, that calculating anything in geometry (or solving some equations) is a bad-style:( It's better to use functions like findPerpendicular and findIntersection.
Chto za dcp-autisti minusyat kazhdii comment v etom trede?
I faced this problem only once in my life — during last CH24 contest.
I have these two long lines from wikipedia in my solution:
What is d?
PS: found it.
Thank you. I tried to follow the instruction in Wikipedia.
I realized that moving A to (0, 0) makes the code shorter considerably.
If you want to calculate only R, then there is a compact formula: .
In your original approach, if you are intersecting medians, then you will get centroid, which is not the same, as center of circumscribed circle! Maybe you wanted to say perpendicular bisectors?)
My top priority is to find the center instead of the radius.
Thank you for indicating my mistake. Google translate was wrong.
Denote a = |BC|, b = |AC|, c = |AB|, .
Then .
This is true since ray AI divides BC side at a ratio of b·cos(β) to c·cos(γ).
To avoid precision problems, you can use the equation a2 + b2 - 2ab·cos(γ) = c2.
Thanks, I will try it.