QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: solomon on April 17, 2020, 03:37:10 am

Title: elliptic hyperboloid
Post by: solomon on April 17, 2020, 03:37:10 am
Hi everyone, I don't know how to write this code, can you help? this topic my homework. I need it very fast :(

[odin edit]: restored solomon's original post, so as not to make following replies sound out of context.
Title: Re: elliptic hyperboloid
Post by: Pete on April 17, 2020, 04:34:33 am
Multi-variable calculus. Where's Bill when we need him? Oh well, I'll guess something like:

x^2  + y^2 / 4 - z^2 / 9 = 1
Title: Re: elliptic hyperboloid
Post by: FellippeHeitor on April 17, 2020, 07:28:55 am
We don’t write homework for people, sorry.

If you already have some code you’re working on and need help with it, post it here and we can assist you.

Welcome to the forum.
Title: Re: elliptic hyperboloid
Post by: Ashish on April 17, 2020, 07:40:07 am
If you just need code for your homework, never mention it is your homework.
Title: Re: elliptic hyperboloid
Post by: FellippeHeitor on April 17, 2020, 07:46:33 am
If you need code for your homework, never try to fish for someone to do it for you at the last minute. How about paying attention to class?
Title: Re: elliptic hyperboloid
Post by: Ashish on April 17, 2020, 08:09:51 am
You have given no description of what the program needs to do. You need to draw it? or Solve for third variable when given value of other two?
Title: Re: elliptic hyperboloid
Post by: solomon on April 17, 2020, 08:49:11 am
Hello, I'm sorry, I am an architect student and I have never taken a code lesson during my education life. but firstly this semester I had 3 hours of lesson. and the corona virus appeared and lessons were canceled. so I asked for help. It was misunderstood. I'm doing a trial course. I will load what I tried.
Title: Re: elliptic hyperboloid
Post by: TerryRitchie on April 17, 2020, 09:40:11 am
Forum members are more than willing to help steer you in the right direction where homework is concerned. What we need to see is the code you have written so far on your own. Also, at a minimum, you should be able to supply the math equation(s) needed to calculate your outcome.

Welcome to the forum by the way :-)
Title: Re: elliptic hyperboloid
Post by: Ashish on April 17, 2020, 10:38:07 am
Is this what you looking for @solomon ?


  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: elliptic hyperboloid
Post by: SMcNeill on April 17, 2020, 10:42:53 am
Is this what you looking for @solomon ?


  [ This attachment cannot be displayed inline in 'Print Page' view ]

If not, it should be.  That's rather impressive looking!  ;D
Title: Re: elliptic hyperboloid
Post by: solomon on April 17, 2020, 10:51:54 am
form like that;


I tried a code for this shape and added
Title: Re: elliptic hyperboloid
Post by: solomon on April 17, 2020, 11:01:20 am
I don't know how to do the rotation code. I just tried to draw ellipse.
Title: Re: elliptic hyperboloid
Post by: solomon on April 17, 2020, 11:03:57 am
Could the rotation code be like this?
Title: Re: elliptic hyperboloid
Post by: Ashish on April 17, 2020, 11:07:24 am
It can be done in OpenGL easily BUT I will wait for @STxAxTIC
I think he is the only one who is going to help you and make you understand the things.
Title: Re: elliptic hyperboloid
Post by: bplus on April 17, 2020, 11:48:49 am
form like that;


I tried a code for this shape and added

Man the past week I have been admiring that design in a TV commercial. Great as fancy table stand or for holding bowls.

Take a bunch of dowels drill holes through center or some other length, put a string or wire through holes and tie to make circle, then angle them all in same direction. I just tested with 4 pencils and pens and scotch tape.

@Ashish, nice graphic!
Title: Re: elliptic hyperboloid
Post by: Pete on April 17, 2020, 12:02:36 pm
It can be done in OpenGL easily BUT I will wait for @STxAxTIC
I think he is the only one who is going to help you and make you understand the things.

What? My equation needs Bill (STxAxTIC) to be explained? Oh wait, that's what I said. :D Yeah, it would be nice to have Bill chime in. What the hell though. I took 4 years of mechanical and architectural drawing in high school,  and never once did some dumbass instructor ask me to design a wormhole!

Pete
Title: Re: elliptic hyperboloid
Post by: _vince on April 17, 2020, 01:12:12 pm
parallel projection is easiest

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.         next
  34.  
  35.         _display
  36.         _limit 10
  37.  
  38.  
  39.  

