LOGO-L> sphere or Christmas bulb

Andrzej Baczynski wrote :-

Quote:

>Hello Turtles,

>I have found an old mail (dated October 23) from Mr. MHELHEFNY, with 4 methods

to

>draw a sphere in MSWLogo 3D. There are Christmas coming, and I found that one

>more way to produce a sphere (i.e. a bulb for a Christmas Tree) may be useful.

>This is a short and simple, I hope, procedure. It use only rudimentary turtle

>move commands and applies very little trigonometry. (I'm proud of this). The

>result, with appropriate PENCOLOR and PENSIZE, may be as attached. It should

>run in PERSPECTIVE mode, of course.

>This is a procedure itself:

to sph4 :z :w :dx

localmake "om (180 / :z / :w)

localmake "fi arctan (1 / :z / 2 )

repeat (:z * :w) [up :fi fd :dx*sin (repcount * :om ) down :fi rt (360 / :w) ]

end

Quote:

>You may run it with :z=18 :w=18 :dx=30 for example and any starting turtle

>position.

>There are 3 questions, which a demanding student may ask:

>1- Is it really a sphere ?

>2- Where is a centre?

>3- How to draw only a visible hemisphere?

>I have no students, so I don't need to look for the answer.

>Regards,

>Andrzej B.

_________________

;Hi Andrzej !

;Your code for drawing the sphere is actually simple and elegant let me

;praise it. But since on the contrary I have many students I tried to

;study it and here is what I have found.

;1- This code could also be used to draw an ellipsoid as well as a sphere

;2- The code actually draws some sort of a space poly_speiral selenoid with

; deminishing radii at both ends

;3- Since it is difficult to figure out the effect of changing :z ,:w and

; :dx on the resulting shape I have renamed these variables to reflect

; there meaning . Also I added a fourth argument to the procedure to

; enable the drawing of an ellipse in addetion to a sphere.

;4- a) The number of turns of the selenoid is :turns, so increasing this

; number will not change the size of the sphere or ellipsoid

; b) The number of sides in each selenoid turn is :sides, so increasing

; this number will make the turn closer to a perfect circle and of

; course will increase its perimiter

; c) The length if each side of the polygon drawing the quasi circular

; turn is :length, so increasing this length will result in an

; increase of the sphere radius

; d) The added input to the procedure :k is a factor which gives a sphere

; when it is 1 and will elongate the spiral giving an ellipsoid if it

; is>1 and will contract it giving an ellipsoid if it is <1

;5- the code as shown will shown a solinoid with 12 turns of square shape

; with the side of the middle turn proportional to 100 and a contraction

; factor of .3

;6- You may try sph4 12 60 20 1 ------> a sphere

; and sph4 12 60 20 1.5 ----> an ellipsoid.

; or sph4 12 60 20 .3 -----> a better ellipsoid

;

;At the end let me wish you and all the members of logo-l a very happy

;and Merry Christmas

;Best Regards

;Mhelhefny

;-------------------

to go

cs ht turnon3d sph4 12 4 200 1

end

to sph4 :turns :sides :length :k

localmake "om (180 / :turns / :sides)

localmake "fi :k* arctan (1 / :turns / 2 )

repeat (:turns* :sides)[wait 5 up :fi fd :length*sin (repcount * :om) down :fi

rt (360/ :sides)]

end

to turnon3d

perspective

setturtle -1 setxyz 1000 1000 1000

setturtle 0

end

;-----------------------------

---------------------------------------------------------------