Author Topic: Double Pendulum Studies  (Read 2180 times)

0 Members and 1 Guest are viewing this topic.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
Re: Double Pendulum Studies
« Reply #15 on: March 18, 2022, 02:08:25 pm »
My God! :))  Fill your pdf with amazement!(translation error? amazes me) Unfortunately, I do not understand the interpretation of advanced algebra. I can’t wait to see the movement of N arms on the screen work. In the meantime, I’m also wondering how this could be easiest. Good luck, I hope we can see the program work as soon as possible !!!

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
Re: Double Pendulum Studies
« Reply #16 on: March 18, 2022, 03:11:39 pm »
By the way - there is a completely different approach to doing rigid body motion.

https://qb64forum.alephc.xyz/index.php?topic=3837.msg131887#msg131887

It uses a bunch of matrix algebra but a Newtonian method, not a Lagrangian one. Pretty good stuff though.
You're not done when it works, you're done when it's right.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
Re: Double Pendulum Studies
« Reply #17 on: March 19, 2022, 02:29:19 am »
REDACTED
« Last Edit: April 13, 2022, 09:35:28 am by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
Re: Double Pendulum Studies
« Reply #18 on: March 19, 2022, 10:53:19 am »
Ah, hold on there sparky, the "Press any key for next case." is broken. Any key pressed results in an exit. Now the first example works as expected. The modification to the effect, however, is quite impressive. This is probably just a small glitch in the transformation process. Wish I could understand the math. It's a bit over my head, but it sure feels nice.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
Re: Double Pendulum Studies
« Reply #19 on: March 19, 2022, 03:21:24 pm »
I still didn’t delve into the math part. works fantastic with 3 wrists! Will I need to write a control for N joints separately? one for each?

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
Re: Double Pendulum Studies
« Reply #20 on: March 20, 2022, 08:20:38 am »
I was thinking of a different approach. The way you calculate it is too complicated for me. I was wondering what if the masses only had a vector. No other. Strength and direction. An inertia. How that would change would determine what it connects to. The distances need to be somewhat flexible, so you don’t necessarily have to calculate with just one huge calculation who is exactly where. For now, it works with these values. I try to take the elasticity as low as possible, the length of the ropes will always be fixed (apparently). This will have the effect of being like a pendulum like yours.

Obj_c is the number of bullets. The obj array contains the position, vector.
The conn array contains the connections. For example.
conn (x, 0) index obj connected to conn (x, 1) obj, rope of conn (x, 2) length

