Given the following code, what will be the output?
import math
def distance(x1, y1, x2, y2):
return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
print(distance(1, 1, 4, 5))
Given the following code, what will be the output?
import math
def dot_product(v1, v2):
return sum(x * y for x, y in zip(v1, v2))
v1 = [1, 2, 3]
v2 = [4, 5, 6]
print(dot_product(v1, v2))
Given the following code, what will be the output?
import math
def cross_product(v1, v2):
return [v1[1] * v2[2] - v1[2] * v2[1], v1[2] * v2[0] - v1[0] * v2[2], v1[0] * v2[1] - v1[1] * v2[0]]
v1 = [1, 2, 3]
v2 = [4, 5, 6]
print(cross_product(v1, v2))
Given the following code, what will be the output?
import math
def line_intersection(m1, c1, m2, c2):
x = (c2 - c1) / (m1 - m2)
y = m1 * x + c1
return x, y
print(line_intersection(2, 3, -1, 1))
Given the following code, what will be the output?
import math
def plane_intersection(p1, n1, p2, n2):
v1 = Vector(*p1)
v2 = Vector(*n1)
v3 = Vector(*p2)
v4 = Vector(*n2)
v5 = v2.cross(v4)
x = v5.cross(v2)
y = x.cross(v5)
return v3 + y.scale((v1 - v3).dot(x) / y.dot(x))
p1 = (1, 2, 3)
n1 = (4, 5, 6)
p2 = (7, 8, 9)
n2 = (10, 11, 12)
print(plane_intersection(p1, n1, p2, n2))
Which of the following code snippets can be used to find the intersection point of two lines given their slope and y-intercept?
Which of the following code snippets can be used to find the equation of a line given two points on the line?
Which of the following code snippets can be used to calculate the dot product of two vectors in Python?
Which of the following code snippets can be used to calculate the cross product of two vectors in Python?
Which of the following code snippets can be used to perform addition of two vectors in Python?