Board Logo
« Hello there is a problem »

Welcome Guest. Please Login or Register.
Jan 21st, 2018, 12:48am


Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Please use the forums Search feature before asking.
Please post code using the code box described in Format Your Messages.
This will keep indentation, separate it better form the message and prevent gibberish.
If the code is too long for one post or additional files are needed, upload a ZIP archive to the Just BASIC Files Archive Site.

« Previous Topic | Next Topic »
Pages: 1 2 3  Notify Send Topic Print
 veryhotthread  Author  Topic: Hello there is a problem  (Read 631 times)
tsh73
JB-Supporter


member is offline

Avatar




PM

Gender: Male
Posts: 3636
xx Re: Hello there is a problem
« Reply #30 on: Nov 1st, 2017, 02:48am »

Valentin,
your equilibrum condition is wrong.
Not
Quote:
(la/pa)=(lb/pb)

but moments of force are equal, that is
Quote:
(la*pa)=(lb*pb)


So let's just change '/' to '*'.
Here you are:
Code:
NOMAINWIN
    WindowWidth = 600
    WindowHeight = 400
    UpperLeftX = (DisplayWidth-WindowWidth)-200
    UpperLeftY = 20 ' (DisplayHeight-WindowHeight)
    TEXTBOX #w.pa, 50 , 50, 80, 25
    BUTTON #w.eq, "Equal", [equ], UL, 270, 50, 50, 20
    TEXTBOX #w.pb, 500 , 50, 80, 25
    TEXTBOX #w.la, 50 , 300, 80, 25
    TEXTBOX #w.lb, 500 , 300, 80, 25
    TEXTBOX #w.testa, 210 , 300, 80, 25
    TEXTBOX #w.testb, 310 , 300, 80, 25
    TEXTBOX #w.testc, 250 , 335, 80, 25
    GRAPHICBOX #w.m 5, 5, 585, 360
    OPEN "Gloups !" FOR window_nf AS #w
    #w, "TRAPCLOSE [close]"
   ' #w.m, "when leftButtonDown [scanne]"
    #w.m, "when leftButtonMove [scanne]"
  [equ]
    dim piv(2): piv(1)=300: piv(2)=200: xa=50
    pa=50: pb=50: la=200: lb=200
    #w.pa, str$(pa);" Kg": #w.pb, str$(pb);" Kg"
    #w.la, str$(la);" cm": #w.lb, str$(lb);" cm"
    'eq: pa*la = pb*lb
'    #w.testa, str$(la/pa): #w.testb, str$(lb/pb)
'    dif=(la/pa)-(lb/pb)
    #w.testa, str$(la*pa): #w.testb, str$(lb*pb)
    dif=(la*pa)-(lb*pb)
    #w.testc, str$(dif)
    #w.m , "down"
    #w.m , "fill blue; color yellow; backcolor blue"
    #w.pa, "!contents? var$":pa=val(var$): #w.pb, "!contents? var$":pb=val(var$)
    dif=(la*pa)-(lb*pb)
  [draw]
    #w.m , "size 2": #w.m , "fill blue"
        #w.m, "PLACE 350 245": #w.m, "\ < Click and move >"
    #w.m, "PLACE 220 280": #w.m, "\ la*pa": #w.m, "PLACE 320 280": #w.m, "\ lb*lpb"
    #w.m, "PLACE 150 345": #w.m, "\ (la*pa)-(lb*pb)"    #w.m, "line ";piv(1);" ";piv(2);" ";piv(1)+10;" ";piv(2)+30
    #w.m, "line ";piv(1);" ";piv(2);" ";piv(1)-10;" ";piv(2)+30
    #w.m , "color yellow; backcolor yellow"
    #w.m, "PLACE ";piv(1)-20;" ";piv(2)+30: #w.m, "boxfilled ";piv(1)+20;" ";piv(2)+50
    #w.m , "color black; backcolor yellow"
    #w.m, "PLACE ";piv(1)-20;" ";piv(2)+45: #w.m, "\ <": #w.m, "PLACE ";piv(1)+5;" ";piv(2)+45: #w.m, "\ >"
    #w.m , "color red"
   ' #w.m, "line ";"50";" ";piv(2);" ";piv(1);" ";piv(2): #w.m, "line ";piv(1);" ";piv(2);" ";"550";" ";piv(2)
    factor = 50000  'by trial and error
    #w.m, "line ";"50";" ";piv(2)+dif/50000*(piv(1)-50);" ";piv(1);" ";piv(2) '
    #w.m, "line ";piv(1);" ";piv(2);" ";"550";" ";piv(2)-dif/factor*(500-(piv(1)-50))
  wait
  [scanne]
    #w.pa, "!contents? var$":pa=val(var$): #w.pb, "!contents? var$":pb=val(var$)
    mx=MouseX: my=MouseY
    if my>piv(2)+30 and my<piv(2)+50 then
       if mx<piv(1)-20 then
          piv(1)=piv(1)-5
          la=la-4: #w.la, str$(la);" cm": lb=lb+4: #w.lb, str$(lb);" cm"
    #w.testa, str$(la*pa): #w.testb, str$(lb*pb)
    dif=(la*pa)-(lb*pb)
    #w.testa, str$(la*pa): #w.testb, str$(lb*pb)
    dif=(la*pa)-(lb*pb)
          #w.testc, str$(dif)
          goto [draw]
       end if
       if mx>piv(1)+20 then
          piv(1)=piv(1)+5
          la=la+4: #w.la, str$(la);" cm": lb=lb-4: #w.lb, str$(lb);" cm"
    #w.testa, str$(la*pa): #w.testb, str$(lb*pb)
    dif=(la*pa)-(lb*pb)
          #w.testc, str$(dif)
          goto [draw]
       end if
    end if
  wait
  [close]
    CLOSE  #w
    END
 

