Page 1 of 1

The Centers of a Triangle

Posted: Sun Jun 10, 2007 2:31 pm
by Francesco
Hi all,
I am back with another toy program.
I was improving the "Koch's snowflake" program, to show something very nice - building the snowflake as a bunch of triangles and then rotating them a bit results in a very nice image - but then I asked myself: how can I compute the center of an arbitrary triangle? Searching the web I have found Jim Loy's geometry pages, which inspired me the following program:
http://www.zomis.net/rnd/download.php?id=660
Developing this program has been very instructive and very fun - I recall Holger's words of some months ago ;)

Again, for what is worth, enjoy this program.

Posted: Sun Jun 10, 2007 5:32 pm
by Zomis
Wow, incredible program, Francesco!
At first I thought that the triangle wasn't moveable, but after a while I found out that it actually was moveable :D

I gotta say that I have no clue about how to calculate some of those things, and honestly I don't know what to use all those things for. Do you have a link to those geometry pages? They sound interesting :)

Posted: Sun Jun 10, 2007 11:34 pm
by Francesco
I am glad you liked it, Zomis.

Those pages can be found at www.jimloy.com , just as stated in the program info (I should have publicized better the "TAB - Program information" button ;)).

Well, in the way they are shown in that program, they are just a delight for the eye - for those eyes who like maths and alike - but just like any math, the nicest part is that all of them have some useful aspect. For example, the Fermat's point is the point where the sum of distances towards the three corners is minimal.

In practice, it represents the best point to connect three towns (or three houses, as well) using the minimum amount of material - electricity wires, telephony cables, water pipes and so forth.

If someone plans to use that information, I'll say here that the point can be found building two equilaterals on two sides of the triangle (they have to be built towards the outside) - the Fermat's point is the intersection between the two lines connecting the fartest corners of these equilaterals to the relative corners on the opposite side of the given triangle - just like shown in my program. It is not necessary to calculate the third equilateral - the resulting line will pass through the Fermat's point in any case.

I'll add also that if the given triangle is not acute - that is, if there is an obtuse angle at one corner - then the best point is not the Fermat's point, but the point on the corner with the obtuse angle. [edit: wrong, the point is valid even for an obtuse triangle, as long as the obtuse angle is not wider than 120°, see Jannik's note below - at least it wasn't my fault ;)]

To make the program a bit more useful, I could allow the user to specify and see the coordinates of the three points of the triangle, as well as the coordinates and the sizes of the various entities shown in the program, but once again, the biggest problem is realizing such things with C++ and put them on the screen in a good way - now I can perfectly understand the hassle when it comes to widgets, coordinates and so on... it isn't that hard, but it's extremely boring...

Posted: Mon Jun 11, 2007 3:31 am
by Jannik
Nice work, Francesco!
Especially the real-time movability is funny!

Jim Loy's Mathematics Page is really interesting ... I wished I had found this fascination of maths in my school time ... :wink:
For example, the Fermat's point is the point where the sum of distances towards the three corners is minimal.
If one angle of the triangle is 120° or bigger, the Fermat's point will be outside the triangle and the point, where the sum of distances towards the three corners is minimal, will be the corner of the triangle with the big angle.

Posted: Mon Jun 11, 2007 2:30 pm
by Francesco
Thank you Jannik, I am happy you liked my program.

About the 120° thing, you're right - I have checked it measuring the sum in my program.

In fact, an angle should be considered obtuse if it's wider than 90°, so my definition is not correct. Well, it is not my definition, I have just reported the words of Wolfram's math pages... now the problem is whether the words "obtuse" and "acute" mean something different when applied to a triangle instead that to a single angle... I'll have to check it out - eventually we'll have to point this out to Wolfram's website ;)

[edit: definitely this is the case, I was wrong just like Wolfram's website, I am about to send an e-mail to point this out]

Posted: Mon Jun 11, 2007 10:35 pm
by Francesco
Well, thinking better... I have my part of fault. The Wolfram's page about the Fermat's point states
In a given acute triangle ABC, the first Fermat point X [...] is the point X which minimizes the sum of distances from A, B, and C
It doesn't state that the point is not valid for an obtuse triangle.
I have wrongly deduced that - but that page is incomplete, as a minimum ;)

Could the Wolfram website's team forgive me - that site is great!

Posted: Tue Jun 12, 2007 1:37 am
by Jannik
Wolfram's page is incomplete about triangles with an angle of 90° <= alpha < 120°.
But Jim Loy's page completely misses the angle issue, so if you still want to write an email, Francesco ... :wink:

Currently, I wonder, if a triangle would be completely defined by only Circum- and Orthocenter. These would easily lead to the Centroid and Nine Points Center. And there are so many relations ... and just 6 unkown variables (ax, ay, bx, by, cx, cy) ... in other words, are there two different triangles with the same (directed) Euler's line? :roll:

