Example from class on Monday, Jan. 27
Contents
(a)
For the two points P=(1,1,0) and Q=(0,0,1) find the distance between the two points.
P = [1,1,0]; Q = [0,0,1];
a = Q - P % vector from P to Q
distance = norm(a)
a = -1 -1 1 distance = 1.7321
(b)
Find the midpoint R between the points P and Q.
Find the midpoint S between the points P and R. Find the midpoint T between the points R and Q.
Plot the line connecting the points P and Q. Mark the points P,Q,R,S,T.
R = P + .5*a % midpoint of P and Q, same as (P+Q)/2 S = P + .25*a T = P + .75*a plotpts([P;Q],'o-') % plot line from P to Q, mark endpoints with circles hold on % add the following stuff to this plot plotpts([R;S;T],'o') % plot points R,S,T, mark with circles texts(P,'P'); texts(Q,'Q'); % label points texts(R,'R'); texts(S,'S'); texts(T,'T'); hold off % we're done with this plot nice3d % make plot look nice % you can rotate plot with mouse in Matlab window view(10,20) % pick nice angle to look at plot
R = 0.5000 0.5000 0.5000 S = 0.7500 0.7500 0.2500 T = 0.2500 0.2500 0.7500