LOGO-L> 4methods to draw a Sphere 
Author Message
 LOGO-L> 4methods to draw a Sphere

;Hello Turtlers
;Here are 4 metods to draw a sphere.
;FIRST METHOD:
;This method is based on the procedure supplied by Garry Clark to
;George mills as given in MSWLogo demos. in this procedure a vertical
;circle is rotated arround the y-axis then circles of different dimeters
;are drawn in planes parallel to the xz plane,spaced a distance g from
;each other. trigonometry is used to calculate circles radii.
;---------------------------------------------------
to go
turnon3d cs ht
vertical 200 10 horizontal 200 10
end

to horizontal :rad :step
repeat 180/:step [make "g repcount*:step-90 fd :rad*sin :g
downpitch 90 circle :rad*cos :g uppitch 90 bk :rad*sin :g]
end

to turnon3d
; This is a library procedure for 3-d
perspective
setturtle -1
setxyz 1000 1000 1000
setturtle 0
end

to vertical :rad :step
repeat 180/:step [circle :rad rr :step]
end
;-----------------------------------------------------------
;SECOND METHOD:
;This method is based on the gridx and gridy procedures I have
;developed for the "sombrero" surface posted some time ago. In this
;method the equation of the sphere is given in xyz co-ordinates as:
;x^2+Y^2+z^2=r^2
;the procedure y calculates the y coordinate for each point on the
;xz plan.
;---------------------------------------------------------------
to go ; sphere (or ellipsoid if you put :a = say 10)
turnon3d grid 10 10 1
end

to grid :a :b :step
for [i 1 2][for[j -:a :a :step][
    for[k -:b :b :step][
      if y >0 [ifelse :i = 1 [setxyz :j*15 y*15 :k*15][
                              setxyz :j*15 -y*15 :k*15] pd]]pu]]
end

to turnon3d
;this is a library procedure for 3d
perspective cs ht setturtle -1
setxyz 1000 1000 1000 setturtle 0
end

to y
ifelse((:j* :j)/(:a* :a) + (:k* :k)/(:b* :b))>1[op 0][
op :a* sqrt( 1-((:j* :j)/(:a* :a) + (:k* :k)/(:b* :b)))]
end
;----------------------------------------------------------------

;THIRD NETHOD:
;This method uses the procedure cylpos to set position in cylindrical
;co-ordinates ,i.e r fi y.In this case for each value of :r and :f the
;corresponding y is calculated by the simple procedure y since
;r^2+y^2 =a^2 where a is the radius of the sphere.
;---------------------------------------------------
to cylpos :r :fi :y
;this is a library procedure for cylinderical co-ordinates
setxyz :r*cos :fi :y :r*sin :fi
end

to go
turnon3d
sphere 200
end

to sphere :a
for [r -:a :a 10][for[fi 0 360 10][cylpos :r :fi y pd]pu]
end

to turnon3d
; This is a library procedure for 3-d
perspective
setturtle -1  
setxyz 1000 1000 1000
setturtle 0 cs ht
end

to y
ifelse :r >0 [op sqrt (:a* :a - :r* :r)][op -sqrt(:a* :a - :r* :r)]
end
;------------------------------------------------------
;FOUTH METHOD:
;This method is based on using sphirical the library procedure
; sppos which is used to setposition in spherical co-ordinates, i.e.
;the r, fi theta values. in this case,since the eqution of the
;sphere in these coordinates is very simple:  r = const. no additinal
;equtions are needed.(it is natural to draw a sphere in spherical
;coordinates.
;--------------------------------------------------------------
to go
turnon3d cs ht
sphere 200
end

to sphere :a
for [theta 0 180 10][for [fi 0 360 10][sppos :a :fi :theta pd]pu]
end

to sppos :r :fi :theta
;this could be a library procedure for sphirical co-ordinates
setxyz :r*(sin :theta)*cos :fi :r*cos :theta :r*(sin :theta)*sin :fi  
end

to turnon3d
; This is a library procedure for 3-d
perspective
setturtle -1
setxyz 1000 1000 1000
setturtle 0
end
;----------------------------------------------------------------

;Best Regards
;MHELHEFNY
---------------------------------------------------------------





Mon, 10 Apr 2000 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. LOGO-L> Logo - drawing some selected shapes

2. LOGO-L> Logo: Drawing some selected shapes

3. LOGO-L> sphere or Christmas bulb

4. LOGO-L> Sphere or bulb

5. LOGO-L> Recursive Drawing

6. LOGO-L> One more drawing

7. LOGO-L> Apple logo/MSW Logo

8. LOGO-L> Reseach Machines Logo (RM LOGO)

9. WTD: 'ls -lR '->HTML code

10. LOGO-L> Welcome to logo-l

11. LOGO-L> Re: Dynamic scope in Logo

12. LOGO-L> INFO re SIG-LOGO

 

 
Powered by phpBB® Forum Software