Code: QB64: [Select]
  1. CONST pip180 = 3.141592 / 180
  2. monx = 800: mony = 600: mon = _NEWIMAGE(monx, mony, 32): SCREEN mon
  3.  
  4. gravity = 1
  5. obj_c = 10 'number objects
  6. DIM obj(obj_c - 1, 9) '0,1 posX,Y 3fix/mover
  7. rad = 10 'circle rad
  8.  
  9.  
  10. cent_x = monx / 2: cent_y = 20: zoom = .05
  11.  
  12.  
  13. 'objects location
  14. FOR a = 1 TO obj_c - 1
  15.     obj(a, 0) = (RND(1) - .5) * 10000
  16.     obj(a, 1) = (RND(1) - .5) * 5000
  17.     obj(a, 3) = 1 '<---- 0 if fix, 1 if fly
  18.  
  19. 'connections
  20. conn_c = obj_c - 1: DIM conn(conn_c - 1, 2)
  21. FOR a = 0 TO conn_c - 1
  22.     conn(a, 0) = a: conn(a, 1) = a + 1
  23.     conn(a, 2) = 30 'rope width
  24.  
  25.  
  26. DO: _LIMIT 100: IF INKEY$ = CHR$(27) THEN END
  27.     'draw objects
  28.     FOR a = 0 TO obj_c - 1
  29.         x = cent_x + obj(a, 0) * zoom
  30.         y = cent_y + obj(a, 1) * zoom
  31.         IF mouse_near = a THEN COLOR _RGB32(255, 0, 0) ELSE COLOR _RGB32(200, 200, 200)
  32.         CIRCLE (x, y), rad
  33.         _PRINTSTRING (x, y), LTRIM$(STR$(a))
  34.     NEXT a
  35.  
  36.     'draw connections
  37.     COLOR _RGB32(150, 150, 150)
  38.     FOR a = 0 TO conn_c - 1:
  39.         x1 = obj(conn(a, 0), 0) * zoom + cent_x
  40.         y1 = obj(conn(a, 0), 1) * zoom + cent_y
  41.         x2 = obj(conn(a, 1), 0) * zoom + cent_x
  42.         y2 = obj(conn(a, 1), 1) * zoom + cent_y
  43.     LINE (x1, y1)-(x2, y2): NEXT a
  44.  
  45.     'calculate moving
  46.     FOR a = 0 TO obj_c - 1: IF obj(a, 3) = 0 OR (mouse_near = a AND _MOUSEBUTTON(1)) THEN _CONTINUE
  47.  
  48.         'connections vector
  49.         vec_x = 0: vec_y = 0: vec_c = 0
  50.         FOR t = 0 TO conn_c - 1: x = -1: FOR t2 = 0 TO 1: IF conn(t, t2) = a THEN x = conn(t, t2 XOR 1)
  51.             NEXT t2
  52.             IF x <> -1 THEN
  53.                 disx = obj(a, 0) - obj(x, 0)
  54.                 disy = obj(a, 1) - obj(x, 1)
  55.                 ang = (-degree(disx, disy) + 0) * pip180
  56.                 dis = SQR(disx * disx + disy * disy)
  57.                 power = ABS(dis - conn(t, 2)) / 70
  58.                 vec_x = vec_x + SIN(ang) * power
  59.                 vec_y = vec_y - COS(ang) * power
  60.                 vec_c = vec_c + 1
  61.             END IF
  62.         NEXT t
  63.  
  64.         obj(a, 4) = (obj(a, 4) + vec_x / vec_c) * .99
  65.         obj(a, 5) = (obj(a, 5) + vec_y / vec_c + gravity) * .99
  66.         obj(a, 0) = obj(a, 0) + obj(a, 4)
  67.         obj(a, 1) = obj(a, 1) + obj(a, 5)
  68.  
  69.     NEXT a
  70.  
  71.  
  72.     'mouse moving activing
  73.     IF moving = 0 THEN
  74.         mouse_near = -1
  75.         FOR a = 0 TO obj_c - 1
  76.             disx = (cent_x + obj(a, 0) * zoom) - _MOUSEX
  77.             disy = (cent_y + obj(a, 1) * zoom) - _MOUSEY
  78.             dis = SQR(disx * disx + disy * disy)
  79.             IF dis < 10 THEN mouse_near = a
  80.         NEXT a
  81.     END IF
  82.  
  83.     IF (_MOUSEBUTTON(1) AND mouse_near <> -1) OR moving THEN
  84.         moving = 1
  85.         obj(mouse_near, 0) = (_MOUSEX - cent_x) / zoom
  86.         obj(mouse_near, 1) = (_MOUSEY - cent_y) / zoom
  87.     END IF
  88.  
  89.     moving = moving AND _MOUSEBUTTON(1)
  90.  
  91.     LOCATE 1, 1: PRINT "grab the ball with the mouse and move it!"
  92.     _DISPLAY: CLS
  93.  
  94.  
  95.  
  96.  
  97.  
  98. FUNCTION degree (a, b): degreex = ATN(a / (b + .00001)) / pip180: degreex = degreex - 180 * ABS(0 > b): degreex = degreex - 360 * (degreex < 0): degree = degreex: END FUNCTION
  99.  

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
Re: Double Pendulum Studies
« Reply #21 on: March 20, 2022, 08:29:28 am »
REDACTED
« Last Edit: April 13, 2022, 09:35:33 am by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
Re: Double Pendulum Studies
« Reply #22 on: March 20, 2022, 01:12:59 pm »
Both of these last two code examples are great, but totally unrealistic. You guys are missing the Tangle Effect. This is a law of physics that states any string in motion eventually ends up as a knot. Yep, you guessed it. Pete's knot happy!

Maybe we need a computer simulation board. These are, kidding aside, very cool!

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
Re: Double Pendulum Studies
« Reply #23 on: March 20, 2022, 04:10:07 pm »
I would like to present the work of STxAxTIC. Man starts and something moves relative to something. the clock arms can be described in a few lines.

