Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Something goes wrong calculating the slope of the simulation

In this python code we are trying to simulate the path of a frisbee that is being shot from a shooter with a certain angle (alpha0). The angle of attack should be the angle at which its being shot, minus the slope of its path. Thus the angle at which the air hits the frisbee. However something goes wrong here, the AoA is not 0 at the beginning, can someone help fixing our code. I suspect that the method of calculating the slope of the path is wrong.

mport numpy as np
import matplotlib.pyplot as plt

t = np.linspace(0,2,1001)
alpha0 = 26*np.pi*(1/180)
v0 = 9.0
vx0 = np.cos(np.rad2deg(alpha0))*v0
vy0 = np.sin(np.rad2deg(alpha0))*v0
x0 = 0.0
y0 = 1.0
g = -9.81
r_disc = 0.12


def Cd_frisbee(alpha):
    Cd_0 = 0.18
    Cd_alpha = 0.69
    Cd = Cd_0 + (Cd_alpha*(alpha - alpha0)**2)
    return Cd

def Cl_frisbee(alpha):
    Cl_0 = 0.33
    Cl_alpha = 1.9
    Cl = Cl_0 + (Cl_alpha*alpha)
    return Cl


def A_frisbee(alpha):
    A = np.pi*(r_disc**2)*(np.sin(alpha))
    return A

def a_Drag(Cd,A,vx):
    rho = 1.25
    m = 0.125
    ax = -0.5*(Cd*A*rho*(vx**2))/m
    return ax

def a_Lift(Cl, A, vy):
    rho = 1.25
    m = 0.125
    ay = (0.5*(Cl*A*rho*(vy**2))/m) - 9.81
    return ay

def numerical(x0, v0, a_func1, a_func2, t):
    x = np.zeros(len(t))
    y = np.zeros(len(t))
    vx = np.zeros(len(t))
    vy = np.zeros(len(t))
    ax = np.zeros(len(t))
    ay = np.zeros(len(t))
    alpha = np.zeros(len(t))
    dy = np.zeros(len(t))
    dx = np.zeros(len(t))
    vx[0] = vx0
    vy[0] = vy0
    x[0] = x0
    y[0] = y0
    ax[0] = a_func1(Cd_frisbee(alpha0), 0, vx0)
    ay[0] = a_func2(Cl_frisbee(alpha0), 0, vy0)
    alpha[0] = 0
    dy[0] = 0
    dx[0] = 0
    for i in range(len(t) - 1):
        dt = (t[i + 1] - t[i])
        x[i + 1] = x[i] + (vx[i] * dt)
        y[i + 1] = y[i] + (vy[i] * dt)
        vx[i + 1] = vx[i] + (dt * ax[i])
        vy[i + 1] = vy[i] + (dt * ay[i])
        ax[i + 1] = a_func1(Cd_frisbee(alpha[i]), A_frisbee(alpha[i]), vx[i])
        ay[i + 1] = a_func2(Cl_frisbee(alpha[i]), A_frisbee(alpha[i]), vy[i])
        dy[i+1] = (y[i + 1] - y[i])
        dx[i+1] = (x[i + 1] - x[i])
        alpha[i+1] = alpha0 - np.radians(np.arctan(dy[i+1]/dx[i+1]))
    return x, y, vx, vy, ax, ay, alpha, dy, dx


x_num = numerical(x0, v0, a_Drag, a_Lift, t)[0]
y_num = numerical(x0, v0, a_Drag, a_Lift, t)[1]
alpha_num = numerical(x0, v0, a_Drag, a_Lift, t)[6]
vx_num = numerical(x0, v0, a_Drag, a_Lift, t)[2]
dy_num = numerical(x0, v0, a_Drag, a_Lift, t)[7]
dx_num = numerical(x0, v0, a_Drag, a_Lift, t)[8]
"""
ax[0].plot(t, x_num, color='green', linestyle='--')
ax[1].plot(t, y_num, color='green', linestyle='--')
ax[3].plot(t, alpha_num, color='green', linestyle='--')
"""

I have used different starting values such as speed etc. and instead of a smooth path i got strange graphs.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If you look at the documentation of np.cos, you will see that it expects the input in radians, not degrees. So you do not want to use np.rad2deg there. The same is true for np.sin.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading