Author Topic: elliptic hyperboloid  (Read 7247 times)

0 Members and 1 Guest are viewing this topic.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: elliptic hyperboloid
« Reply #30 on: April 18, 2020, 12:14:42 pm »
5G... jfc lol
You're not done when it works, you're done when it's right.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: elliptic hyperboloid
« Reply #31 on: April 18, 2020, 12:43:24 pm »
Answer for BPlus: It's all determined by the point of view PERSPECTIVE. A circle, seen from the side is as an ellipse. When correctly rotated (viewed from the top) you can see a circle. My program just counts on the side view, so it creates an ellipse and it does a 3D effect.

Answer to Ashish: Again, it's not 3D mathematics. It's 2D mathematics, with a 3D perspective.

This show it:

Code: QB64: [Select]
  1. _TITLE "Elliptic Hyperboloid"
  2. SCREEN _NEWIMAGE(600, 600, 32)
  3.  
  4. TYPE V3D
  5.     X AS SINGLE
  6.     Z AS SINGLE
  7.  
  8. DIM SHARED V(30) AS V3D
  9. 'create points for circle:
  10. FOR c = 0 TO _PI(2) STEP _PI(2) / 31
  11.     V(i).X = SIN(c) * 3
  12.     V(i).Z = COS(c) * 3
  13.     i = i + 1
  14.  
  15.     _LIMIT 30
  16.  
  17. SUB _GL ()
  18.  
  19.     _glMatrixMode _GL_PROJECTION
  20.     _gluPerspective 50, 1, 0.1, 100
  21.  
  22.     _glMatrixMode _GL_MODELVIEW
  23.     a = 1
  24.     b = 1
  25.     c = 1
  26.     STATIC rotY
  27.     _glTranslatef 0, 0, -10
  28.     _glRotatef rotY, 1, 0, 0
  29.     rotY = rotY + 1
  30.  
  31.  
  32.  
  33.     '    _glPointSize 2
  34.     _glLineWidth 5
  35.     _glBegin _GL_LINES
  36.     FOR u = 0 TO 29 STEP 1
  37.         _glVertex3f V(u).X, 1, V(u).Z
  38.         _glVertex3f V(u + 1).X, 1, V(u + 1).Z
  39.     NEXT
  40.     _glVertex3f V(0).X, 1, V(0).Z
  41.     _glVertex3f V(30).X, 1, V(30).Z
  42.  
  43.     _glEnd
  44.  

So real 3D solution can be something as this:

Code: QB64: [Select]
  1. _TITLE "Elliptic Hyperboloid"
  2. SCREEN _NEWIMAGE(600, 600, 32)
  3.  
  4. TYPE V3D
  5.     X AS SINGLE
  6.     Z AS SINGLE
  7.  
  8. DIM SHARED V(30) AS V3D
  9. 'create points for circle:
  10. FOR c = 0 TO _PI(2) STEP _PI(2) / 31
  11.     V(i).X = SIN(c) * 3
  12.     V(i).Z = COS(c) * 3
  13.     i = i + 1
  14.  
  15.     _LIMIT 30
  16.  
  17. SUB _GL ()
  18.  
  19.     _glMatrixMode _GL_PROJECTION
  20.     _gluPerspective 50, 1, 0.1, 100
  21.  
  22.     _glMatrixMode _GL_MODELVIEW
  23.     a = 1
  24.     b = 1
  25.     c = 1
  26.     STATIC rotY
  27.     _glTranslatef 0, 0, -10
  28.     _glRotatef rotY, 1, 0, 0
  29.     _glRotatef rotY, 0, 1, 0
  30.  
  31.     rotY = rotY + .5
  32.  
  33.  
  34.  
  35.     '    _glPointSize 2
  36.     _glLineWidth 5
  37.     _glBegin _GL_LINES
  38.  
  39.     'circle 1
  40.     FOR u = 0 TO 29 STEP 1
  41.         _glVertex3f V(u).X, -1, V(u).Z
  42.         _glVertex3f V(u + 1).X, -1, V(u + 1).Z
  43.     NEXT
  44.     'circle 1 last area
  45.     _glVertex3f V(0).X, -1, V(0).Z
  46.     _glVertex3f V(30).X, -1, V(30).Z
  47.  
  48.  
  49.     'circle 2
  50.     FOR u = 0 TO 29 STEP 1
  51.         _glVertex3f V(u).X, 1, V(u).Z
  52.         _glVertex3f V(u + 1).X, 1, V(u + 1).Z
  53.     NEXT
  54.     'circle 2 last area
  55.     _glVertex3f V(0).X, 1, V(0).Z
  56.     _glVertex3f V(30).X, 1, V(30).Z
  57.  
  58.     'lines between circles:
  59.     f = _PI(2) / 31
  60.     FOR i2 = 0 TO 30
  61.         _glVertex3f V(i2).X, 1, V(i2).Z
  62.         _glVertex3f COS((i2 * f) + roto) * 3, -1, SIN((i2 * f) + roto) * 3
  63.     NEXT
  64.     roto = roto + .3
  65.     _glEnd
  66.  

