In physics and math, a vector is a quality that has both direction and magnitude. Direction refers to the heading of the object, which is usually represented in degrees or cardinal directions such as north, south, east, or west. The magnitude can be anything ranging from how fast the object is traveling, it's distance, or the amount of force it exerts. Examples of a vector quality would be something like an airliner flying at 230 mph while traveling 35° in relation to the equator or the force of two groups of people in a tug of war. Using this information is useful for finding out stuff like how fast a car is moving after a collision or how much force it would take a lumberjack to cut down a tree.
Vector problems deal with adding or subtracting vectors with one another, and typically look like this:
A Space Shuttle is preparing to land at Kennedy Space Center and is flying to the runway at 250 mph at an 120° angle. However, there are 35 mph wind gusts from the north that is pushing against the Shuttle. What is the Space Shuttles actual magnitude and direction?
In this problem, the Space Shuttle is coming in at a magnitude of 250 mph and a direction of 120°, while the wind is pushing it at an angle of 270° at 35 mph. The goal is to find the magnitude and direction the Shuttle is actually traveling. We can find this by separating the two vectors into two right triangles. Using the magic of SohCahToa (Sine(opposite/hypotenuse), Cosine(adjacent/hypotenuse), Tangent(opposite/adjacent)), it's possible to get the opposite(o) and adjacent(a) sides of each triangle. It would look something like this:
Triangle A (Space Shuttle):
Sin120 = (o/250)
o = 216.51 mph
Cos120= (a/250)
a = 125 mph
Triangle B (Wind):
Sin270 = (o/35)
o = -35 mph
Cos270 = (a/35)
a = 0 mph
Since the opposite and adjacent sides represent the values on the x axis and y axis respectively, we can make ordered pairs for each triangle:
Triangle A: < -125, 216.51>
Triangle B: < 0, -35 >
We can add these ordered pairs together to find the opposite and adjacent sides of the resulting vector triangle. However, before we can do this, we have to determine what part of the ordered pair is negative and positive by examining what sector the vectors angle lies on something known as the unit circle:
The unit circle is just the standard grid with the x and y axis on it, but it has multiple angles jutting out from the center. The idea is that certain angles lie on the positive and negative sides of the x and/or y axis, with certain combinations being separated into specific sectors numbered 1-4 at 90° increments ordered in a counterclockwise direction. For example, in sector 2 only the y-axis is positive, while in sector 3, both axis's are negative. According to the chart, the Space Shuttle is traveling at an angle of 120°, an angle within sector 2, so the x-axis value of 125 becomes negative. The wind gusts are at angle of 270°, which is in sector 3, so both the x and y components are negative. It is only after this determination that we can proceed to add them together:
< -125, 216.51 >
+ < -0, -35 >
< -125, 181.51 >
We now have the adjacent (y) and opposite (x) components of the resultant vector, allowing for the shuttles actual magnitude to be solved. To solve for magnitude, we use the Pythagorean Theorem
(a² + b² = c² or o² + a² = h²) to solve what is essentially the hypotenuse of the resultant triangle:
-125² + 181.51² = c²
√48570.88 = √c²
c = 220.39 mph
Finally, we can solve for the direction by using arc tangent (𝜽 = tan⁻¹(a/o)):
𝜽 = tan⁻¹(-125 / 181.51)
𝜽 = -34.55°
Because the value 125 is negative, the angle has been inverted and flipped on both axis's. In order to get the proper angle, we have to add 180° to the direction, which gives us 145.45°. So the answer would be that the Space Shuttles actual heading is 220.39 mph @ 145.45°.
This can be a lot of work to do, especially when you have to do an entire packet based on these problems, which is where my program comes in:
# Vector addition/subtraction magnitude and direction finder V.0.1
# Nathan Czaja, 5/2/2017
import math
# Vector Input
First_Angle = float(input("First Angle:"))
First_Mag = float(input("First Magnitude:"))
First_Sector = float(input("First Sector:"))
Second_Angle = float(input("Second Angle:"))
Second_Mag = float(input("Second Magnitude:"))
Second_Sector = float(input("Second Sector:"))
#Find Opposite and Adjacent
#(<X1,Y1>)
Y1 = abs(First_Mag * math.sin(math.radians(First_Angle)))
X1 = abs(First_Mag * math.cos(math.radians(First_Angle)))
#(<X2,Y2>)
Y2 = abs(Second_Mag * math.sin(math.radians(Second_Angle)))
X2 = abs(Second_Mag * math.cos(math.radians(Second_Angle)))
#Define Sector (First)
if First_Sector == 4:
Y1 = Y1 * -1
elif First_Sector == 3:
Y1 = Y1 * -1
X1 = X1 * -1
elif First_Sector == 2:
X1 = X1 * -1
else:
Y1 = Y1
X1 = X1
#Define Sector (Second)
if Second_Sector == 4:
Y2 = Y2 * -1
elif Second_Sector == 3:
Y2 = Y2 * -1
X2 = X2 * -1
elif Second_Sector == 2:
X2 = X2 * -1
else:
Y2 = Y2
X2 = X2
# New Vector Order Pair (<X3,Y3>)
Y3 = Y2+Y1
X3 = X2+X1
#New Vector Magnitude
New_Mag = math.sqrt((Y3**2)+(X3**2))
#New Vector direction
New_Divide = Y3/X3
New_Angle = math.atan((New_Divide))
#Convert New_Angle to degrees
New_Angle = math.degrees(New_Angle)
print("\n*Answers rounded to hundredths place")
print("Vector Component Ordered Pair:\n"\
"<",round(X1,2),",",round(Y1,2),">\n"\
"<",round(X2,2),",",round(Y2,2),">\n")
print("Resulting Ordered Pair:\n"\
"<",round(X3,2),",",round(Y3,2),">\n")
print("Resulting Magnitude:\n",round(New_Mag,2))
print("Resulting Direction:\n",round(New_Angle,2))
This is what I call the Vector Addition/Subtraction Magnitude and Direction Finder (or VASMaDiF). What it does is take in input from the user, essentially do all the math we used to solve the problem above, and display the answers.
It first imports the math module, as the functions we need like sine, cosine, tangent, and square root, aren't available by default. The program then asks for the angle, magnitude, and sector of each vector from the user. Since the values entered are considered strings, they have to be converted into actual numbers to be useful, in this case floating point numbers for added accuracy.
It then solves for each vectors components (remember the right triangles?) by using the math.sin() and math.cos() functions. These functions output the answer in radians, so it is necessary to convert them into degrees with the math.radians() function. The opposite and adjacent components then become absolute numbers with the abs() function, which is necessary for the next piece of code, where it is important for every variable used to be positive rather than negative.
2 sets of If-Elif-Else functions (one for each vector) then determine if the x or y axis is negative based on what sector the vector's angle lies. Some problems will have angles in sectors were they do not belong (for example: 45° South of West, which is in sector 3, so it would actually be 225°), so we can make their x and/or y axis negative as per the sector entered, giving us the correct values.
Next, the new ordered pairs are added together so we can solve for magnitude and direction. To find magnitude, we first square the opposite (Y3) and the adjacent (X3) by using the ** exponential mathematical operator followed by 2. Then they are added and square rooted with the math.sqrt() function. To find the direction, Y3 is divided by X3 and the result goes through an math.atan() (arc tangent) function. Since the answer is also in radians, we use a math.degree function to convert it into degrees (I'm uncertain why math.radians doesn't work in this case). Determining whether to add 180° is up to the user.
Finally, the program spits out the answers in print statements. This is where a new function comes into play: round(). I wanted to round the answer to the hundredths place, so I placed the variables into the round() function followed by a comma and a number that indicates to the place it's rounded to, which in this case is 2.
If we enter the values expressed in the example problem, we get this as the output:
*Answers rounded to hundredths place
Vector Component Ordered Pair:
< -125.0 , 216.51 >
< -0.0 , -35.0 >
Resulting Ordered Pair:
< -125.0 , 181.51 >
Resulting Magnitude:
220.39
Resulting Direction:
-55.45
It's pretty much the same, except for the direction not being added with 180°. This program will pretty much help with any problem involving only 2 vectors, but it can be defeated if your solving for one of the original vectors. This probably could be remedied in another version, however as the vector unit in precalc has been finished already, there currently is no point in me modifying the code.
*update: inserted code
No comments:
Post a Comment