Posted: Tue Jun 12, 2007 4:36 am
by Jannik
I just discovered by accident, that you can even change the colours of the dots, lines and circles ... :shock:
To make the program a bit more useful, I could allow the user to specify and see the coordinates of the three points of the triangle, as well as the coordinates and the sizes of the various entities shown in the program
That would make the program really perfect! :wink:

I did some calculations to answer my question in my last post. Now I have 4 equations and 4 unknown variables. I hope these equations are independent, then it should be solvable ...

known:
Circumcenter D=(DX/DY)=(D1/D2)
Orthocenter O=(OX/OY)=(O1/O2)

unkown:
2 points of triangle: B1, B2, C1, C2
(A1 and A2 are then easy to compute)

4 equations:
O1=B1+((2*D2+O2-B2-C2)-C2)*((C2-B2)*(B2-(2*D2+O2-B2-C2))-(B1-(2*D1+O1-B1-C1))*(B1-C1))/(((2*D2+O2-B2-C2)-C2)*(B1-C1)-(C1-(2*D1+O1-B1-C1))*(C2-B2))

O2=B2+(C1-(2*D1+O1-B1-C1))*((C2-B2)*(B2-(2*D2+O2-B2-C2))-(B1-(2*D1+O1-B1-C1))*(B1-C1))/(((2*D2+O2-B2-C2)-C2)*(B1-C1)-(C1-(2*D1+O1-B1-C1))*(C2-B2))

D1=((2*D1+O1-B1-C1)+C1)/2+(((2*D2+O2-B2-C2)-C2)*(((2*D2+O2-B2-C2)-B2)*(C2-B2)-((2*D1+O1-B1-C1)-B1)*(B1-C1)))/(2*((B1-C1)*((2*D2+O2-B2-C2)-C2)-(C1-(2*D1+O1-B1-C1))*(C2-B2)))

D2=((2*D2+O2-B2-C2)+C2)/2+((C1-(2*D1+O1-B1-C1))*(((2*D2+O2-B2-C2)-B2)*(C2-B2)-((2*D1+O1-B1-C1)-B1)*(B1-C1)))/(2*((B1-C1)*((2*D2+O2-B2-C2)-C2)-(C1-(2*D1+O1-B1-C1))*(C2-B2)))

Is anybody here who wants to solve them to B1, B2, C1 and C2? I'm a little bit lazy right now ... :lol:

Posted: Tue Jun 12, 2007 11:23 am
by Francesco
Yes, that page on Jim Loy's website misses completely that issue - but Jim's website has also lower claims ;)

About your equations... I must admit that I am not so used to resolving such things, I prefer to look up the answers from the web :roll:

I am adding the coords to the program.

Posted: Mon Jun 18, 2007 2:56 am
by Jannik
Ok, I have to surrender ... :wink:
My equations aren't linear, so it's really hard to solve them. Maybe with numerical analysis, but these are often erroneous or misleading ...

I transformed the first equation to a quadratic equation of B1: :D
0=B1^2*(-2*D2-O2+C2+2*B2)+B1*(-2*D2*C1-O2*C1+B2*C1+2*C2*C1-2*C1*C2+2*D1*C2+O1*C2+2*C1*B2-2*D1*B2-O1*B2-2*D2*O1-O1*O2+O1*B2+2*O1*C2+C2*O1-O1*B2+4*D1*D2+2*D2*O1+2*D2*C1+2*D1*O2+O1*O2+O2*C1-2*D1*B2-O1*B2-C1*B2-4*D1*C2-2*O1*C2-2*C1*C2)-O1*(-2*D2*C1-O2*C1+B2*C1+2*C2*C1-2*C1*C2+2*D1*C2+O1*C2+2*C1*B2-2*D1*B2-O1*B2)+(2*D2+O2-B2-2*C2)*(2*B2*C2-2*D2*C2-O2*C2+C2^2-2*B2^2+2*D2*B2+O2*B2-C2*B2-2*D1*C1-O1*C1+C1^2)

You could put these two possible solutions into equations 2-4, so you would have only 3 equations with 3 unkown variables ... but these equations would be really cruel ... :twisted:

By the way, here are my formulas for Centroid T, Orthocenter O, Circumcenter D I used above:
T1=(A1+B1+C1)/3
T2=(A2+B2+C2)/3
O1=B1+(A2-C2)*((C2-B2)*(B2-A2)-(B1-A1)*(B1-C1))/((A2-C2)*(B1-C1)-(C1-A1)*(C2-B2))
O2=B2+(C1-A1)*((C2-B2)*(B2-A2)-(B1-A1)*(B1-C1))/((A2-C2)*(B1-C1)-(C1-A1)*(C2-B2))
D1=(A1+C1)/2+((A2-C2)*((A2-B2)*(C2-B2)-(A1-B1)*(B1-C1)))/(2*((B1-C1)*(A2-C2)-(C1-A1)*(C2-B2)))
D2=(A2+C2)/2+((C1-A1)*((A2-B2)*(C2-B2)-(A1-B1)*(B1-C1)))/(2*((B1-C1)*(A2-C2)-(C1-A1)*(C2-B2)))