Robotic Mechanics and Modeling/Kinematics/Additional Examples for Vectors

Example 1 (Spring 20 - Team 4)

edit

Example: A particle has position vector  . What is its distance from the origin ?

If that distance is instead changed to  , what is its new position vector?

%reset -f
import numpy as np
P = np.array([3,4,5])#Initial Position Vector
MagP = np.linalg.norm(P) #magnitude
print(MagP)

PUnit = P/MagP #Unit vector (Direction vector)
newPos = 12 #new distance
PNew = PUnit*newPos #Multiply unit direction vector by distance
MagPNew = np.linalg.norm(PNew) #check distance
print(PNew)
print(MagPNew)

The initial distance of the particle is outputted as  . The new vector is  , and the last line of code checks the new magnitude, which shows that the magnitude (or distance from the origin) is   as intended.

Example 2 (Team 5, Spring 20)

edit

An Example of Representing the Cross Product of Two Vectors

edit

An example of how to find the cross product of a vector   and vector   in IPython.

  1. Example: A triangle has 3 points. Point O at the origin (0,0), point A (3,3) and point B (5,0). Using vectors AO and BO, calculate the area of the triangle. The area of a triangle can be calculated using the following equation: 1/2 *   x  


 
%reset -f
import numpy as np
AO = np.array([3,3])
BO = np.array([5,0])
Area = np.cross(BO,AO)*.5
print ("The area of the triangle is", (Area))

The area of the triangle is 7.5 m^2

Example 3 (Team 6, Spring 20)

edit

Examples for various Vector operations

edit

Python can handle many Vector Operations. This code presents examples of basic arithmetic, such as addition, subtraction, multiplication, and division. All of which are standard procedures. The more detailed syntax arises when a dot product is desired. For the code to understand the dot product of Q dot V the code must be written as "q.dot(v) ". This snippet of code also highlights the simplicity in assigning a variable equal to a scalar value and then implementation of that variable to multiply it by the vector.

%reset -f
from numpy import array
print("Vectors")
v = array([4, 6, 8])
print("V is",v)
q= array ([2, 7, 9])
print("Q is",q)
print("Vector Addition")
z = v+q
print("Z is V +Q Z:",z)
print("Vector Subtraction")
w =q-v
r =v-q
print("W is Q-V",w)
print("R is V minus Q",r)
print("Vector Mulitplication")
c = v*q
print("C is V*Q",c)
print("Vector Division")
d = q / v
print("D is q/v or (q1/v1,q2/v2,q3/v3)",d)
print("Vector Dot Product")
f = q.dot(v)
print("F is equal to q dot product times v",[f])
print("Vector Scalar Multiplication")
print("Variable s is equal to 5")
s = 5
g = s*q
print("G is s times the vector Q",g)