221 - Lines and Planes in Space

1131 days ago by travis

# A line in space from sage.plot.plot3d.plot3d import axes var('t') @interact def _(pt = input_box((1,1,1),length=10),a = slider(-4,4,0.1,1),b = slider(-4,4,0.1,1),c = slider(-4,4,0.1,1)): G = point3d(pt,size=30,color='blue') G += axes(6, color='black') x0 = pt[0] y0 = pt[1] z0 = pt[2] G += parametric_plot3d([x0+a*t,y0+b*t,z0+c*t],[t,-2,2],color='green',thickness=10) G.show(aspect_ratio=[1,1,1],frame=false) 
       
pt 

Click to the left again to hide and once more to show the dynamic interactive window

# A plane in space from sage.plot.plot3d.plot3d import axes var('t,u') @interact def _(pt = input_box((1,1,1),length=10),a = slider(-4,4,0.1,1),b = slider(-4,4,0.1,1),c = slider(-4,4,0.1,1)): G = point3d(pt,size=30,color='blue') G += axes(6, color='black') x0 = pt[0] y0 = pt[1] z0 = pt[2] G += parametric_plot3d([x0+t,y0+u,z0-a*t/c-b*u/c],[t,-2,2],[u,-2,2],color='lightyellow',thickness=10) G.show(aspect_ratio=[1,1,1],frame=false) 
       
pt 

Click to the left again to hide and once more to show the dynamic interactive window

# Angle between two planes - this is example 4 var('x,y,t') z1 = 2*y-x z2 = (2*x+3*y)/2 n1 = (1,-2, 1) n2 = (2,3,-2) G = plot3d(z1,(x,-2,2),(y,-2,2),color='lightblue') G += plot3d(z2,(x,-2,2),(y,-2,2),color='lightgreen') G += parametric_plot3d([t,4*t,7*t],[t,-1,1],thickness=10,color='red') # line of intersection # draw both normal vectors at (0,0,0) G += arrow((0,0,0),n1,width=3,color='blue') G += arrow((0,0,0),n2,width=3,color='green') G.show(aspect_ratio=[1,1,1],frame=false) 
       
# 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)) 
       
Point on Plane 
Point off Plane 

Click to the left again to hide and once more to show the dynamic interactive window

# Distance between a point and a line in space var('t') @interact def _(pt = input_box((1,1,1),label="Point on the line",length=10), pt1 = input_box((2,-4,3),label="Point off the line",length=10), a = slider(-4,4,0.1,1), b = slider(-4,4,0.1,1), c = slider(-4,4,0.1,1)): direction = vector([a,b,c]) d_norm = norm(direction) G = point3d(pt,size=25,color='blue') G += point3d(pt1,size=30,color='yellow') x0 = pt[0] y0 = pt[1] z0 = pt[2] x1 = pt1[0] y1 = pt1[1] z1 = pt1[2] PQ = vector([x1-x0,y1-y0,z1-z0]) dist = (abs(PQ.dot_product(direction))/norm(direction)^2) Proj = -dist*direction # do I need an absolute value somewhere around here? pt2 = (x0+Proj[0],y0+Proj[1],z0+Proj[2]) G += parametric_plot3d([x0+a*t,y0+b*t,z0+c*t],[t,-2,2],color='lightgreen',thickness=8) # the line G += parametric_plot3d([x0+Proj[0]*t,y0+Proj[1]*t,z0+Proj[2]*t],[t,0,1],color='green',thickness=10) # the projection of PQ onto the direction vector G += parametric_plot3d([x0+dist*a*t/d_norm,y0+dist*b*t/d_norm,z0+dist*c*t/d_norm],[t,0,1],color='gray') G += line3d([pt1,pt2],coloro='gray') G.show(aspect_ratio=[1,1,1],frame=false) dist_formula = abs(PQ.cross_product(direction))/norm(direction) pretty_print("Distance between yellow point and the line using book formula = ",str(dist_formula)) 
       
Point on the line 
Point off the line 

Click to the left again to hide and once more to show the dynamic interactive window