The secret is out. The truth is out there. Using weird alien technology, I can now reveal that they do exist... Cubes with holes! Our top people in white coats have revealed these facts about these deceptively simple devices: Due to the reflex angles around the holes, the faces of the cubes must be made from triangles as concave polygons can't be rendered. The angleto procedure returns the angle that a turtle must turn right through to get to another point in its plane. This technology may have applications in other projects... There are strange and as yet unexplained energy fields flowing through the tube. Attempting to fly the camera into the tube results in a Windows GPF... Moving the camera in a vertical circle around these objects (as shown in the demonstration) results in a strange flipping of the viewpoint as the camera crosses the X and Y axes. This flipping has been negated in the demonstration, but commenting out the "ask -2" lines in the flyaround procedure will demonstrate the effect. Cubes with spherical indentations are not beyond the bounds of possibility. Investigations continue. Trust no-one. Tom Lynn
to aaa
; Cubes with holes.
cs perspective setsc [0 0 0] setlight [0 0.3] ask -3 [setposxyz [-1000 -1000 400]]
ht
setcam [150 150 850]
ask -2 [setposxyz [150 150 -150]]
(holeycube 300 100 [95 127 95] [63 95 63] 4)
setposxyz [100 100 -500] setorientation [0 0 0]
(holeycube 100 50 [95 127 191] [95 127 191] 4)
polyview
flyaround [150 150 -150] 1000 10
end
to angleto :pxyz
; Returns the angle to turn right by in order to point towards :pxyz,
; (assuming that :pxyz is in the same plane).
localmake "startpos posxyz
if :startpos = :pxyz [output 0]
localmake "hvec vecsub :pxyz :startpos
localmake "penstate pendownp
pu fd 1 localmake "fdvec vecsub posxyz :startpos bk 1
rt 90 fd 1 localmake "rtvec vecsub posxyz :startpos bk 1 lt 90
local "theta
localmake "costheta (dotprod :hvec :fdvec) / (veclen :hvec)
if 1 < (abs :costheta) [
ifelse :costheta < 0 [make "costheta -1][make "costheta 1]
]
make "theta arccos :costheta
if (dotprod :hvec :rtvec) < 0 [make "theta 360-:theta]
ifelse :penstate [pd][pu]
output :theta
end
to dotprod :p :q
output apply "sum (map "product :p :q)
end
to flyaround :centre :radius :spq
localmake "a 90/:spq
localmake "step :radius*(sin :a)
; spq = slices per quarter
; a = slice angle
setturtle -1
; Should really go down :a/2 to centre properly,
; but this causes problems with the view-flipping.
; The "ask -2"s are needed to cope with a view-flipping
; effect which I don't really understand. Comment them
; out to see what I mean.
repeat :spq [fd :step down :a]
ask -2 [up 90 rt 180]
repeat :spq [fd :step down :a]
ask -2 [down 90 rt 180]
repeat :spq [fd :step down :a]
ask -2 [up 90 rt 180]
repeat :spq [fd :step down :a]
end
to hole :size [:slices 8]
; Makes a square with a circular hole of same diameter as square
; side length, :size. This can be used together with holeface and
; tube to create a 3d object with a cylindrical hole. Circle is
; represented as a regular polygon with 4*:slices sides.
localmake "sliceangle 90/:slices
localmake "holeside :size*sin (:sliceangle/2)
local [k orient corner lastpos]
repeat 4 [
make "corner posxyz
pu fd :size/2 make "lastpos posxyz bk :size/2
repeat :slices [
pu make "orient orientation
pd polystart
make "k (angleto :lastpos)
rt :k fd distancexyz :lastpos lt :k
make "k 180-(repcount-0.5)*:sliceangle
rt :k fd :holeside make "lastpos posxyz lt :k
make "k (angleto :corner)
rt :k fd distancexyz :corner lt :k
polyend
]
pu setposxyz :corner setorientation :orient
fd :size rt 90
]
end
to holeface :side :diameter [:slices 8]
; Creates a square of sidelength :side with a central circular hole
; of diameter :diameter. In fact, the circle is a :slices sided polygon.
localmake "diag (0.5*sqrt 2)*(:side-:diameter)
repeat 4 [
pd polystart
fd :side
rt 135 fd :diag
rt 45 fd :diameter
rt 45 fd :diag
rt 135
polyend
pu fd :side rt 90
]
pu rt 45 fd :diag lt 45
(hole :diameter :slices)
pu rt 45 bk :diag lt 45
end
to holeycube :squareside :holediam :cubecol :tubecol [:slices 8]
repeat 2 [
setpc :cubecol (holeface :squareside :holediam :slices)
pu rt 45 fd 0.5*:squareside*sqrt 2 lt 45
setpc :tubecol (tube :holediam :squareside :slices)
pu rt 45 bk 0.5*:squareside*sqrt 2 lt 45
fd :squareside down 90
setpc :cubecol pd polystart repeat 4 [fd :squareside rt 90] polyend
pu fd :squareside down 90
]
pu lt 90 down 90
repeat 2 [
pd polystart repeat 4 [fd :squareside rt 90] polyend
pu repeat 2 [fd :squareside down 90]
]
end
to reorient :rpy
; Restores an orientation returned by orientation.
setorientation [0 0 0]
rr (first :rpy)
up (first butfirst :rpy)
rt (first butfirst butfirst :rpy)
end
to setcam :pxyz
ask -1 [setposxyz :pxyz]
end
to test_angleto
; Tests that angleto is working by moving to a random plane,
; looking in a random direction and checking that it gives the correct angle.
pu
repeat 20 [
setposxyz (list (100 - random 200) (100 - random 200) (100 - random 200))
setorientation (list (random 360) (random 360) (random 360))
make "testangle (random 360)
rt :testangle fd 100 make "testpos posxyz bk 100 lt :testangle
show abs ((angleto :testpos) - :testangle)
]
end
to tube :d :h [:slices 8]
; Draws an open-ended cylindrical tube, diameter :d, height :h
; with the centre of the top around the current turtle position
; and the tube perpendicular below it. Circular cross-section
; is modelled by a regular polygon with 4*:slices sides.
localmake "r :d/2
localmake "halfsliceangle 45/:slices
localmake "side :d*sin (:halfsliceangle)
repeat 4*:slices [
pu fd :r rt :halfsliceangle down 90
pd polystart
repeat 2 [fd :h rt 90 fd :side rt 90]
polyend
pu up 90 lt :halfsliceangle bk :r
rt 2*:halfsliceangle
]
end
to vecadd :a :b
; Adds vectors :a and :b
output (map [?1 + ?2] :a :b)
end
to veclen :v
localmake "a first :v
localmake "b first butfirst :v
localmake "c first butfirst butfirst :v
output sqrt (:a*:a + :b*:b +:c*:c)
end
to vecscale :s :v
; Multiplies vector :v by scalar :s
output map (list "? "* :s) :v
end
to vecsub :p :q
output (map [?1 - ?2] :p :q)
end
The following section of this message contains a file attachment
prepared for transmission using the Internet MIME message format.
If you are using Pegasus Mail, or any another MIME-compliant system,
you should be able to save it or view it from within your mailer.
If you cannot, please ask your system administrator for assistance.
---- File information -----------
File: holeycubes.gif
Date: 2 Aug 1998, 15:17
Size: 3269 bytes.
Type: GIF-image
Global SchoolNet Foundation -
Linking Kids Around the World!
Copyright GSN - All Rights Reserved
- Comments
& Questions
Visit GSN's
Global
Schoolhouse for more exciting learning resources!
Search our Site
-
Home