Ronan

1022 Reputation

14 Badges

13 years, 109 days
East Grinstead, United Kingdom

MaplePrimes Activity


These are questions asked by Ronan

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

I am trying to replace thickness = 0 with thickness = 3 in a list, under the condition leader = 0 

The order of entries in the list is not fixed so it is more akin to a set.

leader:=1;

parms:=[colour=red,thickness=0,linestyle =dash];
 if leader=0 then selectremove(thickness=0,parms);end if;
[op(parms),thickness=3];
display(plottools:-line([1,2], [3,4]),op(parms));

Is there any to export a 3d plot so it could be used as a 3d pdf or some other document type?

Edit: uploaded Maple 3d plot.
 

 

 


 

Download Tetrahedron_Rat_Trig.mw

How should optional input parameters be handled for procedures. The example has three optional inputs 

vars:=[x,y]   ,  clr:="b"   and prnt:="y"  . if one wants to change prnt to"n", vars and clr values must be entered.

{vars:=[x,y]  } , { clr:="b" }  and{ prnt:="y"}  this is a good method because one just enteres prnt="n".  But have to remember the input parameter name prnt.

I have a 3rd option, but it is to complicated and probably unreliable to use in practice.  and with more than 3 optional inputs too difficult to code.

I am wondering  are the other approaches and what is the prefered methodology. I have about 30+ procedures to apply this to in a package.

Edit:-  I can change the prnt to boolean true, false instead of "y" , "n".  That would make the all the optional inputs different types.

In Test1 its should be vars::list:=[x,y] not vars::{list , `string`}:=[x,y]

restart

Geomclr := "b"

"b"

(1)

NULL

NULL

NULL

Test1 := proc (A, B, vars::{list, string} := [x, y], clr::string := Geomclr, prnt::string := "y") if vars::string then clr := vars; vars := [x, y] end if; if clr = "y" or clr = "n" then prnt := clr; clr := Geomclr end if; print(clr); if prnt = "y" then print("good") end if; A*vars[1]+B*vars[2] end proc

NULL

Test1(A, B)

A*x+B*y

(2)

Test1(A, B, [r, s], "n")

Error, (in Test1) invalid left hand side in assignment

 

Test1(A, B, "g")

Error, (in Test1) invalid left hand side in assignment

 

Test1(A, B, "n")

Error, (in Test1) invalid left hand side in assignment

 

Test1(A, B, [x, y], "b", "n")

A*x+B*y

(3)

 

 

NULL

``

NULL

 

NULL

Test2 := proc (A, B, { vars::{list} := [x, y], clr::string := Geomclr, prnt::string := "y" }) print(clr); if prnt = "y" then print("good") end if; A*vars[1]+A*vars[2] end proc

NULL

NULL

Test2(A, B)

A*x+A*y

(4)

Test2(A, B, clr = "r")

A*x+A*y

(5)

Test2(A, B, prnt = "n")

A*x+A*y

(6)

Test2(A, B, prnt = "n")

A*x+A*y

(7)

Test2(A, B, prnt = "n", clr = "green", l = [r, s])

A*x+A*y

(8)

``

 

# 3 This is possible but is a very complicated method of handling the optional inputs and difficult the handle altered sequence on inputs.

NULL

Test3 := proc (A, B, vars::{list, string} := [x, y], clr::string := Geomclr, prnt::string := "y") local varsl, clrl, prntl; global Geomclr; varsl := vars; clrl := clr; prntl := prnt; if vars::string then varsl := [x, y]; if vars = "y" or vars = "n" then prntl := vars; clrl := Geomclr elif vars = "r" or vars = "g" or vars = "b" then clrl := vars end if elif vars::list and clr = "y" or clr = "n" then prntl := clr; clrl := Geomclr end if; if clr = "y" or clr = "n" and vars::string then prntl := clr; clrl := vars end if; print("Colour print out ", clrl); if prntl = "y" then print("This is a test Message") end if; A*varsl[1]+B*varsl[2] end proc

NULL

Test3(A, B)

A*x+B*y

(9)

Test3(A, B, [r, s])

A*r+B*s

(10)

Test3(A, B, [r, s], "n")

A*r+B*s

(11)

Test3(A, B, "n")

A*x+B*y

(12)

Test3(A, B, [r, s], "r", "n")

A*r+B*s

(13)

Test3(A, B, "r", "n")

A*x+B*y

(14)

Test3(A, B, "n", "r")

A*x+B*y

(15)

NULL


 

Download Q_2024-02-25_Test_proc_Args.mw

Using textplot  is there anything that can be done to to increase the offest of alignI would like to raise  P3 at top of graph up a bit and S3 down. they are {centre, above} and {centre,below}. I know I can tie them to a different point  coordinate to begin with but that is messy to control inside a procedure.

1 2 3 4 5 6 7 Last Page 2 of 26