summaryrefslogtreecommitdiff
path: root/graphics/sketch/Data/buggy.sk
blob: f3dcbe7401c5fc781b0df86ea4c0907b02e45e47 (plain)
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
def O (0,0,0)
def I [1,0,0]
def J [0,1,0]
def K [0,0,1]
def cornerRad 0.1
def tireRad 0.5
def wheelWidth .4
def nArcSegs 3
def nTireSegs 20
def nAxleSegs 6
def axleRad .05
def robotWidth 1.5
def robotLength 2.5
def bodyWidth .5
def bodyHeight .4
def steeringGamma .2
def leftSteeringAngle  atan2(2 * robotLength * steeringGamma, 2 - robotWidth * steeringGamma)
def rightSteeringAngle atan2(2 * robotLength * steeringGamma, 2 + robotWidth * steeringGamma)

def wheelRad tireRad - cornerRad
def wheelXofs wheelWidth/2 - cornerRad

def rightArc put { 
  translate([ wheelXofs, wheelRad, 0]) 
} sweep { nArcSegs, rotate(90 / nArcSegs) } (cornerRad,0)

def leftArc put { 
  translate([-wheelXofs, wheelRad, 0]) 
} sweep { nArcSegs, rotate(90 / nArcSegs) } (0,cornerRad)

def tread line(wheelXofs, tireRad)(-wheelXofs, tireRad)

def hubPlate sweep[fillcolor=lightgray] { nTireSegs<>, rotate(-360 / nTireSegs, (O), [I]) } (0,wheelRad)

def tire sweep[fillcolor=lightgray]{ nTireSegs, rotate(360 / nTireSegs, (O), -[I]) } { 
  {leftArc} 
  {rightArc} 
  {tread}
}

def wheel { 
  def leftHubPlate  put { translate( [-wheelWidth/2, 0, 0] ) } {hubPlate}
  def rightHubPlate put { rotate(180, (O), [K]) }          {leftHubPlate}
  {rightHubPlate}
  {leftHubPlate}
  {tire}
}

def axle sweep[fillcolor=darkgray]{ nAxleSegs, rotate(360 / nAxleSegs, (O), -[I]) } 
  line (robotWidth/2, axleRad)(-robotWidth/2, axleRad)

def leftSteerableWheel put { 
  rotate(leftSteeringAngle, (O), [J]) then
  translate( [-robotWidth/2, 0, 0] )
} {wheel}

def rightSteerableWheel put { 
  rotate(rightSteeringAngle, (O), [J]) then
  translate( [robotWidth/2, 0, 0] )
} {wheel}

def steerableAxleAssembly {
  {leftSteerableWheel}
  {rightSteerableWheel}
  {axle}
}

def fixedAxleAssembly {
  put { translate( [-robotWidth/2, 0, 0] ) } {wheel}
  put { translate( [ robotWidth/2, 0, 0] ) } {wheel}
  {axle}
}

def bodyopts [fillcolor=white]

def bodyCorner # first octant "rounded corner"
   sweep [bodyopts]{ nArcSegs, rotate(90 / nArcSegs, (O), [I]) } 
   sweep           { nArcSegs, rotate(90 / nArcSegs, (O),-[K]) } (0,cornerRad)

def zBodyEdge
  sweep [bodyopts] { 1, translate([K]) }
  sweep            { nArcSegs, rotate(90 / nArcSegs, (O), -[K]) } (0,cornerRad,0)

def xBodyEdge # positive y-z quadrant about x axis quarter-pipe of unit length
  sweep [bodyopts] { 1, translate([I]) } 
  sweep            { nArcSegs, rotate(90 / nArcSegs, (O), -[I]) } (0,0,cornerRad)

def body {
  def xOfs bodyWidth/2 - cornerRad
  def yOfs bodyHeight/2 - cornerRad
  def zOfs robotLength/2 + cornerRad
  def posZend {
    # 4 corners
    put { translate([ xOfs,  yOfs, zOfs]) } {bodyCorner}
    put { rotate(90, (O), [K]) then
          translate([-xOfs,  yOfs, zOfs]) } {bodyCorner}
    put { rotate(180, (O), [K]) then
          translate([-xOfs, -yOfs, zOfs]) } {bodyCorner}
    put { rotate(270, (O), [K]) then
          translate([ xOfs, -yOfs, zOfs]) } {bodyCorner}
    # 4 edges
    put { scale([2*xOfs, 1, 1]) then 
          translate([-xOfs, yOfs, zOfs]) } {xBodyEdge}
    put { scale([2*yOfs, 1, 1]) then 
          rotate(90, (O), [K]) then
          translate([-xOfs,-yOfs, zOfs]) } {xBodyEdge}
    put { scale([2*xOfs, 1, 1]) then 
          rotate(180, (O), [K]) then
          translate([ xOfs,-yOfs, zOfs]) } {xBodyEdge}
    put { scale([2*yOfs, 1, 1]) then 
          rotate(270, (O), [K]) then
          translate([ xOfs, yOfs, zOfs]) } {xBodyEdge}
    def z zOfs + cornerRad
    polygon[bodyopts](xOfs,yOfs,z)(-xOfs,yOfs,z)(-xOfs,-yOfs,z)(xOfs,-yOfs,z)
  }
  def top {
    put { scale([1,1,2*zOfs]) then
          translate([xOfs, yOfs, -zOfs]) } {zBodyEdge}
    put { scale([1,1,2*zOfs]) then
          rotate(90) then
          translate([-xOfs, yOfs, -zOfs]) } {zBodyEdge}
    def y bodyHeight/2
    polygon[bodyopts](xOfs,y,zOfs)(xOfs,y,-zOfs)(-xOfs,y,-zOfs)(-xOfs,y,zOfs)
  }
  def posXside {
    def x bodyWidth/2
    polygon[bodyopts](x,yOfs,zOfs)(x,-yOfs,zOfs)(x,-yOfs,-zOfs)(x,yOfs,-zOfs)
  }

  # ends of the body
  {posZend}
  put { rotate(180, (O), [I]) } {posZend}

  {top}
  {posXside}

  # bottom and negative X side
  put { rotate(180) } { 
    {top} 
    {posXside}
  }
}

