from math import tan, pi

from Basic_Functions import get_float, get_integer

print("""
This code calculates the area of a given regular polygon. Please enter the no of sides and length of each side.
""")
while True:
    no_of_sides = get_integer("Sides: ")
    if no_of_sides > 2:
        side_length = get_float("Length: ")
        if side_length > 0:
            area = no_of_sides * (side_length**2) / (4 * tan(pi / no_of_sides))
            print(f"Area =  {area} square units")
        else:
            print('Length of a side cannot be negative')
    else:
        print('Polygon with less than 3 sides cannot be formed')
    print('')
from math import radians, sin, cos, acos

from Basic_Functions import get_float

print('This code calculates distance between any two coordinates on earth. Provide following data.')
while True:
    print("Input coordinates of two points:")
    start_lat = radians(get_float("Starting latitude: "))
    start_lon = radians(get_float("Starting longitude: "))
    end_lat = radians(get_float("Ending latitude: "))
    end_lon = radians(get_float("Ending longitude: "))

    dist = 6371.01*acos(sin(start_lat)*sin(end_lat)+cos(start_lat)*cos(end_lat)*cos(start_lon-end_lon))
    print(f"The distance is {dist} km.")
Beispiel #3
0
print('''
1. First enter the no of circles you want to plot
2. Enter the radius of first circle
3. Enter the coordinates of its centres in the form "x y", for eg, '3 0'
4. Repeat steps 2 and 3 for the no of circles you want to plot.
''')
no = get_integer("No of circles to plot: ")
while no > 0:
    x = []
    y = []

    start = 0
    end = 2 * pi
    i = start

    radius = get_float("Radius: ")
    cx, cy = input("Centre coords: ").split()
    cx, cy = float(cx), float(cy)
    resolution = pi / 180

    while i < end + resolution:
        x.append(cx + radius * cos(i))
        y.append(cy + radius * sin(i))
        i += resolution

    plt.grid(True)
    plt.plot(x, y)
    plt.plot(cx, cy, "o")
    no -= 1

plt.title("Circles")
import matplotlib.pyplot as plt
from Basic_Functions import get_float

print(u"""
A quadratic equation is in the form of ax\u00B2 + bx +c = 0. To plot, please provide a, b, c.
""")
a = get_float("a: ")
b = get_float("b: ")
c = get_float("c: ")

d = (b**2 - (4 * a * c))**0.5
x1 = ((-b) + d) / (2 * a)
x2 = ((-b) - d) / (2 * a)

print(f"Solution to this equation is x = {x1}, {x2}")
l = 2
if x1 <= x2:
    start = x1 - l
    end = x2 + l
else:
    start = x2 - l
    end = x1 + l

resolution = 0.01
x = []
y = []
i = start
while i <= end:
    x.append(i)
    y.append((a * (i**2)) + (b * i) + c)
    i += resolution
Beispiel #5
0
from math import ceil, cos, pi
from Basic_Functions import get_integer, get_float

while True:
    n = get_integer("No of sides: ")
    a = get_float("Each side length: ")
    diagonals = [a]
    d = n - 3

    if d % 2 == 0:
        temp = -1
    else:
        temp = -2

    for i in range(d):
        if i + 1 <= ceil(d / 2):
            value = (diagonals[-1] * cos(pi / n)) + (diagonals[0] * cos(
                (i + 1) * pi / n))
        else:
            value = diagonals[temp]
            temp -= 2
        diagonals.append(round(value, 3))

    for i in range(1, len(diagonals)):
        print(f"Diagonal {i} = {diagonals[i]}")
    print()
import numpy as np
import matplotlib.pyplot as plt
from math import cos, sin, pi
from Basic_Functions import get_float

# t = 2usin(theta)/g
# r = (u^2)sin(2theta)/g
# h = (u^2)sin^2(theta)/2g

g = 9.8
v = get_float("Initial velocity(in m/s): ")
h = 0
theta = get_float("Projectile angle in degrees(in degrees): ") * pi / 180
dx = 0
dy = 0
t = 0
dt = 0.01
vx = v * cos(theta)
vy = v * sin(theta)
tf = 2 * v * sin(theta) / g

horizontal_distance = []
vertical_distance = []
time = []
if tf > 0:
    while t < tf + dt:
        horizontal_distance.append(vx * t)
        h = vy * t - 0.5 * (g * t**2)
        vertical_distance.append(h)
        time.append(t)
        t += dt