# Distance between a point and a plane
# A plane in space
var('t,u')
@interact
def _(pt = input_box((1,1,1),length=10,label='Point on Plane'),
pt1 = input_box((2,3,5),length=10,label='Point off Plane'),
a = slider(-4,4,0.1,1),
b = slider(-4,4,0.1,1),
c = slider(-4,4,0.1,1)):
n = vector([a,b,c])
n_norm = norm(n)
G = point3d(pt,size=30,color='blue')
G += point3d(pt1,size=30,color='red')
# Coordinates of a point on the plane
x0 = pt[0]
y0 = pt[1]
z0 = pt[2]
# Coordinates of a point not on the plane and not necessarily directly "above" the first point
x1 = pt1[0]
y1 = pt1[1]
z1 = pt1[2]
# how far to travel on normal vector until you create a right triangle with the given two points.
# This models the formula give below the Theorem that references projection
D = (a*(x1-x0)+b*(y1-y0)+c*(z1-z0))/(a^2+b^2+c^2)
x2 = x0+D*a
y2 = y0+D*b
z2 = z0+D*c
pt2 = (x2,y2,z2)
dist = sqrt((x2-x0)^2+(y2-y0)^2+(z2-z0)^2)
G += point3d((x0+D*a,y0+D*b,z0+D*c),size=30,color='yellow')
G += parametric_plot3d([x0+t,y0+u,z0-a*t/c-b*u/c],[t,-2,2],[u,-2,2],color='green',thickness=10)
G += parametric_plot3d([x0+dist*a*t/n_norm,y0+dist*b*t/n_norm,z0+dist*c*t/n_norm],[t,0,1],color='gray')
G.show(aspect_ratio=[1,1,1],frame=false)
pretty_print("Distance between yellow point and Point on Plane = ",str(dist))
PQ = vector([x1-x0,y1-y0,z1-z0])
# Now, instead just project the vector from the provided point on the plane to the provided point off the plan onto the plane's normal vector
dist_formula = abs(PQ.dot_product(n))/norm(n)
pretty_print("Distance between red point and the Plane using book formula = ",str(dist_formula))
|
Click to the left again to hide and once more to show the dynamic interactive window
|