Does it works as you want?
User IP Logged

Q: "And if I took your codes and compile them, and sell them for a profit"?
A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it - please do.
(enjoying JB 1.01 on WinXP, netbook and desktop)
Valentin
Full Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 130
xx Re: Hello there is a problem
« Reply #31 on: Nov 1st, 2017, 04:29am »

Yes, it's good like that; but I am also studying the bplus method which is more orthodox for the future (small and large weight variations and pivot position at equilibrium).
« Last Edit: Nov 1st, 2017, 04:30am by Valentin » User IP Logged

Rod
Administrator
ImageImageImageImageImage


member is offline

Avatar

Graphics = Goosebumps!


PM

Gender: Male
Posts: 3151
xx Re: Hello there is a problem
« Reply #32 on: Nov 1st, 2017, 08:50am »

This behaves a little more like a balance arm might. It will either be grounded left or right or there will be a very small sensitive balance position. Left Mouse Button Move to change the pivot.

I have simplified the line drawing, it isn't geometrically accurate no angles not trig just simple incremental steps that define a slope.

Code:
 nomainwin
    WindowWidth = 800
    WindowHeight = 600
    UpperLeftX = int((DisplayWidth-WindowWidth)/2)
    UpperLeftY = int((DisplayHeight-WindowHeight)/2)
    pivotx=int(WindowWidth/2) 'pivot at mid screen
    ground=int(WindowHeight/2)'ground at mid screen
    pivoty=50
    armLength=600
    la=300
    pa=50 'heavy side
    lb=300
    pb=5

    button #1, "Quit", [quit], LR, 50, 10
    open "Balance" for graphics_nsb as #1
    #1 "trapclose [quit]"
    #1 "when leftButtonMove  [track]"


    [draw]
    'clear the screen
    #1 "down ; fill black ; color white ; size 4"
    'draw the pivot
    #1 "line ";pivotx;" ";ground;" ";pivotx;" ";ground-pivoty
    'work out end points depending on slope of arm
    if slope<0 then lay=(ground-pivoty)-la*slope : lby=lay+600*slope
    if slope=0 then lay=(ground-pivoty):lby=(ground-pivoty)
    if slope>0 then lby=(ground-pivoty)+lb*slope : lay=lby-600*slope
    #1 "line 100 ";lay;" 700 ";lby
    wait

    [track]
    'track and move the pivot on the x plane
    pivotx=MouseX
    if pivotx<100 then pivotx=100
    if pivotx>700 then pivotx=700
    'work out length either side of the pivot
    la=pivotx-100
    lb=700-pivotx
    'work out the moment force for each end
    ma=la*pa
    mb=lb*pb
    'if it is heavily out of balance ground one side
    'work out the slope from the grounded end to the pivot
    'we will use this to project the full bar slope
    if ma>mb+50 then slope=pivoty/la*-1'left side down
    if mb>ma+50 then slope=pivoty/lb 'right side down
    'if it is nearly balanced allow it to cant towards balance
    if abs(ma-mb)<50 and ma-mb<>0 then slope=slope/50*abs(ma-mb)
    goto [draw]




    [quit]
    close #1
    end

 
User IP Logged

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1255
xx Re: Hello there is a problem
« Reply #33 on: Nov 1st, 2017, 12:53pm »

Hi Rod,

I guess you have overcome your confusion because your code works. I like how it completely avoids Trig which means not having to fudge with pi, making something negative is easier than adjusting an angle to a quadrant.

Hi tsh73,

So this is how William Tell practiced? grin
User IP Logged

B+
Valentin
Full Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 130
xx Re: Hello there is a problem
« Reply #34 on: Nov 2nd, 2017, 2:27pm »

@: Rod:
Very good ! I adopt!
Of course, by the movement of the pivot, we will not be able to see intermediate equilibria; but I hope to get them with slight variations in weight.
A virtual parmacien trebuchet to weigh my thoughts.
thank you very much
Pythagoras can rest easy, when Newton, who was trying to break in with his eyes, we will forget him for the moment; But the code is in my bag for future rebondissemnts

EDIT: Oh Rod, you crook! The weights are gone!
I'm running away with Tsh73's trick before you steal the board!
« Last Edit: Nov 2nd, 2017, 3:31pm by Valentin » User IP Logged

Rod
Administrator
ImageImageImageImageImage


member is offline

Avatar

Graphics = Goosebumps!


PM

Gender: Male
Posts: 3151
xx Re: Hello there is a problem
« Reply #35 on: Nov 2nd, 2017, 4:01pm »

The weights are still there. The point is that a balance bar TRIPS at the balance weight. It does not gradually change and imply movement towards balance.

If you try and balance an aeroplane propeller then what you do is suspend it in a magnetic frictionless pivot. You are not looking for it to balance, you are looking for it to stop rotating. That means it is in balance, not that it stops in the horizontal position. That would be unnatural. As would your balance beam model.
User IP Logged

Pages: 1 2 3  Notify Send Topic Print
« Previous Topic | Next Topic »

Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls