# Definition of an exercise ruler & compass.
# syntax of the file.
# points:  each line defines a point.  x,y
# lines:   each line defines two points on a line.   x1,y1,x2,y2,type
#          type: 1 (segment), 2 (line), 3 (semiline direct), 4 (semiline inverse)
#	   type is facultative, defaulting to 1.
# circles: each line defines a circle. x,y,r,n
#	   where (x,y) is the center, r=radius,
#          n is the number of point for the center (if n>0).
# goal: each line defines an object. First item is the type of the object
# (point,line or circle), the rest are parameters (same as above).
# goal_text: text explaining the goal. (language-dependent)

title=Ortocentro de un tringulo

a=!random 0,2*pi
a1=!random pi*0.67,pi*1.2
a2=!random $a1+pi/4,(7/4)*pi
b1=$[$a+$a1]
b2=$[$a+$a2]
r=3
x1=$[$r*cos($a)]
y1=$[$r*sin($a)]
x2=$[$r*cos($b1)]
y2=$[$r*sin($b1)]
x3=$[$r*cos($b2)]
y3=$[$r*sin($b2)]
points=$x1,$y1\
$x2,$y2\
$x3,$y3
lines=$x1,$y1,$x2,$y2,1\
$x2,$y2,$x3,$y3,1\
$x3,$y3,$x1,$y1,1

#compute the orthocenter
det=(($x2-$x3)*($y1-$y3)-($x1-$x3)*($y2-$y3))
c1=($x1*($x2-$x3)+$y1*($y2-$y3))
c2=($x2*($x1-$x3)+$y2*($y1-$y3))
x4=((($c1)*($y1-$y3)-($c2)*($y2-$y3))/$det)
y4=((($x2-$x3)*($c2)-($x1-$x3)*($c1))/$det)

goal=point,$x4,$y4
goal_text=encuentra el ortocentro del tringulo 1 2 3
hint=El ortocentro de un tringulo es el punto comn de las tres alturas. \
Como las tres alturas tienen un punto comn, solo tienes que dibujar dos\
de ellas, y entonces marcas la interseccin.
solution=circle,1,3#We start by constructing the altitude of side 1-2.\
circle,2,3\
point,circle,1,circle,2\
line,3,4#Line 4 is the altitude of side 1-2.\
hide,circle,1\
hide,circle,2\
hide,point,4#Now the altitude of side 2-3.\
circle,2,1\
circle,3,1\
point,circle,3,circle,4\
line,1,5#Line 5 is the altitude of side 2-3. The goal can already be reached by marking the intersection of the two altitudes, but we are going to construct the third altitude too.\
hide,circle,3\
hide,circle,4\
hide,point,5\
circle,1,2\
circle,3,2\
point,circle,5,circle,6\
line,2,6#Line 6 is the altitude of side 1-3. The intersection of the three altitudes is the orthocenter.\
hide,circle,5\
hide,circle,6\
hide,point,6\
point,line,4,line,5