Code: QB64: [Select]
  1. pi = 4*atn(1)
  2. sw = 640
  3. sh = 480
  4.  
  5.  
  6.         c = c + 0.05
  7.         t = t + 0.05
  8.         a = 0
  9.         b = pi*cos(t)/3
  10.         x = 250*cos(a - b)
  11.         z = 100*sin(a - b)
  12.         y = -150
  13.         yy = y*cos(c) - z*sin(c)
  14.         zz = y*sin(c) + z*cos(c)
  15.         y = yy
  16.         z = zz
  17.         ox = x
  18.         oz = z
  19.         oy = y
  20.  
  21.         x = 250*cos(a + b)
  22.         z = 100*sin(a + b)
  23.         y = 150
  24.         yy = y*cos(c) - z*sin(c)
  25.         zz = y*sin(c) + z*cos(c)
  26.         y = yy
  27.         z = zz
  28.         oxx = x
  29.         ozz = z
  30.         oyy = y
  31.         line (0,0)-(sw,sh),0,bf
  32.         for a=2*pi/30 to 2*pi step 2*pi/30
  33.                 x = 250*cos(a - b)
  34.                 z = 100*sin(a - b)
  35.                 y = -150
  36.  
  37.                 yy = y*cos(c) - z*sin(c)
  38.                 zz = y*sin(c) + z*cos(c)
  39.                 y = yy
  40.                 z = zz
  41.                 line (sw/2 + ox + 0.507*oz, sh/2 + oy + 0.507*oz)-(sw/2 + x + 0.507*z, sh/2 + y + 0.507*z)
  42.                 ox = x
  43.                 oy = y
  44.                 oz = z
  45.  
  46.                 x = 250*cos(a + b)
  47.                 z = 100*sin(a + b)
  48.                 y = 150
  49.  
  50.                 yy = y*cos(c) - z*sin(c)
  51.                 zz = y*sin(c) + z*cos(c)
  52.                 y = yy
  53.                 z = zz
  54.  
  55.                 line -(sw/2 + x + 0.507*z, sh/2 + y + 0.507*z)
  56.                 line -(sw/2 + oxx + 0.507*ozz, sh/2 + oyy + 0.507*ozz)
  57.                 oxx = x
  58.                 oyy = y
  59.                 ozz = z
  60.         next
  61.  
  62.         _display
  63.         _limit 10
  64.  
  65.  
  66.  
  67.  
Title: Re: elliptic hyperboloid
Post by: Petr on April 17, 2020, 04:46:37 pm
_vince, that's a great piece of code!
Title: Re: elliptic hyperboloid
Post by: TerryRitchie on April 17, 2020, 05:52:20 pm
I envy those of you (looking at you vince, static, bplus) that can whip out math equations like this. I'm stuck in Flatland I guess.
Title: Re: elliptic hyperboloid
Post by: STxAxTIC on April 17, 2020, 06:43:02 pm
Sorry I'm late to the party. Is solomon's question basically answered at this point? Nice work @_vince and @Ashish.

There are clearly two different approaches going on here. I can add a third (basically modifying Sanctum.bas to have the shape requested), but then the math behind the projection itself is harder to explain than any paraboloid.

What *exactly* is being asked, solomon? (I got your private message about this but lets carry on openly.)
Title: Re: elliptic hyperboloid
Post by: solomon on April 18, 2020, 03:19:16 am
I am trying to draw elliptical hyperboloid using ellipse code in this code. I tried to define two ellipses. I don't know how successful it is. I am trying. but I think these ellipses have to turn. as in the video I added. but I can't find how these ellipses will rotate in the code section.

I will also assign the scr file of this code to the AUTOCAD drawing program. and I'll see the shape there.






@STxAxTIC, @_vince, @Petr
Title: Re: elliptic hyperboloid
Post by: solomon on April 18, 2020, 03:26:06 am
@STxAxTIC
I have beginner level knowledge and I have to draw this shape according to the code information I have.
also

Rotation algorithm:

Let there be a point P (x, y) in the plane. If we rotate this point counterclockwise around the origin by an angle of t (Theta), that point will come to the point Pt.
The coordinates of the Pt point are found as follows:
Pt.x = x * cos (t) - y * sin (t)
and
Pt.y = x * sin (t) + y * cos (t)

