1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
/* -*-ePiX-*- */
#include "epix.h"
using namespace ePiX;
const P pt1(2,-1);
const P pt2(1,2);
const P pt3(-2,0);
void altitude_color()
{
blue(1.4);
}
#ifdef BISECTORS
void bisector_color()
{
green(1.4);
}
#endif
// project arg to line through tail, head
P drop_perp(const P& arg, const P& tail, const P& head)
{
return arg - ((arg - tail)%(head - tail)); // % = orthogonalization
}
#ifdef BISECTORS
P bisector(const P& arg, const P& tail, const P& head)
{
P dir_tl(tail - arg);
dir_tl *= 1.0/norm(dir_tl);
P dir_hd(head - arg);
dir_hd *= 1.0/norm(dir_hd);
Segment bisect(arg, arg + 0.5*(dir_tl + dir_hd));
return Segment(tail, head)*bisect;
}
#endif
void rangle(const P& arg, const P& tail, const P& head)
{
const P dir(head - tail);
const P loc(arg - ((arg - tail)%dir));
right_angle(loc, dir, J(dir));
}
const P q1(drop_perp(pt1, pt2, pt3));
const P q2(drop_perp(pt2, pt3, pt1));
const P q3(drop_perp(pt3, pt1, pt2));
#ifdef BISECTORS
const P r1(bisector(pt1, pt2, pt3));
const P r2(bisector(pt2, pt3, pt1));
const P r3(bisector(pt3, pt1, pt2));
#endif
int main()
{
picture(P(-3,-3), P(3,3), "4x4in");
begin();
set_crop();
// sides
Segment side1(pt2, pt3);
Segment side2(pt3, pt1);
Segment side3(pt1, pt2);
// medians
Segment med1(pt1, side1.midpoint());
Segment med2(pt2, side2.midpoint());
Segment med3(pt3, side3.midpoint());
// altitudes
Segment alt1(pt1, q1);
Segment alt2(pt2, q2);
Segment alt3(pt3, q3);
#ifdef BISECTORS
// bisectors
Segment bis1(pt1, r1);
Segment bis2(pt2, r2);
Segment bis3(pt3, r3);
#endif
med1.draw();
med2.draw();
med3.draw();
bold();
side1.draw();
side2.draw();
side3.draw();
plain();
altitude_color();
alt1.draw();
alt2.draw();
alt3.draw();
rangle(q1, pt2, pt3);
rangle(q2, pt3, pt1);
rangle(q3, pt1, pt2);
circle(q1, q2, q3);
label(q1, P(-2,4), "$a_1$", t);
label(q2, P(-2,-4), "$a_2$", b);
label(q3, P(4,0), "$a_3$", r);
#ifdef BISECTORS
bisector_color();
bis1.draw();
bis2.draw();
bis3.draw();
// circle(r1, r2, r3);
#endif
black();
font_size("footnotesize");
label(pt1, P(2,-2), "$p_1$", br);
label(pt2, P(2,2), "$p_2$", tr);
label(pt3, P(-4,-2), "$p_3$", l);
label(side1*med1, P(-4,2), "$m_1$", tl);
label(side2*med2, P(-2,-4), "$m_2$", b);
label(side3*med3, P(4,0), "$m_3$", r);
end();
}
|