FreeBalistic - physical app to calculate ballistic curves

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

FreeBalistic - physical app to calculate ballistic curves

Postby peter-cat » Mar 06, 2019 9:09

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:

Image

Image

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: 1848
Joined: Sep 25, 2005 21:54

Re: FreeBalistic - physical app to calculate ballistic curves

Postby srvaldez » Mar 06, 2019 13:06

hello peter-cat :-)
your project look really good.
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: 8
Joined: Feb 18, 2019 8:03

Re: FreeBalistic - physical app to calculate ballistic curves

Postby peter-cat » Mar 06, 2019 17:22

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: 5614
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: FreeBalistic - physical app to calculate ballistic curves

Postby dodicat » Mar 07, 2019 1:50

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

Code: Select all

Dim  As Integer xres,yres
Screen 20,32,,64
Screeninfo xres,yres
Dim Shared As Any Ptr i:i=Imagecreate(xres,yres,0)

Type v2
    As Single x,y
End Type

Type screendata
    As Integer w,h,depth,bpp,pitch
    As Any Pointer row
    As Ulong Pointer pixel32
End Type

Dim Shared As screendata ThisScreen,thisimage
With ThisScreen
    Screeninfo .w,.h,.depth,.bpp,.pitch
    .row=Screenptr
End With
With thisimage
    Imageinfo i,.w,.h,.bpp,.pitch,.row
    .depth=32
End With

Const k=1   
Const g=9.81  'gravity
Const m=5     'mass
Const 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<340

Sub 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
    Loop
End Sub
'Bressenham line thickened
Sub 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 yp
End Sub

Sub 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 Sub

Sub clearimage()
    Line i,(0,0)-(1023,767),Rgba(0,0,0,220),bf
    drawline(thisimage,990,750,0,20,Rgb(0,200,0))
End Sub

Function 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 sleeptime
End Function

Sub 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<0
End Sub

Sub 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 Sub


Dim As String key

Dim As Integer cx=200,cy=320,powder=200,theta=40
Dim As v2 startpos
Dim As Single a=theta*pi/180
Do
    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: 8
Joined: Feb 18, 2019 8:03

Re: FreeBalistic - physical app to calculate ballistic curves

Postby peter-cat » Mar 14, 2019 12:17

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/
Feel invited to download this update!

Screen of currently released version:

Image

Have Fun, this time with english GUI !

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 3 guests