Methods for determining the components and angles of vectors are frequently used in physics and engineering.
The components of a vector refer to the amount of change in the direction of each coordinate axis from the starting point to the end point, which can be determined to clarify the direction and length of the vector.
In this paper, the components and direction of a vector are derived using A-coordinates (4, 2) and B-coordinates (6, 5) as examples and visually confirmed using Python code.
It also explains in detail how to find the angle of a vector and shows an example calculation using the inverse function of tan.
Finding the components of a vector
If the A-coordinate is (4, 2) and the B-coordinate is (6, 5), the components of the vector are
using,
In other words.
This is the result of subtracting the A coordinate (4, 2) from the B coordinate (6, 5). As also shown in the graph, the vector is drawn in the direction from point A (4, 2) to point B (6, 5).
Below is the code for finding the components of the vector.
# To find the components of vector AB, subtract the coordinates of point A from the coordinates of point B. # Vector AB = (x-coordinate of B - x-coordinate of A, y-coordinate of B - y-coordinate of A) # Definition of coordinates. A = (4, 2) B = (6, 5) # Calculate the components of vector AB vector_AB = (B[0] - A[0], B[1] - A[1]) # Use matplotlib to draw the vectors import matplotlib.pyplot as plt # Plot the start and end points of the vector plt.quiver(A[0], A[1], vector_AB[0], vector_AB[1], angles=‘xy’, scale_units=‘xy’, scale=1, colour=‘r’) # Set the coordinate axes plt.xlim(0, 10) plt.ylim(0, 10) plt.grid(True) # Label point A and point B plt.text(A[0], A[1], ‘A(4, 2)’, fontsize=12, verticalalignment=‘bottom’, horizontalalignment=‘right’) plt.text(B[0], B[1], ‘B(6, 5)’, fontsize=12, verticalalignment=‘bottom’, horizontalalignment=‘right’) # Titles and labels plt.title(‘Vector AB’) plt.xlabel(‘x’) plt.ylabel(‘y’) # Show the results plt.show() # Output the components of vector AB vector_AB
Find the direction of the vector.
The approximate direction of a vector can be determined by looking at the signs of its components.
If the value of x is negative, it’s a right-to-left vector, and if y is negative, it’s a top-to-bottom vector.
Now let’s find the angle of the vector.
First, draw a straight line from the endpoint of the vector to the x-axis and use the inverse function of tan to represent it as follows.
Now let’s calculate it.
Let’s find the inverse function of Tan using the math module tatn2() function.
The following code gives an angle of 56.31 degrees.
import math rad = math.atan2(3, 2) th = math.degrees(rad) th = round(th, 2) th
Now let’s also find the angle when x and y are negative.
The following code gives an angle of 123.69 degrees.
import math rad = math.atan2(-3, -2) th = math.degrees(rad) th = round(th, 2) th
When calculating the angle of a vector, the positive direction of the x-axis is 0 and the upward vector is 180 degrees anti-clockwise. In comparison, the opposite is -180 degrees clockwise in the downward direction.
Conclusion.
Finding the components and angles of a vector gives an accurate idea of its orientation and angle in space.
The orientation of a vector is also clear by finding its components from the difference of the coordinates and calculating the angle using the atan2 function.
Using Python code, the results of these calculations can be visualized intuitively and the calculations can be easily checked.
コメント