-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeometry2d
More file actions
95 lines (78 loc) · 1.84 KB
/
geometry2d
File metadata and controls
95 lines (78 loc) · 1.84 KB
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
#a collection of basic geometries for repocad
#use these in other scripts by typing
#"import geometry2d" in the script (without ")
def Vector(x as Number y as Number)
#### RECTANGLE ####
#PARAMETERS:
# x1 = corner1 x
# y1 = corner1 y
# x2 = corner1 x
# y2 = corner1 y
def rectangle (x1 as Number y1 as Number
x2 as Number y2 as Number) = {
line(x1 y1 x1 y2)
line(x2 y2 x1 y2)
line(x2 y1 x2 y2)
line(x1 y1 x2 y1)
}
def rectangle(v1 as Vector v2 as Vector) = rectangle(v1.x, v1.y, v2.x, v2.y)
def line(v1 as Vector v2 as Vector) = {
line(v1.x v1.y v2.x v2.y)
}
def length(v1 as Vector v2 as Vector) = {
def a = v1.x
def b = v1.y
def c = v2.x
def d = v2.y
sqrt(((c - a) * (c - a)) + ((d - b) * (d - b)))
}
def midpoint(v1 as Vector v2 as Vector) = {
Vector((v1.x + v2.x) / 2, (v1.y + v2.y) / 2)
}
#example
repeat -5 to -1 using i {
repeat -4 to 1 using j {
def a = i * 20
def b = j * 22
rectangle(a b a + 5 b + 5)
}
}
#### TRIANGLE ####
#PARAMETERS:
# x = center x
# y = center y
# d = distance to corners
def triangle(x as Number y as Number d as Number) = {
def p1y = y + d
def p2x = x + d
def p3x = x - d
def offsetY = d / 3
line(x p1y p2x y - offsetY)
line(p2x y - offsetY p3x y - offsetY)
line(x p1y p3x y - offsetY)
}
#### SQUARE ####
def square(neg as Number pos as Number) = {
line(neg neg neg pos)
line(neg pos pos pos)
line(pos pos pos neg)
line(pos neg neg neg)
}
#example
repeat 0 to 4 using i {
repeat -4 to 1 using j {
def a = i * 20
def b = j * 22
triangle(a b 5)
}
}
#ARC TOOLS
def arcArray (cX as Number cY as Number
rowSize as Number radial as Number) = {
repeat 3 to 22 using i {
def multiplied = i * rowSize
def startAngle = radians(radial - 105)
def endAngle = radians(radial - 75)
arc(cX cY multiplied startAngle endAngle )
}
}