generated from millerm22/Engineering_4_Notebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Part 2 (Plotting)
86 lines (65 loc) · 2.79 KB
/
Part 2 (Plotting)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import board
import math
import time
import busio
import terminalio
import displayio
import digitalio
import adafruit_displayio_ssd1306
from adafruit_display_shapes.triangle import Triangle
from adafruit_display_shapes.line import Line
from adafruit_display_shapes.circle import Circle
from adafruit_display_text import label
import time
time.sleep(1)
displayio.release_displays()
# Starts Initializing the screen
sda_pin = board.GP14
scl_pin = board.GP15
i2c = busio.I2C(scl_pin, sda_pin)
# Intitializes the I2C
display_bus = displayio.I2CDisplay(i2c, device_address=0x3d, reset=board.GP17)
# Initializes the screen and tells it its address
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=64)
# Tells the screen its limits and how its displayed
splash = displayio.Group()
# Creates the display group
splash.append(Circle(64, 32, 3, outline=0xFFFFFF))
splash.append(Line(0, 32, 128, 32, 0xFFFFFF))
splash.append(Line(64, 0, 64, 64, 0xFFFFFF))
plotting_label = label.Label(terminalio.FONT, x=5, y=5, text="")
# This creates the area where the area will display and where the graph will be
# It also make the axis and the origin
splash.append(plotting_label)
LZADisp = None
def LZ(VX1, VX2, VX3):
LZA = 0.5 * (VX1[0] * (VX2[1] - VX3[1]) + VX2[0] * (VX3[1] - VX1[1]) + VX3[0]* (VX1[1] - VX2[1]))
# this is the formula to find area based off of the coordinates we also could've done this with herrons formula but this is easier because it requires less math
return abs(LZA)
while True:
# point 1 is (VX1[0],VX1[1])
# point 2 is (VX2[0],VX2[1])
# point 3 is (VX3[0],VX3[1])
VX1 = input('Enter X1,Y1:').split(",")
VX2 = input('Enter X2,Y2:').split(",")
VX3 = input('Enter X3,Y3:').split(",")
if LZADisp is not None:
splash.pop()
# Clears old triangle
try:
print(f"The Landing Zone with vertices ({VX1[0]},{VX1[1]}),({VX2[0]},{VX2[1]}),({VX3[0]},{VX3[1]}) is {LZ((int(VX1[0]),int(VX1[1])), (int(VX2[0]),int(VX2[1])), (int(VX3[0]),int(VX3[1])))} square km.")
# This the print that uses the function that was made above.
# It is extremely long because each point had to be indexed here.
#LZAText = print(f"{LZ}km^2")
#splash.append(LZAText)
area = LZ((int(VX1[0]),int(VX1[1])), (int(VX2[0]),int(VX2[1])), (int(VX3[0]),int(VX3[1])))
LZADisp = Triangle(int(VX1[0])+64, 32-int(VX1[1]), int(VX2[0])+64, 32-int(VX2[1]), int(VX3[0])+64, 32-int(VX3[1]), outline=0xFFFFFF)
splash.append(LZADisp)
display.show(splash)
time.sleep(2)
# Shows the Triangle
except:
print("VALUE ERROR RETRY")
# This throws an error if the user inputs the wrong data.
plotting_label.text = f"{area}km2"
#prints the area on the OLED