## FreeBalistic - physical app to calculate ballistic curves

User projects written in or related to FreeBASIC.
peter-cat
Posts: 18
Joined: Feb 18, 2019 8:03

### FreeBalistic - physical app to calculate ballistic curves

Hello,

I' ve been created application, that allows to input physical measures, calculate and show ballistic curve chart. Here is the link to the project:

https://sourceforge.net/projects/free-balistic/

...and some screenshoots:  I hope, that it will be useful for anyone of you.

The project in its current form is just a figment of what I would like to get, because there are some limitations that require the help of an expert in transforming physical patterns. That is what I would like to write about now.

According to what I wrote on the project website: "The aim of this project is to obtain a modification of the calculation that allows you to enter at least the angle of the projection and the strength of the wind."
Ultimately, there should be two additional fields in the program to introduce these quantities. I would like the application to only show a graph in one of the three considered planes, in a 2D view, and that the reading of the size and their analysis with the help of the legend image were intuitive. I need a formula for this purpose, which makes the result of the equation "z =" from the angle "alpha_xz" and includes the vector "Wx". Please, show the derivation, which allows you to develop the pattern for the placement of "Z =" in the "XZ" plane.

I am also asking for tips on how to consolidate patterns for rising and falling in one graph. Perhaps it is possible to transform both given patterns (climb and descent) so that a pattern is created that applies in this particular case, where the ballistic curve is considered in one dimension. The purpose of these applications is, as in most other programs of this type, the creation of a simple to analyze the 2D system, to calculate the height of the projectile after a specified time, possibly also calculating the distance traveled in a straight, horizontal line from the point of ejection. Unlike typical applications, however, the air resistance and wind force should also be taken into account. All this will be combined with a simple to read for the user drawing, presenting the size and 2D vectors used for calculations.

I am asking you, therefore, for the necessary diagrams and formulas to be available.
Greetings.
srvaldez
Posts: 2483
Joined: Sep 25, 2005 21:54

### Re: FreeBalistic - physical app to calculate ballistic curves

hello peter-cat :-)
I would like to compile the program myself so that the menu would be in English, but there are missing bmp files, would you be so kind and add the necessary files for your project?
also, what IDE are you using?
peter-cat
Posts: 18
Joined: Feb 18, 2019 8:03

### Re: FreeBalistic - physical app to calculate ballistic curves

The BMP files you can download from Sourceforge project Website. There you can find screenshoots atached to project. One of them are Your missing files, just open it in new tab and save as BMP via your net browser.
I am using FBEdit. In the Website on Sourceforge there is the project file of this Editor, *.FBP.
Greetings.
dodicat
Posts: 6648
Joined: Jan 10, 2006 20:30
Location: Scotland

### Re: FreeBalistic - physical app to calculate ballistic curves

Interesting subject.
for fun
Drag is proportional to velocity, and a wind factor.

Code: Select all