def robot {
  {fixedAxleAssembly}
  put { translate([0, 0, -robotLength]) } {steerableAxleAssembly}
  put { translate([0, 0, -robotLength/2])   } {body}
}

def centerXform
       translate(robotLength/2 * [K])
  then rotate(90, (O), [J])

def winWidth
  <zoomed_in> 0.6
  <zoomed_out> 1.5
  <> 1 

def foreshorteningFactor 
  <fish_eye> .3
  <parallel> 30
  <> 1 # base

def pai 8
def panAngle 
  <vai>   -pai
  <vaii>  -pai
  <vaiii> -pai
  <vaiv>   pai
  <vav>    0
  <vavi>  -pai
  <vavii>  pai
  <vaviii> pai
  <vaix>  pai
  <>       0

def panAxis
  <vai>    [-1,-1,0]
  <vaii>   [-1,0,0]
  <vaiii>  [-1,1,0]
  <vaiv>   [0,1,0]
  <vav>    [0,1,0]
  <vavi>   [0,1,0]
  <vavii>  [-1,1,0]
  <vaviii> [-1,0,0]
  <vaix>  [-1,-1,0]
  <>       [0,1,0]

def eyeAxis [10,7,10]
def eyeI (O) + .5 * foreshorteningFactor * [eyeAxis]
def dvI (O) - (eyeI)

def upRot 
  <tilt_left>  -20
  <tilt_right> 20
  <> 0

def up [0,1,0] then rotate(upRot, (O), -[eyeAxis])

def viewXformI
  <parallel> 
     view ((eyeI), [dvI], [up]) 
     then rotate(-panAngle, (O), [panAxis])
     then perspective(|[dvI]|)
     then scale(1.5/winWidth)
     then scale([1,1,1000])
  <> view ((eyeI), [dvI], [up]) 
     then rotate(-panAngle, (O), [panAxis])
     then perspective(|[dvI]|)
     then scale(1.5/winWidth)

def dashframe {
  line[linestyle=dashed](-1,-1, 1)( 1,-1, 1)(1,1, 1)(-1,1, 1)(-1,-1, 1)
  line[linestyle=dashed](-1,-1,-1)( 1,-1,-1)(1,1,-1)(-1,1,-1)(-1,-1,-1)
  line[linestyle=dashed](-1,-1, 1)(-1,-1,-1)
  line[linestyle=dashed]( 1,-1, 1)( 1,-1,-1)
  line[linestyle=dashed]( 1, 1, 1)( 1, 1,-1)
  line[linestyle=dashed](-1, 1, 1)(-1, 1,-1)
}

def floor_grid {
  def opts [linewidth=.2pt]
  def nX 7
  def nZ 5
  def dx (robotLength+tireRad*2) + 2
  def dz (robotWidth+wheelWidth) + 2
  def y -tireRad-.001

  repeat { nX+1, translate([dx/nX,0,0]) } line[opts](-dx/2,y,-dz/2)(-dx/2,y,dz/2)
  repeat { nZ+1, translate([0,0,dz/nZ]) } line[opts](-dx/2,y,-dz/2)(dx/2,y,-dz/2)
}

put { [[viewXformI]] } {
  put { [[centerXform]] } {robot}
  {floor_grid}
# put { scale([(robotLength+tireRad*2)/2, tireRad, (robotWidth+wheelWidth)/2]) } {dashframe}
}

#def frameOfs 2
#put { [[viewXformI]] then translate(-frameOfs * [I]) } {robot}
#put { [[viewXformI]] then translate(frameOfs * [I]) } {robot}
#put { [[simpleViewXform]] then translate(2*frameOfs * [I]) } {robot}


global {
  set [linewidth=.3pt]

  % set up a bounding box
  def w 3
  def ar 3/2.2
  def cbp1 (-w,-w/ar,0)
  def cbp2 (w,w/ar,0)

  picturebox [.5] (cbp1)(cbp2)
  frame
}