Targil 7 - mupad questions - solution notes
Question 1a
q1a:=proc(p1,p2,p3,p4)
local V;
begin
V:=abs(linalg::scalarProduct( p2-p1, linalg::crossProduct( p3-p1, p4-p1 ))/6);
return(V);
end_proc
p1:=matrix(3,1,[0,0,0]); p2:=matrix(3,1,[1,0,0]); p3:=matrix(3,1,[0,1,0]); p4:=matrix(3,1,[0,0,1]);
Example
q1a(p1,p2,p3,p4)
Plot
plot( plot::Line3d(p1,p2) , plot::Line3d(p1,p3) , plot::Line3d(p1,p4) ,
plot::Line3d(p2,p3) , plot::Line3d(p2,p4) , plot::Line3d(p3,p4) )
Question 1b
Take the planes to be written as equations for x,y,z (see example below)
Note the "solve" statement below gives something of the form [x=.. , y=.., z=..]
- change this to the form of a vector
q1b:=proc(P1,P2,P3)
local p;
begin
p:=op(solve({P1,P2,P3},{x,y,z}));
p:=matrix(3,1,[op(op(p,1),2), op(op(p,2),2), op(op(p,3),2)]);
return(p);
end_proc
Example
q1b( 2*x+y=3, x+3*z=1, x+y-z=4 )
Plot (I rotated the output)
plot( plot::Plane(matrix(3,1,[0,3,0]), matrix(3,1,[2,1,0]), Color=RGB::Red ),
plot::Plane(matrix(3,1,[1,0,0]), matrix(3,1,[1,0,3]), Color=RGB::Green ),
plot::Plane(matrix(3,1,[4,0,0]), matrix(3,1,[1,1,-1]), Color=RGB::Blue ),
plot::Point3d(matrix(3,1,[-2,7,1]), Color=RGB::Black) )
Question 1c
combine the last two
q1c:=proc(P1,P2,P3,P4)
local V;
begin
V:=q1a( q1b(P1,P2,P3), q1b(P1,P2,P4), q1b(P1,P3,P4), q1b(P2,P3,P4) );
end_proc
Example
q1c( 2*x+y=3, x+3*z=1, x+y-z=4, x-y-3*z=-2)
Questions 2a and 2b - same as 2c but remove all the z coordinates!
Question 2c
take the 2 points as vectors, and the plane as an equation of the form
ax+by+cz+d=0
q2a:=proc(p1,p2,P)
local s1,s2;
begin
s1:=subs( P, x=p1[1], y=p1[2], z=p1[3]);
s2:=subs( P, x=p2[1], y=p2[2], z=p2[3]);
if s1*s2>0 then
return(+1);
elif s1*s2<0 then
return(-1);
else
return(0);
end_if;
end_proc
Example: same side
q2a( matrix(3,1,[1,0,0]) , matrix(3,1,[2,0,0]), x )
Example: opposite sides
q2a( matrix(3,1,[1,0,0]) , matrix(3,1,[-1,0,0]), x )
Question 2d
l1=list of points, l2=list of planes
answers: 1 if "yes", 0 if "no"
q2d:=proc(l1,l2)
local i,j,k,s,t;
begin
s:=1;
for i from 1 to nops(l1) do
for j from i+1 to nops(l1) do
t:=0;
for k from 1 to nops(l2) do
if q2a(l1[i],l1[j],l2[k])=-1 then
t:=1;
end_if;
end_for;
if t<>1 then
s:=0;
end_if;
end_for;
end_for;
return(s);
end_proc
Examples
l1:=[ matrix(3,1,[1,1,1]), matrix(3,1,[1,1,-1]), matrix(3,1,[1,-1,1]), matrix(3,1,[-1,1,1]),
matrix(3,1,[1,-1,-1]), matrix(3,1,[-1,1,-1]), matrix(3,1,[-1,-1,1]), matrix(3,1,[-1,-1,-1]) ]
l2:=[x,y,z]
this l2 is the 3 planes x=0, y=0, z=0
q2d(l1,l2)
l1:=[ matrix(3,1,[1,1,1]), matrix(3,1,[1,1,2])]
q2d(l1,l2)
Question 3
q3:=proc(a1,b1,r1,a2,b2,r2)
local d,i;
begin
d:=sqrt( (a1-a2)^2 + (b1-b2)^2 );
if d+r2<r1 then
i:=1;
elif d+r1<r2 then
i:=2;
elif d+r1=r2 or d+r2=r1 or r1+r2=d then
i:=3;
elif d<r1+r2 then
i:=4;
else
i:=5;
end_if;
return(i)
end_proc
extra function to draw what is happening
dr3:=proc(a1,b1,r1,a2,b2,r2)
begin
plot( plot::Circle2d(r1,[a1,b1], Color=RGB::Red), plot::Circle2d(r2,[a2,b2],Color=RGB::Blue) )
end_proc
dr3( 1,1,10,2,4,3 ); q3( 1,1,10,2,4,3 )
dr3( 2,4,3,1,1,10 ); q3( 2,4,3,1,1,10 )
dr3( 2,4,3,2,11,4 ); q3( 2,4,3,2,11,4 )
dr3( 2,4,3,1,1,4 ); q3( 2,4,3,1,1,4 )
dr3( 9,4,3,1,1,4 ); q3( 9,4,3,1,1,4 )