Python | Triangle Law of Vector Addition (Matplotlib Arrow Example)

Here, we are going to learn about the triangle law of vector addition (matplotlib arrow example) and its Python implementation.
Submitted by Anuj Singh, on August 04, 2020

There is a law of vector addition in physics, that is commonly known as the triangular law of vector addition and in this article, we are going to draw the vector diagram for the same using arrows in python. This example illustrates one of the very common and good examples of applications of arrows in real life.

#Vector A
plt.arrow(0.05, 0.15, 0.4, 0.15, head_width=0.02, head_length=0.04)

#Vector B
plt.arrow(0.45, 0.3, 0.2, 0.5, head_width=0.02, head_length=0.04)

#Sum of the Vectors as A + B
plt.arrow(0.05, 0.15, 0.59, 0.65, head_width=0.02, head_length=0.04)

Illustration:

Python | Triangle Law of Vector Addition (Matplotlib Arrow Example)

Python code for triangle law of vector addition (matplotlib arrow example)

import matplotlib.pyplot as plt

plt.figure()
plt.arrow(0.05, 0.15, 0.4, 0.15, head_width=0.02, head_length=0.04)
plt.text(0.2, 0.14, 'Vector A')

plt.arrow(0.45, 0.3, 0.2, 0.5, head_width=0.02, head_length=0.04)
plt.text(0.6, 0.6, 'Vector B')

plt.arrow(0.05, 0.15, 0.59, 0.65, head_width=0.02, head_length=0.04)
plt.text(0.28, 0.45, 'Vector A + Vector B', rotation=40)


plt.title('Triangle Law of Vector Addition')
plt.show()

Output:

Output is as figure


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.