mon = _NEWIMAGE(600, 600, 32): SCREEN mon
r(0) = 12: r(1) = 60: r(2) = 60: r(3) = 100
DO
    t$ = TIME$ + ":" + RIGHT$("00" + LTRIM$(STR$(TIMER)), 2)
    x1 = _WIDTH(mon) / 2: y1 = _HEIGHT(mon) / 2
    FOR t = 0 TO 3
        ang = 360 / r(t) * VAL(MID$(t$, t * 3 + 1, 2)) * (3.141592 / 180)
        rad = (4 - t) ^ 1 * (_WIDTH(mon) * .05)
        x2 = SIN(ang) * rad + x1
        y2 = -COS(ang) * rad + y1
        LINE (x1, y1)-(x2, y2)
        x1 = x2
        y1 = y2
    NEXT t

    _DISPLAY
    CLS
LOOP





  Or something like this. Could be clarified, it is irrelevant now. I am writing an example to Bplus that there are two things here!
STxAxTIC was brave and climbed into the most cruel pots of physics. I was wondering if it could be simplified. I tried, but those results didn't come out. This cannot be achieved by "cheap" means.
  Congratulations to STxAxTIC for his patience and fanaticism for showing a great connection without neglecting the rigor of physics! Congratulations!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Double Pendulum Studies
« Reply #24 on: March 20, 2022, 04:46:39 pm »
Quote
STxAxTIC was brave and climbed into the most cruel pots of physics.

Yeah I think he might be stuck in there ;-))

Code: QB64: [Select]
  1. mon = _NewImage(600, 600, 32): Screen mon
  2. r(0) = 12: r(1) = 60: r(2) = 60: r(3) = 100
  3.     t$ = Time$ + ":" + Right$("00" + LTrim$(Str$(Timer)), 2)
  4.     x1 = _Width(mon) / 2: y1 = _Height(mon) / 2
  5.     For t = 0 To 3
  6.         ang = 360 / r(t) * Val(Mid$(t$, t * 3 + 1, 2)) * (3.141592 / 180)
  7.         rad = (4 - t) ^ 1 * (_Width(mon) * .05)
  8.         x2 = Sin(ang) * rad + x1
  9.         y2 = -Cos(ang) * rad + y1
  10.         drawPully -1, x1, y1, .1 * rad, x2, y2, .1 * (4 - (t + 1)) ^ 1 * (_Width(mon) * .05), _RGB32(255 - t * 64)
  11.         x1 = x2
  12.         y1 = y2
  13.     Next t
  14.     _Display
  15.     Cls
  16.  
  17. Sub drawPully (withCircles, x1, y1, r1, x2, y2, r2, c As _Unsigned Long)
  18.     Dim a, a1, a2, x3, x4, x5, x6, y3, y4, y5, y6
  19.     a = _Atan2(y2 - y1, x2 - x1)
  20.     a1 = a + _Pi(1 / 2)
  21.     a2 = a - _Pi(1 / 2)
  22.     x3 = x1 + r1 * Cos(a1): y3 = y1 + r1 * Sin(a1)
  23.     x4 = x1 + r1 * Cos(a2): y4 = y1 + r1 * Sin(a2)
  24.     x5 = x2 + r2 * Cos(a1): y5 = y2 + r2 * Sin(a1)
  25.     x6 = x2 + r2 * Cos(a2): y6 = y2 + r2 * Sin(a2)
  26.     Line (x3, y3)-(x5, y5), c
  27.     Line (x4, y4)-(x6, y6), c
  28.     If withCircles Then
  29.         Circle (x1, y1), r1, c
  30.         Circle (x2, y2), r2, c
  31.     End If
  32.  
  33.  
  34.  

Something wrong with 4th arm :(

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
Re: Double Pendulum Studies
« Reply #25 on: March 20, 2022, 06:02:56 pm »
Bplus, the "drawpully" is a very excellent SUB !!! :)

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
Re: Double Pendulum Studies
« Reply #26 on: March 20, 2022, 06:51:00 pm »
If only we had QB64 for the iwatch! Oh well, I think I'll wait for the digital version.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
Re: Double Pendulum Studies
« Reply #27 on: March 22, 2022, 04:34:27 pm »
REDACTED
« Last Edit: April 13, 2022, 09:35:41 am by STxAxTIC »
You're not done when it works, you're done when it's right.