Code: QB64: [Select]
  1. TYPE point3d
  2.     x AS SINGLE
  3.     y AS SINGLE
  4.     z AS SINGLE
  5.  
  6. TYPE Elips
  7.     Center AS point3d
  8.     A AS SINGLE
  9.     B AS SINGLE
  10.  
  11. DIM elip AS Elips
  12. PRINT "please define elips:"
  13. INPUT "Elips Center (x, y): ", elip.Center.x, elip.Center.y
  14. INPUT "Elips 'A': ", elip.A
  15. INPUT "Elips 'B': ", elip.B
  16.  
  17. INPUT "Vertex number: ", n
  18.  
  19. OPEN "C:\scr\deneme2.scr" FOR OUTPUT AS #1
  20.  
  21.  
  22. CONST pi = 4 * ATN(1)
  23. dt = 2 * pi / n
  24.  
  25. DIM ElipsKoor(1 TO n) AS point3d
  26. FOR d = 1 TO n
  27.     t = (d - 1) * dt
  28.     r = Elips_R(elip.A, elip.B, t)
  29.  
  30.     DIM v AS point3d
  31.     v.z = 0
  32.     v.x = elip.Center.x + r * COS(t)
  33.     v.y = elip.Center.y + r * SIN(t)
  34.     ElipsKoor(d) = v
  35.  
  36.  
  37. INPUT "Elliptic hyperboloid height: ", h
  38.  
  39. DIM elip2 AS Elips
  40. PRINT "Please elip2 define:"
  41. INPUT "Elips2 Center (x, y): ", elip2.Center.x, elip2.Center.y
  42. INPUT "Elips 'A': ", elip2.A
  43. INPUT "Elips 'B': ", elip2.B
  44.  
  45. DIM Elips2Koor(1 TO n) AS point3d
  46. FOR k = 1 TO n
  47.     t2 = (k - 1) * dt
  48.     r2 = Elips_R(elip2.A, elip2.B, t)
  49.  
  50.     DIM v2 AS point3d
  51.     v2.z = h
  52.     v2.x = elip2.Center.x + r * COS(t2)
  53.     v2.y = elip2.Center.y + r * SIN(t2)
  54.  
  55.  
  56.  
  57. FOR d = 1 TO n
  58.     sv = d + 1
  59.     IF d = n THEN sv = 1
  60.     Write3DFace3 ElipsKoor(d), ElipsKoor(sv), Elip2Koor(k), Elip2Koor(sv)
  61.  
  62.  
  63. FUNCTION Elips_R (a AS SINGLE, b AS SINGLE, t AS SINGLE)
  64.     Elips_R = (a * b) / SQR((b * COS(t)) ^ 2 + (a * SIN(t)) ^ 2)
  65.  
  66.  
  67. SUB Write3DFace3 (v1 AS point3d, v2 AS point3d, v3 AS point3d)
  68.     PRINT #1, "3DFace"
  69.     WRITE #1, v1.x, v1.y, v1.z
  70.     WRITE #1, v2.x, v2.y, v2.z
  71.     WRITE #1, v3.x, v3.y, v3.z
  72.     PRINT #1, ""
  73.     PRINT #1, ""
  74.  
  75. SUB Write3DFace (v1 AS point3d, v2 AS point3d, v3 AS point3d, v4 AS point3d)
  76.     PRINT #1, "3DFace"
  77.     WRITE #1, v1.x, v1.y, v1.z
  78.     WRITE #1, v2.x, v2.y, v2.z
  79.     WRITE #1, v3.x, v3.y, v3.z
  80.     WRITE #1, v4.x, v4.y, v4.z
  81.     PRINT #1, ""
  82.     PRINT #1, ""
  83.  
  84. SUB WriteLine (v1 AS point3d, v2 AS point3d)
  85.     PRINT #1, "Line"
  86.     WRITE #1, v1.x, v1.y, v1.z
  87.     WRITE #1, v2.x, v2.y, v2.z
  88.     PRINT #1, ""
  89.  
  90.  
Title: Re: elliptic hyperboloid
Post by: Richard Frost on April 18, 2020, 04:22:34 am
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.

Title: Re: elliptic hyperboloid
Post by: Petr on April 18, 2020, 05:58:50 am
Hi. Maybe this easy program help you.

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.  

Use mousewheel to set points displacement in ellipse 2 and mouse.
Title: Re: elliptic hyperboloid
Post by: Ashish on April 18, 2020, 09:54:26 am
Amazing work @_vince and @Petr
Petr, when you have learned 3D maths?
Title: Re: elliptic hyperboloid
Post by: Ashish on April 18, 2020, 10:06:29 am
Here is my lazy approach.

Code: QB64: [Select]
  1. _TITLE "Elliptic Hyperboloid"
  2. SCREEN _NEWIMAGE(600, 600, 32)
  3.  
  4.     _LIMIT 30
  5.  
  6. SUB _GL ()
  7.     'using parametric equations
  8.     'x(u,v) = a*sqrt(1+u^2)*cos(v)
  9.     'y(u,v)=b*sqrt(1+u^2)*sin(v)
  10.     'z(u,v)=c*u
  11.     'for v in [0, 2ã]
  12.     'from https://mathworld.wolfram.com/EllipticHyperboloid.html
  13.  
  14.     _glMatrixMode _GL_PROJECTION
  15.     _gluPerspective 50, 1, 0.1, 100
  16.  
  17.     _glMatrixMode _GL_MODELVIEW
  18.     a = 1
  19.     b = 1
  20.     c = 1
  21.     STATIC rotY
  22.     _glTranslatef 0, 0, -10
  23.     _glRotatef rotY, 0, 1, 0
  24.     rotY = rotY + 1
  25.  
  26.     _glPointSize 2
  27.     _glBegin _GL_POINTS
  28.     FOR u = 0 TO 3 STEP 0.1
  29.         FOR v = 0 TO _PI(2) STEP 0.1
  30.             x = a * SQR(1 + u ^ 2) * COS(v)
  31.             y = c * u
  32.             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
  33.  
  34.             _glVertex3f x, y, z
  35.             _glVertex3f x, -y, z 'creating mirror image
  36.         NEXT
  37.     NEXT
  38.     _glEnd
  39.  
Title: Re: elliptic hyperboloid
Post by: STxAxTIC on April 18, 2020, 10:46:58 am
Solomon I see your private messages -

I still find the whole issue ambiguous, to be honest - because plotting general 3D shapes is not natural in QB64 without _GL tech. Do you need just a *particular* projection of the shape you need, or *any* projection? Is it required that you use QB64 for this? Why not gnuplot? We need specifics if you've got them. Also: can you give some feedback as to whether the good gentlemen above have gotten near the solution you need? Plenty of good code up there.
Title: Re: elliptic hyperboloid
Post by: solomon on April 18, 2020, 10:57:16 am
unfortunately the program I should use is qb64. I think it is not natural to limit it, but I have to come to the conclusion with the data I have. I'm sorry to say that I can't give feedback because I don't understand most of them. I really thank everyone who has worked. I try to reach the result around what I know. I think I cannot draw this form with the code I tried.

@Ashish and @_vince e thanx a lot, really good shape and turning :)
@Petr thanx :) I guess this shape is torus?

but what I want to tell before returning is
The ellipse forming the elliptical hyperboloid rotate and form the elliptic hyperboloid.
that is, the rotation in the formation of the shape.

When I run the shape, it doesn't need to rotate.
Title: Re: elliptic hyperboloid
Post by: bplus on April 18, 2020, 11:25:23 am
Nice work _vince, Petr, Ashish. Petr seems really close to duplicating video so with _vince nice rotation but...

What is confusing to me is that it looks from video like the top and bottom are circles like Ashish has, not ellipse, this is made obvious when towards end the object is rotated on x axis so you see the circular face and the smaller circle of the "neck".
Title: Re: elliptic hyperboloid
Post by: _vince on April 18, 2020, 11:41:04 am
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.

And 5G cooling towers as well!
https://en.wikipedia.org/wiki/Cooling_tower (https://en.wikipedia.org/wiki/Cooling_tower)
Title: Re: elliptic hyperboloid
Post by: STxAxTIC on April 18, 2020, 12:14:42 pm
5G... jfc lol
Title: Re: elliptic hyperboloid
Post by: Petr 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.  
Title: Re: elliptic hyperboloid
Post by: bplus on April 18, 2020, 01:10:26 pm
Thanks Petr, according to this video you can can both:
Title: Re: elliptic hyperboloid
Post by: Pete 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!
Title: Re: elliptic hyperboloid
Post by: ngr888 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.)
Title: Re: elliptic hyperboloid
Post by: _vince 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
Title: Re: elliptic hyperboloid
Post by: Pete on April 19, 2020, 09:50:06 pm
--------->APPLAUSE<--------
Title: Re: elliptic hyperboloid
Post by: Petr on April 20, 2020, 10:00:37 am
Perfect!
Title: Re: elliptic hyperboloid
Post by: bplus on April 20, 2020, 12:10:21 pm
Yep, nailed it.