Code: QB64: [Select]
  1. _TITLE "Elliptic Hyperboloid"
  2. SCREEN _NEWIMAGE(1024, 768, 32)
  3.  
  4. TYPE V3D
  5.     X AS SINGLE
  6.     Z AS SINGLE
  7.  
  8. DIM SHARED V(30) AS V3D
  9. 'create points for circle:
  10. FOR c = 0 TO _PI(2) STEP _PI(2) / 31
  11.     V(i).X = SIN(c) * 3
  12.     V(i).Z = COS(c) * 3
  13.     i = i + 1
  14.  
  15.     _LIMIT 30
  16.  
  17. SUB _GL ()
  18.  
  19.     _glMatrixMode _GL_PROJECTION
  20.     _gluPerspective 50, 1, 0.1, 100
  21.  
  22.     _glMatrixMode _GL_MODELVIEW
  23.     a = 1
  24.     b = 1
  25.     c = 1
  26.     STATIC rotY
  27.     _glTranslatef 0, 0, -15
  28.     _glRotatef rotY, 1, 0, 0
  29.     _glRotatef rotY, 0, 1, 0
  30.  
  31.     rotY = rotY + .5
  32.  
  33.  
  34.  
  35.     '    _glPointSize 2
  36.     _glLineWidth 5
  37.     _glBegin _GL_LINES
  38.  
  39.     'circle 1
  40.     FOR u = 0 TO 29 STEP 1
  41.         _glVertex3f V(u).X, -5, V(u).Z
  42.         _glVertex3f V(u + 1).X, -5, V(u + 1).Z
  43.     NEXT
  44.     'circle 1 last area
  45.     _glVertex3f V(0).X, -5, V(0).Z
  46.     _glVertex3f V(30).X, -5, V(30).Z
  47.  
  48.  
  49.     'circle 2
  50.     FOR u = 0 TO 29
  51.         _glVertex3f V(u).X, 5, V(u).Z
  52.         _glVertex3f V(u + 1).X, 5, V(u + 1).Z
  53.     NEXT
  54.     'circle 2 last area
  55.     _glVertex3f V(0).X, 5, V(0).Z
  56.     _glVertex3f V(30).X, 5, V(30).Z
  57.  
  58.     'lines between circles:
  59.     f = _PI(2) / 31
  60.     FOR i2 = 0 TO 30
  61.         _glVertex3f V(i2).X, 5, V(i2).Z
  62.         _glVertex3f COS((i2 * f) + roto) * 3, -5, SIN((i2 * f) + roto) * 3
  63.     NEXT
  64.     roto = roto + .3
  65.     _glEnd
  66.  
« Last Edit: April 18, 2020, 12:48:43 pm by Petr »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: elliptic hyperboloid
« Reply #32 on: April 18, 2020, 01:10:26 pm »
Thanks Petr, according to this video you can can both:

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: elliptic hyperboloid
« Reply #33 on: April 18, 2020, 03:29:39 pm »
It's a popular design for TV towers, like the Canton Tower. 
Also used for a lighthouse in 1910.

It also looks like the Holy Grail.  I offerred Ashish a shrubbery
for it.

The Canton Tower looks like an upside down golf tee to me, but thanks for posting a real-life architectural example. Hey, maybe if I can buy it, flip it, and put the Times square New Years Eve Ball on top of it, I can finally get the Jolly Green Giant to pay me a Jolly green greens fee for a round of golf.

I forgot to wipe the IDE when I did this. It combined the code contributed by Petr and Ashish. I didn't even realize that, until I ran the routine.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1024, 768, 256)
  2. x = _WIDTH / 2
  3. y = _HEIGHT / 2
  4. radiusX = 50
  5. radiusY = 50
  6.  
  7. CIRCLE (x, y), 10
  8.  
  9.  
  10. DO UNTIL angle = 360
  11.  
  12.     angle = angle + 1
  13.     t = _D2R(angle)
  14.  
  15.     '    Pt.x = x * COS(t) - y * SIN(t)
  16.     '    Pt.y = x * SIN(t) + y * COS(t)
  17.  
  18.     Pt.x = x + COS(t) * radiusX
  19.     Pt.y = y + SIN(t) * radiusY
  20.  
  21.     CIRCLE (Pt.x, Pt.y), 10
  22.     _LIMIT 100
  23.  
  24.  
  25. PRINT "Press key..."
  26.  
  27. radiusX = 75
  28. radiusY = 25
  29.  
  30.  
  31.     angle = 0
  32.     DO UNTIL angle = 360
  33.         a2 = a2 + _D2R(15) 'rotate up to 15 degrees
  34.  
  35.         angle = angle + 360 / 20
  36.         t = _D2R(angle)
  37.         t2 = _D2R(angle + 360 / 20)
  38.         DO WHILE _MOUSEINPUT
  39.             an3 = an3 + _MOUSEWHEEL
  40.         LOOP
  41.         a3 = _D2R(an3)
  42.  
  43.         'ellipse 1
  44.         Pt.x = _MOUSEX + COS(t + a2) * radiusX
  45.         Pt.y = _MOUSEY + SIN(t + a2) * radiusY
  46.  
  47.         'ellipse 2
  48.         Pt.x2 = x + COS(t + a2 + a3) * radiusX
  49.         Pt.y2 = y + SIN(t + a2 + a3) * radiusY
  50.  
  51.  
  52.         '   PSET (Pt.x, Pt.y)
  53.         '   PSET (Pt.x2, Pt.y2), 14
  54.  
  55.         LINE (Pt.x, Pt.y)-(Pt.x2, Pt.y2)
  56.  
  57.  
  58.         'for ellipse1 circuit:
  59.         Pt.x3 = _MOUSEX + COS(t2 + a2) * radiusX
  60.         Pt.y3 = _MOUSEY + SIN(t2 + a2) * radiusY
  61.  
  62.  
  63.         'for ellipse2 circuit:
  64.         Pt.x4 = x + COS(t2 + a2 + a3) * radiusX
  65.         Pt.y4 = y + SIN(t2 + a2 + a3) * radiusY
  66.  
  67.         'draw elipses circuit
  68.         LINE (Pt.x3, Pt.y3)-(Pt.x, Pt.y), 9
  69.         LINE (Pt.x4, Pt.y4)-(Pt.x2, Pt.y2), 10
  70.  
  71.     LOOP
  72.     _DISPLAY
  73.     _LIMIT 25
  74.     CLS
  75.  
  76.  
  77. _TITLE "Elliptic Hyperboloid"
  78. SCREEN _NEWIMAGE(600, 600, 32)
  79.  
  80.     _LIMIT 30
  81.  
  82. SUB _GL ()
  83.     'using parametric equations
  84.     'x(u,v) = a*sqrt(1+u^2)*cos(v)
  85.     'y(u,v)=b*sqrt(1+u^2)*sin(v)
  86.     'z(u,v)=c*u
  87.     'for v in [0, 2ã]
  88.     'from https://mathworld.wolfram.com/EllipticHyperboloid.html
  89.  
  90.     _glMatrixMode _GL_PROJECTION
  91.     _gluPerspective 50, 1, 0.1, 100
  92.  
  93.     _glMatrixMode _GL_MODELVIEW
  94.     a = 1
  95.     b = 1
  96.     c = 1
  97.     STATIC rotY
  98.     _glTranslatef 0, 0, -10
  99.     _glRotatef rotY, 0, 1, 0
  100.     rotY = rotY + 1
  101.  
  102.     _glPointSize 2
  103.     _glBegin _GL_POINTS
  104.     FOR u = 0 TO 3 STEP 0.1
  105.         FOR v = 0 TO _PI(2) STEP 0.1
  106.             x = a * SQR(1 + u ^ 2) * COS(v)
  107.             y = c * u
  108.             z = b * SQR(1 + u ^ 2) * SIN(v) 'you see, I swap the expression for y and z 'cause in 3D graphics, Y-axis upward
  109.  
  110.             _glVertex3f x, y, z
  111.             _glVertex3f x, -y, z 'creating mirror image
  112.         NEXT
  113.     NEXT
  114.     _glEnd
  115.  

