# Thread: Spiral over the Sphere

1. ## Spiral over the Sphere

here https://www.intmath.com/blog/mathema...l-spiral-10254
the author wants to cover the surface of a solid sphere using 1.5 cm hemp rope and he wants to know how much he needs to buy.
i have used the equation provided by the author, imagine the spiral lines as the center of the thick rope. experimentally by adding the tiny distances we find the length = 522.7 cm. it is supposed the rope is ideal, i don't understand why the difference between 522.7 and the author result 514.9
change the 16.4 in line 87 to get less or more spiral loops
Q: how to make the sphere in the middle nicer. there is a topic about this in the forum years ago but i can't find it.
```Uses "TBGL"
Uses "math"
'uses "console"
'the points in this spiral is dense at poles, but the distance
'between each Loop is the same
'https://www.intmath.com/blog/mathematics/how-to-find-the-length-of-a-spherical-spiral-10254

Begin Const
%listPoints = 1
End Const

Type PointsData
x As Double
y As Double
z As Double
End Type

Global Number_Of_Points As Long
Global increment, Loops As Double
increment = 0.001 ' increment of parameter t

Number_Of_Points = Int(2*Pi/increment)+2
Dim arr(Number_Of_Points) As PointsData

Function TBMain()
Global hWnd      As DWord
Local FrameRate As Double
' -- Create and show window
hWnd = TBGL_CreateWindowEx("parametric sphere - press ESC to quit", 800, 600, 32, %TBGL_WS_WINDOWED)' Or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
TBGL_BackColor 255,255,255

FillArrays ' call the sub to create the List of vertices and color

' -- Resets status of all keys
TBGL_ResetKeyState()
TBGL_PointSize 2 'if you want thick points uncomment this line
TBGL_LineWidth 2
Long i: i=0
' -- Main loop
While TBGL_IsWindow(hWnd)
'init
FrameRate = TBGL_GetFrameRate
TBGL_ClearFrame
'TBGL_Camera(0, 1.1, 0.0000001, 0, 0, 0)
TBGL_Camera(0, 3, 30, 0, 0, 0)
TBGL_Rotate 90, 1, 0, 0
TBGL_Rotate GetTickCount/50, 1, 1, 1
TBGL_CallList %listPoints
TBGL_Color 195, 235, 195
TBGL_Sphere 1
TBGL_PushMatrix
i+1
If i>Number_Of_Points Then i=Number_Of_Points
TBGL_Translate arr(i).x,arr(i).y,arr(i).z
TBGL_Color 0, 0, 255
TBGL_Sphere 0.2
TBGL_PopMatrix

TBGL_DrawFrame
' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
Wend
' -- Destroying the buffer is not necessary,
' -- the garbage collector will take care of it

' -- Destroy window
TBGL_DestroyWindow
End Function

Sub FillArrays()
Dim x, y, z,r, t As Double
Dim x1,x2,y1,y2,z1,z2, tot, dis As Double

t = 0

TBGL_NewList %listPoints
'TBGL_BeginPoly(%GL_POINTS)
TBGL_BeginPoly(%GL_LINE_STRIP)

Long i : i=1
r = 7.83
Double toot

While t <= 2*Pi

x = r *Cos((t - Pi)/2)* Cos(16.4*t)
y = r *Cos((t - Pi)/2)* Sin(16.4*t)
z = r *Sin((t - Pi)/2)

TBGL_Color 255, 0, 0
TBGL_Vertex x, y , z
t + increment
i+1
arr(i).x = x: arr(i).y = y: arr(i).z = z
If i>=2 Then
dis = Sqr((x-x2)^2+(y-y2)^2+(z-z2)^2)
tot = tot + dis
End If

x2=x
y2=y
z2=z

Wend

TBGL_EndPoly
TBGL_EndList
TBGL_SetWindowTitle( hWnd, "spiral Length by experiment= " +Str\$(tot)+"   "+"length of the last dis   "+Format\$(dis, "####.########"))
End Sub
```
another spiral not related to the above problem , the distance between the points is equal, and you can decide the number of the whole points in line 97: Number_Of_Points = 1000 . this spiral can be used to cover with tubes
```Uses "UI", "TBGL"
Uses "math"
#Include Once "%APP_INCLUDEPATH%\thinbasic_gl.inc"
#Include Once "%APP_INCLUDEPATH%\thinbasic_glu.inc"
'Uses "console"
' in this spiral the points are separated equaly even at the poles
' the distance between each Loop is the same
'https://math.stackexchange.com/questions/2668043/archimedean-spiral-on-a-hemisphere

Begin Const
%listPoints = 1
%listPoints2 = 2
End Const

Type PointsData
x As Double
y As Double
z As Double
End Type

Dim arr(1) As PointsData

Global SmallNum As Double
Global Degrees As Double
Global Number_Of_Points As Long
'Declare Function Asin(ByVal number As Double ) As Double

Function TBMain()
Global hWnd      As DWord
Local FrameRate As Double
' -- Create and show window
hWnd = TBGL_CreateWindowEx("parametric sphere - press ESC to quit", 800, 600, 32, %TBGL_WS_WINDOWED)' Or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
TBGL_BackColor 255,255,255

FillArrays ' call the sub to create the List of vertices and color

' -- Resets status of all keys
TBGL_ResetKeyState()
'if you want thick points uncomment this line
TBGL_LineWidth  1
TBGL_PointSize 5
glEnable(%GL_POINT_SMOOTH)
Dim i As Long: i=1
' -- Main loop
While TBGL_IsWindow(hWnd)
'init
FrameRate = TBGL_GetFrameRate
TBGL_ClearFrame
TBGL_Camera(0, 2, 3, 0, 0, 0)
' -- Render it
TBGL_Rotate 90, 1, 0, 0
TBGL_Rotate GetTickCount/50, 0, 1, 0
TBGL_CallList %listPoints
TBGL_CallList %listPoints2

TBGL_PushMatrix
TBGL_Translate arr(i).x,arr(i).y,arr(i).z
TBGL_Color 255, 0, 0
TBGL_Sphere 0.05
TBGL_PopMatrix
i=i+1
If i=Number_Of_Points+1 Then i=Number_Of_Points
TBGL_DrawFrame
'DoEvents(On)

' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
Wend
' -- Destroying the buffer is not necessary,
' -- the garbage collector will take care of it

' -- Destroy window
TBGL_DestroyWindow
End Function

Sub FillArrays()
Global red, green, blue As Long

TBGL_NewList %listPoints
TBGL_BeginPoly(%GL_LINE_STRIP)
red = 255: green = 50: blue =  0
calcArrays()
TBGL_NewList %listPoints2
TBGL_BeginPoly(%GL_POINTS)
red = 0: green = 0: blue = 255
calcArrays()

End Sub

Sub calcArrays()
Dim x, y, z,r, u, v,volLim As Double
Dim x1,x2,y1,y2,z1,z2, tot, dis As Double
Degrees =  180 / Pi
SmallNum = 0.000000001
Long N, i
Number_Of_Points = 1000
N = Number_Of_Points
ReDim arr(Number_Of_Points)
volLim = 2*Pi ' % volume limit. volLim = pi will give a hemisphere.
For i = 1 To N
z = -((volLim/Pi)*(i-1)-N)/N

TBGL_Color red, green, blue
TBGL_Vertex x, y , z

arr(i).x = x: arr(i).y = y: arr(i).z = z
If i>=2 Then
dis = Sqr((x2-x)^2+(y2-y)^2+(z2-z)^2)
tot = tot + dis
End If
x2=x
y2=y
z2=z
'PrintL dis
Next

'msgbox(0, str\$(oo))
TBGL_EndPoly
TBGL_EndList
TBGL_SetWindowTitle( hWnd, "spiral Length by experiment= " +Str\$(tot)+"   "+"length of the last dis ="+Str\$(dis) )

End Sub

FUNCTION asin(ByVal x As double) As double 'returns ARC SIN in degrees
asin = (Atn(x / Sqr(-x * x + 1+ SmallNum))) * (180 / Pi)
End Function
```
NOTE: i have astonished that the small blue sphere is following the spiral line wherever and however it rotates. it is in fact like a magic. yes we can say it is because glRotate or translate affect all systems below it, but i was not believing this will happened until i saw it in practice with some guessing.

2. Primo,

thanks a lot for sharing these visual examples, I really enjoy observing them a lot

Nice way to optimize via display lists!

```Dim i As Long: i=1
```
You can write:
```Dim i As Long = 1
```
Or even shorter:
```Long i = 1
```

Petr

3. Thanks Petr
about my question: how to make the sphere in the middle nicer, i have found the page i refer to: it is how to make "smooth openGL objects"? http://www.thinbasic.com/community/s...light=freeglut

the function TBGL_SetPrimitiveQuality works okay