`Dim  As Integer xres,yresScreen 20,32,,64Screeninfo xres,yresDim Shared As Any Ptr i:i=Imagecreate(xres,yres,0)Type v2    As Single x,yEnd TypeType screendata    As Integer w,h,depth,bpp,pitch    As Any Pointer row    As Ulong Pointer pixel32End TypeDim Shared As screendata ThisScreen,thisimageWith ThisScreen    Screeninfo .w,.h,.depth,.bpp,.pitch    .row=ScreenptrEnd WithWith thisimage    Imageinfo i,.w,.h,.bpp,.pitch,.row    .depth=32End WithConst k=1   Const g=9.81  'gravityConst m=5     'massConst pi=4*Atn(1)Dim Shared As Integer mx,my,btn#define range(f,l) Int(Rnd*((l+1)-(f))+(f))#define map(a,b,x,c,d)  ((d)-(c))*((x)-(a))/((b)-(a))+(c)#define incircle(cx,cy,radius,x,y) (cx-x)*(cx-x) +(cy-y)*(cy-y)<= radius*radius#define inbox mx>20 andalso mx<400 andalso my>300 andalso my<340Sub bline(sd As screendata,x1 As Integer,y1 As Integer,x2 As Integer,y2 As Integer,col As Ulong)    #define ppset32(_x,_y,colour) *Cptr(Ulong Ptr,sd.row+ (_y)*sd.pitch+ (_x) Shl 2)  =(colour)    #define onscreen ((x1+x)>=0) And ((x1+x)<(sd.w-1)) And ((y1+y)>=0) And ((y1+y)<(sd.h-1))    Var dx=Abs(x2-x1),dy=Abs(y2-y1),sx=Sgn(x2-x1),sy=Sgn(y2-y1)    Dim As Integer e    If dx<dy Then  e=dx\2 Else e=dy\2    Do        For x As Integer=0 To 1            For y As Integer=0 To 1                If onscreen Then                    ppset32((x1+x),(y1+y),col)                End If            Next y        Next x        If x1 = x2 Then If y1 = y2 Then Exit Do        If dx > dy Then            x1 += sx : e -= dy : If e < 0 Then e += dx : y1 += sy        Else            y1 += sy : e -= dx : If e < 0 Then e += dy : x1 += sx        End If    LoopEnd Sub'Bressenham line thickenedSub thickline(sd As screendata,_    x1 As Long,_    y1 As Long,_    x2 As Long,_    y2 As Long,_    thickness As Single,_    colour As Ulong)    Var h=Sqr((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))    Var s=(y1-y2)/h    Var c=(x2-x1)/h    For yp As Double=-thickness/2 To thickness/2 'step 2        bline(sd,x1+(s*yp),y1+(c*yp),x2+(s*yp),y2+(c*yp),colour)    Next ypEnd SubSub drawline(s As screendata,x As Long,y As Long,angle As Single,length As Long,col As Ulong)    angle=angle*.0174532925199433      Var x2=x+length*Cos(angle)    Var y2=y-length*Sin(angle)    thickline(s,x,y,x2,y2,10,col)End SubSub clearimage()    Line i,(0,0)-(1023,767),Rgba(0,0,0,220),bf    drawline(thisimage,990,750,0,20,Rgb(0,200,0))End SubFunction Regulate(Byval MyFps As Long,Byref fps As Long=60) As Long    Static As Double timervalue,lastsleeptime,t3,frames    frames+=1    If (Timer-t3)>=1 Then t3=Timer:fps=frames:frames=0    Var sleeptime=lastsleeptime+((1/myfps)-Timer+timervalue)*1000    If sleeptime<1 Then sleeptime=1    lastsleeptime=sleeptime    timervalue=Timer    Return sleeptimeEnd FunctionSub fire(startpos As v2,theta As Single,v As Single)    Randomize    #macro show_wind(d)    Draw String(500,20),"Wind " & Abs(w)    If d<0 Then         Draw String(500,60),"<------"    Else        Draw String(500,60),"------>"     End If    #endmacro    theta=theta*(4*Atn(1))/180    Dim As Integer xres,yres,w=range(-10,10)    Screeninfo xres,yres    Dim As v2 position,lastposition    Dim As Single t    Do        t+=.05        position.x=startpos.x+(m/k)*(1-Exp(-(k/m)*t))*(V*Cos(theta)-w)+w*t        position.y=startpos.y+(m/k)*(1-Exp(-(k/m)*t))*(V*Sin(theta)+g*m/k)-(g*m/k)*t        Screenlock        Put(0,0),i,Pset        show_wind(w)        Locate 2,2        Print "Speed "; 100*Sqr((position.x-lastposition.x)^2+(position.y-lastposition.y)^2)        thickline(thisscreen,position.x,yres-position.y,lastposition.x,yres-lastposition.y,6,Rgb(0,155,255))        thickline(thisimage,position.x,yres-position.y,lastposition.x,yres-lastposition.y,6,Rgb(0,155,255))        lastposition=position        Screenunlock        Sleep regulate(60)        If incircle(1000,20,10,position.x,position.y) Then  Draw String i,(500,500),"HIT"    Loop Until position.y<0End SubSub show(p As Integer,theta As Long,cx As Long,cy As Long)    Put(0,0),i,Pset    Circle(150,150),25,Rgb(0,200,0),,,,f    Draw String(135,145),"Fire",Rgb(200,0,0)    Draw String(50,280),"Powder = " &p    Draw String(400,320),"<--- Adjust Powder"    Line(20,300)-(400,340),Rgb(0,200,255),b    Draw String(20,350),"100                                          300"    Circle(0,768),100    Draw String(100,740),"<------  Adjust elevation"    Draw String(20,600),"Elevation = "&theta    Circle(cx,cy),18,Rgb(100,0,0),,,,f    drawline(thisscreen,0,768,theta,100,Rgb(200,100,0))    drawline(thisimage,990,750,0,20,Rgb(0,200,0))End SubDim As String keyDim As Integer cx=200,cy=320,powder=200,theta=40Dim As v2 startposDim As Single a=theta*pi/180Do    key=Inkey    Getmouse mx,my,,btn    Screenlock    show(powder,theta,cx,cy)        If btn=1 And inbox Then        Cls        show(powder,theta,cx,cy)        cx=mx        If cx<40 Then cx=40        If cx>380 Then cx=380        powder=map(40,380,cx,100,300)    End If        If incircle(150,150,25,mx,my) And btn Then        Screenunlock        Cls        clearimage        fire(startpos,theta,powder)    End If        If incircle(0,768,100,mx,my) And btn=1 Then        Cls        show(powder,theta,cx,cy)        a=Atan2(768-my,mx)        theta=a*180/pi    End If    startpos=Type(100*Cos(a),100*Sin(a))        Screenunlock    Loop Until key=Chr(27)If i Then Imagedestroy i  `
peter-cat
Posts: 18
Joined: Feb 18, 2019 8:03