Anyway, I get the feeling the O.P. can't use the GL example, because it is calling internal functions, which he wouldn't be able to explain. There should be ways to draw this out along a 2-D x,y,z projection axis I liked Vince's parallel projection code. I modified it just a bit to draw one line at a time. Very cool...

Code: QB64: [Select]
  1. pi = 4 * ATN(1)
  2. sw = 640
  3. sh = 480
  4.  
  5.  
  6. t = t + 0.05
  7. a = 0
  8. b = pi * COS(t) / 3
  9. ox = 120 * COS(a - b)
  10. oz = 120 * SIN(a - b)
  11. oy = -150
  12. oxx = 120 * COS(a + b)
  13. ozz = 120 * SIN(a + b)
  14. oyy = 150
  15. LINE (0, 0)-(sw, sh), 0, BF
  16. FOR a = 2 * pi / 30 TO 2 * pi STEP 2 * pi / 30
  17.     x = 120 * COS(a - b)
  18.     z = 120 * SIN(a - b)
  19.     y = -150
  20.     LINE (sw / 2 + ox + 0.707 * oz, sh / 2 + oy + 0.707 * oz)-(sw / 2 + x + 0.707 * z, sh / 2 + y + 0.707 * z)
  21.     ox = x
  22.     oy = y
  23.     oz = z
  24.  
  25.     x = 120 * COS(a + b)
  26.     z = 120 * SIN(a + b)
  27.     y = 150
  28.     LINE -(sw / 2 + x + 0.707 * z, sh / 2 + y + 0.707 * z)
  29.     LINE -(sw / 2 + oxx + 0.707 * ozz, sh / 2 + oyy + 0.707 * ozz)
  30.     oxx = x
  31.     oyy = y
  32.     ozz = z
  33.     SLEEP
  34.  


Pete

I have a mind like a steel trap. Once it's shut, nothing gets in!
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline ngr888

  • Newbie
  • Posts: 5
    • View Profile
Re: elliptic hyperboloid
« Reply #34 on: April 19, 2020, 02:40:40 pm »
put a string or wire through holes and tie to make circle, then angle them all in same direction.


Much better than strings or wires, for a studio model it is to use rubbers. The 3 axis flexibility is very instructive.

The use of rubbers for the edges would allow the construction to be manipulated so that the 'bases' were more or less separated.
As well as that those bases were not parallel, originating lateral surfaces with different parabolas.
(Sorry, it is difficult to explain without the support of a couple of drawings, but I still do not know how to add them to my post.)
« Last Edit: April 19, 2020, 03:40:31 pm by ngr888 »

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: elliptic hyperboloid
« Reply #35 on: April 19, 2020, 08:59:38 pm »
Ok, last one from me, this is an exact clone of that video minus some minor perspective and proportion adjustment

Code: [Select]
dim shared pi, sw, sh
pi = 4*atn(1)
sw = 640
sh = 480

rr = 500
h = 1200

screen 12

do
        for t=0 to h step 10
                line (0,0)-(sw,sh),0,bf
                hyperb rr, t, 0, 0

                _display
                _limit 100
        next

        for b=0 to 0.80*pi/2 step 0.008
                line (0,0)-(sw,sh),0,bf
                hyperb rr, h, b, 0

                _display
                _limit 100
        next

        _delay 0.5

        for rot = 0 to 0.9*pi/2 step 0.01
                line (0,0)-(sw,sh),0,bf
                hyperb rr, h, 0.80*pi/2, rot

                _display
                _limit 100
        next

        _delay 0.5

        for i=0 to 1 step 0.005
                line (0,0)-(sw,sh),0,bf
                hyperb rr, h, (1 - i)*0.80*pi/2, (1 - i)*0.9*pi/2

                _display
                _limit 100
        next

        for t=0 to h step 10
                line (0,0)-(sw,sh),0,bf
                hyperb rr, h-t, 0, 0

                _display
                _limit 100
        next
loop
system

'radius, height, twist, rotate
sub hyperb (r, h, b, rot)
        a = 0
        x = r*cos(a - b)
        z = r*sin(a - b)
        y = -h/2 + 200

        yy = y*cos(rot) - z*sin(rot)
        zz = y*sin(rot) + z*cos(rot)
        y = yy
        z = zz

        ox = x
        oz = z
        oy = y


        x = r*cos(a + b)
        z = r*sin(a + b)
        y = h/2 + 200

        yy = y*cos(rot) - z*sin(rot)
        zz = y*sin(rot) + z*cos(rot)
        y = yy
        z = zz

        oxx = x
        oyy = y
        ozz = z


        for a = 2*pi/30 to 2*pi step 2*pi/30
                x = r*cos(a - b)
                z = r*sin(a - b)
                y = -h/2 + 200

                yy = y*cos(rot) - z*sin(rot)
                zz = y*sin(rot) + z*cos(rot)
                y = yy
                z = zz

                pset  (sw/2 + ox*700/(oz + 2500), sh/2 - 50 + oy*700/(oz + 2500))
                line -(sw/2 +  x*700/( z + 2500), sh/2 - 50 +  y*700/( z + 2500))

                ox = x
                oy = y
                oz = z


                x = r*cos(a + b)
                z = r*sin(a + b)
                y = h/2 + 200

                yy = y*cos(rot) - z*sin(rot)
                zz = y*sin(rot) + z*cos(rot)
                y = yy
                z = zz

                line -(sw/2 +   x*700/(  z + 2500), sh/2 - 50 +   y*700/(  z + 2500))
                line -(sw/2 + oxx*700/(ozz + 2500), sh/2 - 50 + oyy*700/(ozz + 2500))

                oxx = x
                oyy = y
                ozz = z
        next
end sub


edit: fixed
« Last Edit: April 19, 2020, 09:35:51 pm by _vince »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: elliptic hyperboloid
« Reply #36 on: April 19, 2020, 09:50:06 pm »
--------->APPLAUSE<--------
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: elliptic hyperboloid
« Reply #37 on: April 20, 2020, 10:00:37 am »
Perfect!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: elliptic hyperboloid
« Reply #38 on: April 20, 2020, 12:10:21 pm »
Yep, nailed it.