|
Post by honkytonk on Oct 2, 2022 11:47:26 GMT
Hello friends, I took this code here and modified it a bit. The adjustment by the cyan square works. The goal: I would like to be able to regulate by the textboxes. With values close to the "default" it works Velocity max square graphicbox x 2 (100--->200). Angle: All are ok Mass x 2 or 3 (0.1--->0.3). But, but, but: I would like: Velocity: 285 and mass 0.0006 Kg And then nothing goes. With these values and 30° angle the lead should land between 120m and 200m And it's only a very small charm of a few millimeters. A little help..?? Thank you for.
nomainwin WindowWidth=650: WindowHeigh=360 UpperLeftX=5: UpperLeftY=10 button #p.b1, "Fire!", [fire], UL, 10, 20, 50, 25 button #p.b2, "Clear", [clear], UL, 70, 20, 50, 25 statictext #p.st1, "Initialise", 130, 20, 250, 20 statictext #p.st2, "Distance", 130, 40, 250, 20 TEXTBOX #p.vel, 460, 15, 60, 25 TEXTBOX #p.ang, 460, 45, 60, 25 TEXTBOX #p.mass, 460, 75, 60, 25 graphicbox #p.g2, 5, 90, 40, 40 graphicbox #p.g, 5, 10, 630, 310 open "Trajectoire" for window as #p #p, "trapclose [quit]" #p.g2 "when leftButtonDown [vecto]" #p.b1, "!font courrier 12 bold": #p.b2, "!font courrier 12 bold" #p.st1, "!font courrier 12 bold": #p.st2, "!font courrier 12 bold" [clear] #p.vel, "": #p.ang, "": #p.mass, "" #p.g "cls; down; fill lightgray" #p.g, "color black backcolor lightgray" #p.g, "place 10 70": #p.g, "\Clic in the square" #p.g, "place 400 20": #p.g, "\Velocity" #p.g, "place 520 25": #p.g, "\Square and Fire" #p.g, "place 520 55": #p.g, "\Clic in square" #p.g, "place 400 50": #p.g, "\Angle" #p.g, "place 400 80": #p.g, "\Mass" #p.g, "place 520 85": #p.g, "\Square and Fire" #p.g2 "size 2 ; down ; fill cyan ; flush" #p.g "up ; goto 5 305 ; color darkblue" '----horizon #p.g "down ; goto 985 305 ; color black ;size 1": #p.g "flush" ' #p.vel, "!contents? vel$": #p.ang, "!contents? ang$": #p.mass, "!contents? mass$" m = 0.1 '1 'fixed mass of stone in kg. 0.1 A = 0.002 'csa of stone in m^2. g = 9.81 'acc'n of gravity m^s2. D = 1.2 'density of air. Cd = 0.75 'allows for the shape. v = 0.005 '60 'release velocity in m/s. theta = 30 'release angle in degrees, theta =theta /180 *3.14159265 ' ... changed to radians. y = 0 'initial vertical height. vy = v *cos( theta) 'initial vertical vel'y. x = 0 'initial horizontal position. vx = v *sin( theta) 'initial horizontal vel'y. t = 0 'initial time. s dt = 0.001 'time interval between updates. wait [fire] scan #p.vel, "!contents? vel$": #p.ang, "!contents? ang$": #p.mass, "!contents? mass$" if mass$<>"" then m=val(mass$) fy =0 -g*m -0.5*D*vy^2*Cd *A '*sgn(vy) ay=fy/m: vy=vy+ay*dt: y=y+vy*dt fx=0-0.5 *D*vx^2*Cd*A '*sgn(vx) ax=fx/m: vx=vx+ax*dt: x=x+vx*dt t=t+dt if vel$<>""then v=val(vel$) xset=5 +(2.5*x): yset=305 -(2.5*y) if yset > 302 then yset=302 ': xset=xset*2 #p.g, "set ";xset; " ";yset '305 -(2.5*y) scan ' if x <400 and y >-40 then [fire] 'x <400----(si non sortie définitive d'écran ? if x <500 and y >-100 then [fire] #p.g "flush" ' #p.b1 "'!enable" #p.st2, "Distance=" ; using( "###.###",xset/33);" mètres" wait [vecto] '-----initialisation-définition paramètres #p.vel, "!contents? vel$": #p.ang, "!contents? ang$": #p.mass, "!contents? mass$" x =0 y =0 xx =MouseX yy =MouseY #p.g2 "cls ; down ; fill cyan ; up ; goto 0 39 ; down ; goto "; xx; " "; yy theta =atn( ( 39 -yy) /xx) v =2 *( xx^2 +( 39-yy)^2)^0.5 if vel$<>""then v=val(vel$) print v'***************** if ang$<>"" then #p.g2 "cls ; down ; fill cyan" theta=val(ang$) theta =theta /180 *3.14159265 end if if mass$<>"" then #p.g2 "cls ; down ; fill cyan" #p.st1 "v ="; using( "###.#", v); " & angle =";_ using( "###.#", theta *180 /3.14159265); " degrees." vy=v*sin( theta) ' initial vertical vel'y. vx=v*cos( theta) ' initial horizontal vel'y. if ang$<>"" then [fire] wait [quit] close #p end
|
|
|
Post by plus on Oct 2, 2022 17:10:17 GMT
honkytonk Can you show me the formula where mass is supposed to effect something in the calculations. My quick Internet scan just shows formulas concerning velocity, gravity and time eg, y = h + Vᵧ * t - g * t² / 2
|
|
|
Post by honkytonk on Oct 2, 2022 19:01:52 GMT
The mass is contained in the initial speed v0(e=1/2 mv^2) Putting the initial velocity as a parameter avoids having to manipulate the mass and the energy. But we can vary the mass at constant energy through the initial velocity. In the net formula, V is v0 (initial velocity (function of m and energy in Joules).
|
|
|
Post by plus on Oct 2, 2022 19:06:57 GMT
The mass is contained in the initial speed v0(e=1/2 mv^2) So what's the initial velocity of the v? BTW your code seems to work fine without anything for mass, except maybe the graph after the projectile hits the ground.
|
|
|
Post by tsh73 on Oct 2, 2022 20:00:30 GMT
honkytonk, Where you took that code from? I'm afraid something is wrong If I do not account for air drag, maximum distance should be Lmax = v0^2*sin(2*theta)/g so for v = 50 and angle 30 degrees I got 220 meters But your program gives much smaller values even if 'm' is big enough so drag effect is not visible (looks like parabola, no speed decrease at the end) v 5 angle 30 mass 1 it shows 21.907 meters
Also if that is indeed lead sphere then density rho is 11340 and for m=0.1 we get radius 1.26 cm (1 inch diameter?) and 0.002 sphere area But if you change m, area should change as well I got formula A=4*pi*((m/rho/pi/4*3)^(1/3))^2 ( from sphere area A=4*pi*r^2 sphere volume v=4/3*pi*r^3 m = v*pho )
EDIT
isn't 0.0006 Kg is too small for a bullet? I think 0.006 Kg or 6 g is more realistic.
|
|
|
Post by tsh73 on Oct 2, 2022 20:32:49 GMT
I just tried that v = 50 and angle 30 degrees dt = 0.001 solved with most simple method (Euler's) Got distance 220 as well.
0.001 0.4330127e-1 0.025 24.99019 0.002 0.8660254e-1 0.4999019e-1 24.98038 0.003 0.12990381 0.7497057e-1 24.97057 ''' (very many lines) 5.096 220.663273 0.0459914 -24.99176 5.097 220.706574 0.2099964e-1 -25.00157 5.098 220.749875 -0.400193e-2 -25.01138
pi = acs(-1) t = 0 x=0 y=0
dt=0.001 v=50 a=30 theta=a*pi/180
vx=v*cos(theta) vy=v*sin(theta)
g = 9.81
while y >=0 x=x+vx*dt y=y+vy*dt vy=vy-g*dt t=t+dt print t, x, y, vy wend
|
|
|
Post by tsh73 on Oct 2, 2022 21:09:38 GMT
Ok I think I kind of fixed that (I just checked where y goes below 0, and stored xHit of that point. And print it out as distance) Give it a spin nomainwin WindowWidth=650: WindowHeigh=360 UpperLeftX=5: UpperLeftY=10 button #p.b1, "Fire!", [fire], UL, 10, 20, 50, 25 button #p.b2, "Clear", [clear], UL, 70, 20, 50, 25 statictext #p.st1, "Initialise", 130, 20, 250, 20 statictext #p.st2, "Distance", 130, 40, 250, 60 TEXTBOX #p.vel, 460, 15, 60, 25 TEXTBOX #p.ang, 460, 45, 60, 25 TEXTBOX #p.mass, 460, 75, 60, 25 graphicbox #p.g2, 5, 90, 40, 40 graphicbox #p.g, 5, 10, 630, 310 open "Trajectoire" for window as #p #p, "trapclose [quit]" #p.g2 "when leftButtonDown [vecto]" #p.b1, "!font courrier 12 bold": #p.b2, "!font courrier 12 bold" #p.st1, "!font courrier 12 bold": #p.st2, "!font courrier 12 bold" [clear] #p.vel, "": #p.ang, "": #p.mass, "" #p.g "cls; down; fill lightgray" #p.g, "color black backcolor lightgray" #p.g, "place 10 70": #p.g, "\Clic in the square" #p.g, "place 400 20": #p.g, "\Velocity" #p.g, "place 520 25": #p.g, "\Square and Fire" #p.g, "place 520 55": #p.g, "\Clic in square" #p.g, "place 400 50": #p.g, "\Angle" #p.g, "place 400 80": #p.g, "\Mass" #p.g, "place 520 85": #p.g, "\Square and Fire" #p.g2 "size 2 ; down ; fill cyan ; flush" #p.g "up ; goto 5 305 ; color darkblue" '----horizon #p.g "down ; goto 985 305 ; color black ;size 1": #p.g "flush" ' #p.vel, "!contents? vel$": #p.ang, "!contents? ang$": #p.mass, "!contents? mass$" m = 0.1 '1 'fixed mass of stone in kg. 0.1 A = 0.002 'csa of stone in m^2. g = 9.81 'acc'n of gravity m^s2. D = 1.2 'density of air. Cd = 0.75 'allows for the shape. v = 0.005 '60 'release velocity in m/s. theta = 30 'release angle in degrees, theta =theta /180 *3.14159265 ' ... changed to radians. y = 0 'initial vertical height. vy = v *cos( theta) 'initial vertical vel'y. x = 0 'initial horizontal position. vx = v *sin( theta) 'initial horizontal vel'y. t = 0 'initial time. s dt = 0.001 'time interval between updates. wait [fire] scan #p.vel, "!contents? vel$": #p.ang, "!contents? ang$": #p.mass, "!contents? mass$" if mass$<>"" then m=val(mass$) fy =0 -g*m -0.5*D*vy^2*Cd *A '*sgn(vy) ay=fy/m: vy=vy+ay*dt: y=y+vy*dt fx=0-0.5 *D*vx^2*Cd*A '*sgn(vx) ax=fx/m: vx=vx+ax*dt: x=x+vx*dt t=t+dt 'print t, x, y, vy if vel$<>""then v=val(vel$) xset=5 +(2.5*x): yset=305 -(2.5*y) if yset > 302 then yset=302 ': xset=xset*2 if y<0 then if xHit=0 then xHit = x end if #p.g, "set ";xset; " ";yset '305 -(2.5*y) scan ' if x <400 and y >-40 then [fire] 'x <400----(si non sortie dA©finitive d'A©cran ? if x <500 and y >-100 then [fire] #p.g "flush" ' #p.b1 "'!enable" '#p.st2, "Distance=" ; using( "###.###",xset/33);" mA?tres" #p.st2, "Distance=" ; using( "###.###",xHit);" mA?tres" distMsg$ = distMsg$ +chr$(13)+"Distance=" ; using( "###.###",xHit);" m" #p.st2, distMsg$ wait [vecto] '-----initialisation-dA©finition paramA?tres #p.vel, "!contents? vel$": #p.ang, "!contents? ang$": #p.mass, "!contents? mass$" 'm = 0.1 '1 'fixed mass of stone in kg. 0.1 '''A = 0.002 'csa of stone in m^2. pi = acs(-1) rho = 11340 'plumbum m=val(mass$) A=4*pi*((m/rho/pi/4*3)^(1/3))^2 'notice "A=";using("#.######",A) '''Lmax=v0^2*sin(2*a)/g theta=val(ang$) theta =theta /180 *3.14159265 Lmax=val(vel$)^2*sin(2*theta)/g 'notice "Max possible length =";Lmax distMsg$ = "Dist. w/o air drag=" ; using( "#####.##",Lmax);" m" distMsg$ =distMsg$ +chr$(13)+"A=";using("#.######",A);" m^2" #p.st2, distMsg$ xHit=0 'not set
x =0 y =0 xx =MouseX yy =MouseY #p.g2 "cls ; down ; fill cyan ; up ; goto 0 39 ; down ; goto "; xx; " "; yy theta =atn( ( 39 -yy) /xx) v =2 *( xx^2 +( 39-yy)^2)^0.5 if vel$<>""then v=val(vel$) print v'***************** if ang$<>"" then #p.g2 "cls ; down ; fill cyan" theta=val(ang$) theta =theta /180 *3.14159265 end if if mass$<>"" then #p.g2 "cls ; down ; fill cyan" #p.st1 "v ="; using( "###.#", v); " & angle =";_ using( "###.#", theta *180 /3.14159265); " degrees." vy=v*sin( theta) ' initial vertical vel'y. vx=v*cos( theta) ' initial horizontal vel'y. if ang$<>"" then [fire] wait [quit] close #p end
|
|
|
Post by honkytonk on Oct 3, 2022 7:41:45 GMT
0.0006 Kg is the weight of 4.5 mm pellets (air rifle). For 0.0006 Kg and 20 Joules the initial speed is: 285 M/s
The "Air" parameter (resistance) can be ignored, because when a scope is adjusted for horizontal shooting the "Air" parameter is integrated into the adjustment and remains constant regardless of the angle of elevation.
It was a mistake to want to set the mass without the energy, since it is "contained" in the initial speed In the end, two parameters: Initial speed and angle + parable calculation It is necessary to "clean the code of all the useless.
|
|
|
Post by tsh73 on Oct 3, 2022 8:19:47 GMT
Interesting thing to know.
well, graph shows that you rather shouldn't - with air resistance counted bullet falls after losing speed quite dramatically.
BTW I found likely mistake in counting for air resistance: now it uses air resistance calculated upon vx and vy separately But it should calculate air resistance as whole, on vv=sqr(vx^2+vy^2) Then project it along vx, vy (just scaling it by vx/vv, vy/vv)
|
|
|
Post by honkytonk on Oct 3, 2022 14:27:23 GMT
Yes, apparently you are right. The air is not nothing.
|
|
|
Post by xxgeek on Oct 3, 2022 16:24:07 GMT
Edited for the visually impaired. More real-estate and size 4 projectile. Cleaned up the code a bit.
Changed #p.g, "set ";xset; " ";yset '305 -(2.5*y) to if yset < 700 then #p.g, "set ";xset; " ";yset
Removed - if yset > 302 then yset=302 ': xset=xset*2
EDIT - Changed - if x <500 and y >-100 then [fire] to if x <1000000 and y >-1000000 then [fire] Now it keeps calculating distance when x,y coordinates go way off screen. Distance is also posted if you wait long enough Longer and more powerful shots get graphed.
The graphed projectile no longer goes past the ground. Thing is my math skills are lacking and can't be sure the posted distance is still correct.
nomainwin WindowWidth=1350: WindowHeight=760 UpperLeftX=5: UpperLeftY=10 button #p.b1, "Fire!", [fire], UL, 10, 20, 50, 25 button #p.b2, "Clear", [clear], UL, 70, 20, 50, 25 statictext #p.st1, "Initialise", 150, 20, 270, 20 statictext #p.st2, "Distance", 150, 45, 270, 60 TEXTBOX #p.vel, 480, 15, 60, 25 TEXTBOX #p.ang, 480, 45, 60, 25 TEXTBOX #p.mass, 480, 75, 60, 25 graphicbox #p.g2, 5, 60, 40, 40 graphicbox #p.g, 5, 10, 1350, 760
open "Trajectoire" for window as #p #p, "trapclose [quit]" #p.g2 "when leftButtonDown [vecto]" #p.b1, "!font courrier 12 bold": #p.b2, "!font courrier 12 bold" #p.st1, "!font courrier 12 bold": #p.st2, "!font courrier 12 bold"
[clear] #p.vel, "": #p.ang, "": #p.mass, "" #p.g "cls; down; fill lightgray" #p.g, "color black backcolor lightgray" #p.g, "place 45 72": #p.g, "\Clic in square" #p.g, "place 420 20": #p.g, "\Velocity" #p.g, "place 540 25": #p.g, "\Square and Fire" #p.g, "place 540 55": #p.g, "\Clic in square" #p.g, "place 420 50": #p.g, "\Angle" #p.g, "place 420 80": #p.g, "\Mass" #p.g, "place 540 85": #p.g, "\Square and Fire" #p.g2 "size 2 ; down ; fill cyan ; flush" #p.g "up ; goto 5 700 ; color blue;size 3" '----horizon #p.g "down ; goto 1340 700 ; color red ;size 4": #p.g "flush" ' #p.vel, "!contents? vel$": #p.ang, "!contents? ang$": #p.mass, "!contents? mass$" m = 0.1 '1 'fixed mass of stone in kg. 0.1 A = 0.002 'csa of stone in m^2. g = 9.81 'acc'n of gravity m^s2. D = 1.2 'density of air. Cd = 0.75 'allows for the shape. v = 0.005 '60 'release velocity in m/s. theta = 30 'release angle in degrees, theta =theta /180 *3.14159265 ' ... changed to radians. y = 0 'initial vertical height. vy = v *cos( theta) 'initial vertical vel'y. x = 0 'initial horizontal position. vx = v *sin( theta) 'initial horizontal vel'y. t = 0 'initial time. s dt = 0.001 'time interval between updates. wait [fire] scan #p.vel, "!contents? vel$": #p.ang, "!contents? ang$": #p.mass, "!contents? mass$" if mass$<>"" then m=val(mass$) fy =0 -g*m -0.5*D*vy^2*Cd *A '*sgn(vy) ay=fy/m: vy=vy+ay*dt: y=y+vy*dt fx=0-0.5 *D*vx^2*Cd*A '*sgn(vx) ax=fx/m: vx=vx+ax*dt: x=x+vx*dt t=t+dt if vel$<>""then v=val(vel$) xset=5 +(2.5*x): yset=700 -(2.5*y)
if y<0 then if xHit=0 then xHit = x end if if yset < 700 then #p.g, "set ";xset; " ";yset scan if x <1000000 and y >-1000000 then [fire] #p.g "flush" #p.st2, "Distance=" ; using( "###.###",xHit);" mA?tres" distMsg$ = distMsg$ +chr$(13)+"Distance=" ; using( "###.###",xHit);" m" #p.st2, distMsg$ wait [vecto] '-----initialisation-dA©finition paramA?tres #p.vel, "!contents? vel$": #p.ang, "!contents? ang$": #p.mass, "!contents? mass$" pi = acs(-1) rho = 11340 'plumbum m=val(mass$) A=4*pi*((m/rho/pi/4*3)^(1/3))^2 theta=val(ang$) theta =theta /180 *3.14159265 Lmax=val(vel$)^2*sin(2*theta)/g distMsg$ = "Dist. w/o air drag=" ; using( "#####.##",Lmax);" m" distMsg$ =distMsg$ +chr$(13)+"A=";using("#.######",A);" m^2" #p.st2, distMsg$ xHit=0 'not set x =0 y =0 xx =MouseX yy =MouseY #p.g2 "cls ; down ; fill cyan ; up ; goto 0 39 ; down ; goto "; xx; " "; yy theta =atn( ( 39 -yy) /xx) v =2 *( xx^2 +( 39-yy)^2)^0.5 if vel$<>""then v=val(vel$) if ang$<>"" then #p.g2 "cls ; down ; fill cyan" theta=val(ang$) theta =theta /180 *3.14159265 end if if mass$<>"" then #p.g2 "cls ; down ; fill cyan" #p.st1 "v ="; using( "###.#", v); " & angle =";_ using( "###.#", theta *180 /3.14159265); " degrees." vy=v*sin( theta) ' initial vertical vel'y. vx=v*cos( theta) ' initial horizontal vel'y. if ang$<>"" then [fire] wait [quit] close #p end ]/code]
|
|
|
Post by xxgeek on Oct 3, 2022 22:27:15 GMT
Added some textboxes to view calculations in progress.
Is the math correct?
It seems ok till the end.
I stopped sending data to the textboxes when the graph shows the projectile hits the ground. But, the app still keeps calculating. Is it not sinc'd with the graphing?
Check how fast it is falling, and how Y is so large. Doesn't make sense. Is the reported distance correct when it finishes?
Edit - One more thing. The angle may be calculated properly in the math (I wouldn't know) But the angle on the graph doesn't always match the angle given. eg: a 10 degree angle appears more like a 35 to 45 degree angle.
Updated
nomainwin WindowWidth=1350: WindowHeight=760 UpperLeftX=5: UpperLeftY=10 button #p.b1, "Fire!", [fire], UL, 10, 20, 50, 25 button #p.b2, "Clear", [clear], UL, 70, 20, 50, 25 statictext #p.st1, "Initialise", 150, 20, 270, 20 statictext #p.st2, "Distance", 150, 45, 270, 60
textbox #p.x, 690, 45, 150, 25 textbox #p.y, 690, 75, 150, 25 textbox #p.hs, 850, 45, 200, 25 textbox #p.vs, 1060, 45, 200, 25 statictext #p.stco "Coordinates", 730, 30, 75, 15 statictext #p.sth "Horizontal Velocity", 870, 30, 155, 15 statictext #p.stv "Vertical Velocity", 1090, 30, 140, 15 TEXTBOX #p.vel, 480, 15, 60, 25 TEXTBOX #p.ang, 480, 45, 60, 25 TEXTBOX #p.mass, 480, 75, 60, 25 graphicbox #p.g2, 5, 60, 40, 40 graphicbox #p.g, 5, 10, 1350, 760
open "Trajectoire" for window as #p #p "font courrier 10 bold" #p, "trapclose [quit]" #p.g2 "when leftButtonDown [vecto]" #p.b1, "!font courrier 12 bold": #p.b2, "!font courrier 12 bold" #p.st1, "!font courrier 12 bold": #p.st2, "!font courrier 12 bold" #p.stco "!font courrier 10 bold" #p.x "!font courrier 10 bold" #p.y "!font courrier 10 bold" #p.sth "!font courrier 10 bold" #p.stv "!font courrier 10 bold" [clear] #p.vel, "": #p.ang, "": #p.mass, "" #p.g "cls; down; fill lightgray" #p.g, "color black backcolor lightgray" #p.g, "place 45 72": #p.g, "\Clic in square" #p.g, "place 420 20": #p.g, "\Velocity" #p.g, "place 540 25": #p.g, "\Square and Fire" #p.g, "place 540 55": #p.g, "\Clic in square" #p.g, "place 420 50": #p.g, "\Angle" #p.g, "place 420 80": #p.g, "\Mass" #p.g, "place 540 85": #p.g, "\Square and Fire" #p.stco "place 730 30": #p.stco "Coordinates" #p.sth "place 870 30" : #p.sth "Horizontal Velocity (m\s)" #p.stv "place 1090 30": #p.stv "Vertical Velocity (m\s)" #p.g2 "size 2 ; down ; fill cyan ; flush" #p.g "up ; goto 5 700 ; color blue;size 3" '----horizon #p.g "down ; goto 1340 700 ; color red ;size 4": #p.g "flush" ' #p.vel, "!contents? vel$": #p.ang, "!contents? ang$": #p.mass, "!contents? mass$" m = 0.1 '1 'fixed mass of stone in kg. 0.1 A = 0.002 'csa of stone in m^2. g = 9.81 'acc'n of gravity m^s2. D = 1.2 'density of air. Cd = 0.75 'allows for the shape. v = 0.005 '60 'release velocity in m/s. theta = 30 'release angle in degrees, theta =theta /180 *3.14159265 ' ... changed to radians. y = 0 'initial vertical height. vy = v *cos( theta) 'initial vertical vel'y. x = 0 'initial horizontal position. vx = v *sin( theta) 'initial horizontal vel'y. t = 0 'initial time. dt = 0.001 'time interval between updates. wait [fire] scan #p.vel, "!contents? vel$": #p.ang, "!contents? ang$": #p.mass, "!contents? mass$" if mass$<>"" then m=val(mass$) fy =0 -g*m -0.5*D*vy^2*Cd *A '*sgn(vy) ay=fy/m: vy=vy+ay*dt: y=y+vy*dt fx=0-0.5 *D*vx^2*Cd*A '*sgn(vx) ax=fx/m: vx=vx+ax*dt: x=x+vx*dt t=t+dt if vel$<>""then v=val(vel$) xset=5 +(2.5*x): yset=700 -(2.5*y)
if y<0 then if xHit=0 then xHit = x end if if yset < 701 then #p.g, "set ";xset; " ";yset #p.x "X = ";int(xset) #p.y "Y = ";int(yset) #p.hs vx #p.vs vy end if scan if x <1000000 and y >-1000000 then [fire] #p.g "flush" #p.st2, "Distance=" ; using( "###.###",xHit);" mA?tres" distMsg$ = distMsg$ +chr$(13)+"Distance=" ; using( "###.###",xHit);" m" #p.st2, distMsg$ wait [vecto] '-----initialisation-dA©finition paramA?tres #p.vel, "!contents? vel$": #p.ang, "!contents? ang$": #p.mass, "!contents? mass$" pi = acs(-1) rho = 11340 'plumbum m=val(mass$) A=4*pi*((m/rho/pi/4*3)^(1/3))^2 theta=val(ang$) theta =theta /180 *3.14159265 Lmax=val(vel$)^2*sin(2*theta)/g distMsg$ = "Dist. w/o air drag=" ; using( "#####.##",Lmax);" m" distMsg$ =distMsg$ +chr$(13)+"A=";using("#.######",A);" m^2" #p.st2, distMsg$ xHit=0 'not set x =0 y =0 xx =MouseX yy =MouseY #p.g2 "cls ; down ; fill cyan ; up ; goto 0 39 ; down ; goto "; xx; " "; yy theta =atn( ( 39 -yy) /xx) v =2 *( xx^2 +( 39-yy)^2)^0.5 if vel$<>""then v=val(vel$) if ang$<>"" then #p.g2 "cls ; down ; fill cyan" theta=val(ang$) theta =theta /180 *3.14159265 end if if mass$<>"" then #p.g2 "cls ; down ; fill cyan" #p.st1 "v ="; using( "###.#", v); " & angle =";_ using( "###.#", theta *180 /3.14159265); " degrees." vy=v*sin( theta) ' initial vertical vel'y. vx=v*cos( theta) ' initial horizontal vel'y. if ang$<>"" then [fire] wait [quit] close #p end
|
|
|
Post by tsh73 on Oct 4, 2022 7:15:12 GMT
You output xset, yset This is screen coords in pixels, and yset = 700 is low on window, starting line Print x, y instead - these are math (real world) coordinates
|
|
|
Post by honkytonk on Oct 4, 2022 9:40:49 GMT
Hello, We can see it more clearly, but not really... And you can notice that theta and v are not used.
NOMAINWIN mapw=650: maph= 400 WindowWidth=mapw+15: WindowHeight=maph+40 UpperLeftX = 10: UpperLeftY = 20 TEXTBOX #w.vy, 70, 20, 60, 25 TEXTBOX #w.vx, 185, 20, 60, 25 BUTTON #w.go, "Go!", [go], UL, 435, 20, 40, 25 GRAPHICBOX #w.g, 5, 5, mapw, maph OPEN "Help" FOR window_nf AS #w #w, "TRAPCLOSE [closeHelp]" #w.g, "down;fill darkgreen;color white;backcolor darkgreen;size 2" ' #w.g, "size 3" #w.g, "font courrier 12 bold" #w.vy, "!font courrier 12 bold": #w.vy, "42" #w.vx, "!font courrier 12 bold": #w.vx, "34" #w.g, "place 10 30": #w.g, "\vy --->": #w.g, "place 130 30": #w.g, "\vx --->" #w.g, "place 245 30": #w.g, "\<--- Change and Go --->" m = 0.1 '1 'fixed mass of stone in kg. 0.1 A = 0.002 'csa of stone in m^2. g = 9.81 'acc'n of gravity m^s2. D = 1.2 'density of air. Cd = 0.75 'allows for the shape. ' v = 0.005 '60 'release velocity in m/s. ' theta = 30 'release angle in degrees, ' theta =theta /180 *3.14159265 ' ... changed to radians. y = 0 'initial vertical height. vy = v *cos( theta) 'initial vertical vel'y. x = 0 'initial horizontal position. vx = v *sin( theta) 'initial horizontal vel'y. t = 0 'initial time. s dt = 0.001 'time interval between updates. wait [go] ' theta = 54.0370243 ' v=0.8902751 #w.vy, "!contents? vy$": vy=val(vy$) #w.vx, "!contents? vx$": vx=val(vx$) t=0: y=0: x=0 [fire] scan fy =0 -g*m -0.5*D*vy^2*Cd *A '*sgn(vy) ay=fy/m: vy=vy+ay*dt: y=y+vy*dt fx=0-0.5 *D*vx^2*Cd*A '*sgn(vx) ax=fx/m: vx=vx+ax*dt: x=x+vx*dt t=t+dt xset=5 +(2.5*x) yset=305 -(2.5*y) if yset > 302 then yset=302 ': xset=xset*2 #w.g, "set ";xset; " ";yset '305 -(2.5*y) if x <500 and y >-100 then [fire] wait [closeHelp] CLOSE #w END
|
|
|
Post by honkytonk on Oct 4, 2022 11:37:47 GMT
If we test whith vy=10: vx=285: m=0.0006 "d" expected = >100<200 m Displayed---> 0.41 m The math is wrong (We can adjust). If we test whith vy=72: vx=1000: m=0.01 The procedure is not good (shape of the curve) And there we have to think.
NOMAINWIN mapw=650: maph= 400 WindowWidth=mapw+15: WindowHeight=maph+40 UpperLeftX = 10: UpperLeftY = 20 TEXTBOX #w.vy, 70, 20, 60, 25 TEXTBOX #w.vx, 185, 20, 60, 25 TEXTBOX #w.m, 70, 55, 80, 25 TEXTBOX #w.d, 205, 55, 120, 25 BUTTON #w.go, "Go!", [go], UL, 435, 20, 40, 25 GRAPHICBOX #w.g, 5, 5, mapw, maph OPEN "Help" FOR window_nf AS #w #w, "TRAPCLOSE [closeHelp]" #w.g, "down;fill darkgreen;color white;backcolor darkgreen;size 2" #w.g, "font courrier 12 bold" #w.vy, "!font courrier 12 bold": #w.vy, "42" #w.vx, "!font courrier 12 bold": #w.vx, "34" #w.m, "!font courrier 12 bold": #w.m, "0.1" #w.d, "!font courrier 12 bold" #w.g, "place 10 30": #w.g, "\vy --->": #w.g, "place 130 30": #w.g, "\vx --->" #w.g, "place 10 70": #w.g, "\m --->": #w.g, "place 160 70": #w.g, "\d --->" #w.g, "place 245 30": #w.g, "\<--- Change and Go --->" #w.g, "flush" m = 0.1 '1 'fixed mass of stone in kg. 0.1 A = 0.002 'csa of stone in m^2. g = 9.81 'acc'n of gravity m^s2. D = 1.2 'density of air. Cd = 0.75 'allows for the shape. ' v = 0.005 '60 'release velocity in m/s. ' theta = 30 'release angle in degrees, ' theta =theta /180 *3.14159265 ' ... changed to radians. y = 0 'initial vertical height. vy = v *cos( theta) 'initial vertical vel'y. x = 0 'initial horizontal position. vx = v *sin( theta) 'initial horizontal vel'y. t = 0 'initial time. s dt = 0.001 'time interval between updates. wait [go] ' theta = 54.0370243 ' v=0.8902751 #w.vy, "!contents? vy$": vy=val(vy$) #w.vx, "!contents? vx$": vx=val(vx$) #w.m, "!contents? m$": m=val(m$) t=0: y=0: x=0 [fire] scan fy =0 -g*m -0.5*D*vy^2*Cd *A '*sgn(vy) ay=fy/m: vy=vy+ay*dt: y=y+vy*dt fx=0-0.5 *D*vx^2*Cd*A '*sgn(vx) ax=fx/m: vx=vx+ax*dt: x=x+vx*dt t=t+dt xset=5 +(2.5*x) yset=305 -(2.5*y) if yset > 302 then yset=302 ': xset=xset*2 #w.g, "set ";xset; " ";yset '305 -(2.5*y) if x <500 and y >-100 then [fire] #w.g, "flush" #w.d, using( "###.##",xset/33);" m" wait [closeHelp] CLOSE #w END
|
|