Question: Handling lists and vectors for 3D lines. Changing the colour of plot3d lines?

Was experimenting with methods to handle the representation of 3D lines and plotting them. Where I normally use a point and a direction vector to dascribe the line.

With a bit of experimenting I see the element wise operation `+`~  or  `-`~  using prefix notation saves a lot of time converting vector to lists and vice a versa.  Would be interested to know if there are better techniques.

On the plotting side using plot3d Can the colour of the lines be changed individually? Or should I use a different plotting command?

restart

with(plottools):

l:=([2,-3,1],<3,7/9,6>);   # 3d line point + vector

P:=[7,-8,9]

l := [2, `&ndash;`(3), 1], Vector(3, {(1) = 3, (2) = 7/9, (3) = 6})

 

[7, -8, 9]

(1)

pl:=`+`~(lambda*l[2],l[1]); #3d line as vector eqn

 

Vector(3, {(1) = 3*lambda+2, (2) = (7/9)*lambda-3, (3) = 6*lambda+1})

(2)

vnl:=`-`~(pl,P) ; #vector from Point P to 3D line

 

Vector(3, {(1) = 3*lambda-5, (2) = (7/9)*lambda+5, (3) = 6*lambda-8})

(3)

vnl.l[2] assuming `real` ; #dot product of vectors= 0 when perpendicular

 

(3694/81)*lambda-532/9

(4)

sol:=solve( { (4) }, [lambda] )[];

[lambda = 2394/1847]

(5)

intP:=eval(pl,sol)  #intersection point

Vector(3, {(1) = 10876/1847, (2) = -3679/1847, (3) = 16211/1847})

(6)

l2:=P,eval(vnl,sol) ;  #perpendicular 3D line through P

l2 := [7, `&ndash;`(8), 9], Vector(3, {(1) = -2053/1847, (2) = 11097/1847, (3) = -412/1847})

(7)

pl2:=`+`~(lambda*l2[2],l2[1]); #3D line as vector eqn

Vector(3, {(1) = -(2053/1847)*lambda+7, (2) = (11097/1847)*lambda-8, (3) = -(412/1847)*lambda+9})

(8)

plots:-display(plot3d([pl,pl2],lambda=-.5..1.8,thickness=0,colour=[orange,purple],axes=normal,scaling=constrained),
                point(P,colour=blue ,symbolsize=15,symbol=solidsphere),
                point(l[1],colour=green ,symbolsize=15,symbol=solidsphere),
                point(eval(pl,sol),colour=red ,symbolsize=15,symbol=solidsphere),
                arrow(l,0.2, 0.4, 0.1,colour=green),
                arrow(l2,0.2, 0.4, 0.1,colour=blue));

 

  

 


 

Download Perpendicular_3D_lines.mw

Please Wait...