Demo entry 6658497

Vector Calculation

   

Submitted by Jinhee Park on Nov 07, 2017 at 06:15
Language: Python. Code size: 637 Bytes.

j = 0
while j < (len(matrix) - 1):
	x_sub.append(int(matrix[j+1][2]) - int(matrix[j][2]))
	y_sub.append(int(matrix[j+1][3]) - int(matrix[j][3]))
	j = j + 1
# get x_sub and y_sub which are subtraction of their own list elements

scalar = []

k = 0
while k < (len(matrix) - 1):
	scalar.append(math.hypot(x_sub[k], y_sub[k]))
	k = k + 1
# hypot return the Euclidean norm, sqrt(x*x, y*y) which is the lenght of the vector form
# get scalar

theta = []

l = 0

while l < (len(matrix) - 1):
	try:
		theta.append(math.atan2(-y_sub[l], x_sub[l]))
	except ZeroDivisionError as e:
		theta.append(0)
	l = l + 1
# get theta

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).