### Re: FreeBalistic - physical app to calculate ballistic curves

Hello,

It's time for first update of my app! The files of newer FreeBalistic version are available on: https://sourceforge.net/projects/free-balistic/files/

Screen of currently released version: Have Fun, this time with english GUI !
Lachie Dazdarian
Posts: 2338
Joined: May 31, 2005 9:59
Location: Croatia
Contact:

### Re: FreeBalistic - physical app to calculate ballistic curves

Really cool stuff. Something I wanted to do for a while (learn/refresh physics by producing physics related toys/educational programs).

Realtime simulation planned?
peter-cat
Posts: 18
Joined: Feb 18, 2019 8:03

### Re: FreeBalistic - physical app to calculate ballistic curves

Thanks!
The real time simulation is not plannet yet, but I was thinking about it. Maybe some animation of moving bullet will be added. But first I would like to fix the problem of the tight scope of values on the chart. It should be more flexible and work like Excel, that can automatically make the scales for axis in charts. I was looking for some freebasic charts library and it seems like it is possible to use it in this app. I'll do it when I get some free time, maybe then with some advanced graphical simulations :)
MrSwiss
Posts: 3582
Joined: Jun 02, 2013 9:27
Location: Switzerland

### Re: FreeBalistic - physical app to calculate ballistic curves

As you've noted yourself, it's currently having a to much limited scope.
(guns can fire 'downhill' too)

I'm an old armourer of the: Oerlikon_GDF (twin AA auto-cannon, 35 mm NATO),
which have a barrel movement angle from: below 0° to more than 90° (straight up).
This would require a change in the currently pre-set min./max. input values ...
(a split into height of cannon itself (barrel pivot point) and added/subtracted barrel
end's distance (from pivot), derived from lenght/angle of barrel+weapon)

There is yet another part to be taken into consideration: (but nice, for animation!)
The War-Amunition (grenades) have a 'self destruct' mechanism, set at 4000 m (of flight).
The latest Ammo, called AHEAD, is even a more complex beast, to deal with ...
peter-cat
Posts: 18
Joined: Feb 18, 2019 8:03

### Re: FreeBalistic - physical app to calculate ballistic curves

Hello,
Acording to proposals of MrSwiss: Hmm, interesting idea...

As we have some good chart library, we can finally modify the way of displaying the plots, and solve problem of tight scopes on the chart.
It will require to implement the chart library and change the code responsible for drawing charts, to adapt it in this case. The library is available here (Chart.bas file):

https://sourceforge.net/projects/fb-cha ... /files/V3/

Second thing, probably most hard, is to change loops in calculating functions to give them a new prepared data in dynamic memory structures. I mean wider amount of loop steps to calcullate.

This program bases only on the two physical patterns to calculate in the different ways the nine measures. It operates on loops to achieve this effect, what causes a lot of operations to make by processor. Currently, the small scopes prevents from the high usage of processor. But if we want to use wider scopes, then it could cause the problems with weak performance. So here we need the help of physician, to transform the pattern for use in each of nine function. If you are interested in patterns, then here is the link to e-book, that I' ve been using (I took the patterns from it):

It's in Polish language, but I think, that Google Translate can manage... ;) The most important things starts at page 101.
Good luck :)
I have recently too small time to back to this project, so don't hesitate, if you want help.
bcohio2001
Posts: 553
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact: