Author Topic: elliptic hyperboloid  (Read 7247 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: elliptic hyperboloid
« Reply #15 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: elliptic hyperboloid
« Reply #16 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.  
« Last Edit: April 17, 2020, 01:38:51 pm by _vince »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: elliptic hyperboloid
« Reply #17 on: April 17, 2020, 04:46:37 pm »
_vince, that's a great piece of code!

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: elliptic hyperboloid
« Reply #18 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.
In order to understand recursion, one must first understand recursion.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: elliptic hyperboloid
« Reply #19 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.)
« Last Edit: April 17, 2020, 08:41:06 pm by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline solomon

  • Newbie
  • Posts: 8
    • View Profile
Re: elliptic hyperboloid
« Reply #20 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
« Last Edit: April 18, 2020, 04:56:15 am by solomon »

Offline solomon

  • Newbie
  • Posts: 8
    • View Profile
Re: elliptic hyperboloid
« Reply #21 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.  
« Last Edit: April 18, 2020, 04:37:12 am by solomon »

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: elliptic hyperboloid
« Reply #22 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.

It works better if you plug it in.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: elliptic hyperboloid
« Reply #23 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.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: elliptic hyperboloid
« Reply #24 on: April 18, 2020, 09:54:26 am »
Amazing work @_vince and @Petr
Petr, when you have learned 3D maths?
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: elliptic hyperboloid
« Reply #25 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.  
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: elliptic hyperboloid
« Reply #26 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.
You're not done when it works, you're done when it's right.

Offline solomon

  • Newbie
  • Posts: 8
    • View Profile
Re: elliptic hyperboloid
« Reply #27 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.
« Last Edit: April 18, 2020, 11:13:02 am by solomon »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: elliptic hyperboloid
« Reply #28 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".
« Last Edit: April 18, 2020, 11:30:22 am by bplus »

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: elliptic hyperboloid
« Reply #29 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