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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
#include "cad/solve.h"
#include <assert.h>
int main(int argc, char *argv[]) {
{
printf("Triangle by 3 distances\n");
struct constraints constraints = {};
struct component p1 = {.type = COM_POINT};
struct component p2 = {.type = COM_POINT};
struct component p3 = {.type = COM_POINT};
add_constraint(&constraints, (struct constraint[]){
PP_DISTANCE(&p1, &p2, 30),
PP_DISTANCE(&p1, &p3, 30),
PP_DISTANCE(&p2, &p3, 30),
CEND(),
});
struct drawing drawing = {};
bool solved = solve_constraints(&constraints, &drawing);
assert(solved);
free_drawing(&drawing);
free_constraints(&constraints);
}
{
printf("Triangle by 2 angles and a distance\n");
struct constraints constraints = {};
struct component l1 = {.type = COM_LINE};
struct component l2 = {.type = COM_LINE};
struct component l3 = {.type = COM_LINE};
struct component p1 = {.type = COM_POINT};
struct component p2 = {.type = COM_POINT};
struct component p3 = {.type = COM_POINT};
add_constraint(&constraints, (struct constraint[]){
POINT_ON_LINE(&p1, &l3),
POINT_ON_LINE(&p1, &l1),
POINT_ON_LINE(&p2, &l1),
POINT_ON_LINE(&p2, &l2),
POINT_ON_LINE(&p3, &l2),
POINT_ON_LINE(&p3, &l3),
PP_DISTANCE(&p1, &p2, 30),
LL_ANGLE(&l1, &l2, DEG(60)),
LL_ANGLE(&l2, &l3, DEG(60)),
CEND(),
});
struct drawing drawing = {};
bool solved = solve_constraints(&constraints, &drawing);
assert(solved);
free_drawing(&drawing);
free_constraints(&constraints);
}
{
printf("Two triangles sharing a point one defined by angles\n");
struct constraints constraints = {};
struct component p1 = {.type = COM_POINT};
struct component p2 = {.type = COM_POINT};
struct component p3 = {.type = COM_POINT};
struct component p4 = {.type = COM_POINT};
struct component p5 = {.type = COM_POINT};
struct component t1base = {.type = COM_LINE};
struct component t2base = {.type = COM_LINE};
struct component t2side = {.type = COM_LINE};
add_constraint(&constraints, (struct constraint[]){
// Make a triangle
PP_DISTANCE(&p1, &p2, 30),
PP_DISTANCE(&p1, &p3, 30),
PP_DISTANCE(&p2, &p3, 30),
POINT_ON_LINE(&p1, &t1base),
POINT_ON_LINE(&p2, &t1base),
// With another triangle sharing a point
PP_DISTANCE(&p4, &p5, 30),
PP_DISTANCE(&p3, &p4, 30),
LL_ANGLE(&t2side, &t2base, DEG(60)),
POINT_ON_LINE(&p3, &t2side),
POINT_ON_LINE(&p4, &t2side),
POINT_ON_LINE(&p4, &t2base),
POINT_ON_LINE(&p5, &t2base),
// The edge they don't share is constrained
LL_ANGLE(&t1base, &t2base, DEG(40)),
CEND(),
});
struct drawing drawing = {};
bool solved = solve_constraints(&constraints, &drawing);
assert(solved);
free_drawing(&drawing);
free_constraints(&constraints);
}
{
printf("Two triangles sharing a point with an angle constrained base\n");
struct constraints constraints = {};
struct component p1 = {.type = COM_POINT};
struct component p2 = {.type = COM_POINT};
struct component p3 = {.type = COM_POINT};
struct component p4 = {.type = COM_POINT};
struct component p5 = {.type = COM_POINT};
struct component t1base = {.type = COM_LINE};
struct component t2base = {.type = COM_LINE};
add_constraint(&constraints, (struct constraint[]){
// Make a triangle
PP_DISTANCE(&p1, &p2, 30),
PP_DISTANCE(&p1, &p3, 30),
PP_DISTANCE(&p2, &p3, 30),
POINT_ON_LINE(&p1, &t1base),
POINT_ON_LINE(&p2, &t1base),
// With another triangle sharing a point
PP_DISTANCE(&p4, &p5, 30),
PP_DISTANCE(&p3, &p4, 30),
PP_DISTANCE(&p3, &p5, 30),
POINT_ON_LINE(&p4, &t2base),
POINT_ON_LINE(&p5, &t2base),
// The edge they don't share is constrained
LL_ANGLE(&t1base, &t2base, DEG(40)),
CEND(),
});
struct drawing drawing = {};
bool solved = solve_constraints(&constraints, &drawing);
// @COMPL: We don't currently know how to derive an angle constraint
// from the rigid triangle. We'd probably need to do some sort of
// recursive solving, and even then you can't construct it without some
// sort of math in the construction phase.
assert(!solved);
// assert(solved);
free_drawing(&drawing);
free_constraints(&constraints);
}
return 0;
}
|