close all       % Vi stänger alla figurfönster
figure(1)

display('Maximera figurfönstret')
pause
R=get(1,'Position');

title('\bf Exempel 10: Vi ritar en rät linje genom punkten  P = [x0, y0, z0] i riktningen  v = [a, b, c]')
input('')

P=input('Ange P:  P = ');

v=input('Ange v:  v = ');

t=-3:1:3;

x=P(1)+t.*v(1);
y=P(2)+t.*v(2);
z=P(3)+t.*v(3);

hold off

xr=min(x):.1:max(x);yr=min(y):.1:max(y);
[X,Y]=meshgrid(xr,yr);
Z=zeros(size(X));
mesh(X,Y,Z);hold on

plot3(P(1),P(2),P(3),'ro');
plot3(x,y,z,'LineWidth',2);
plot3([P(1) P(1)+v(1)],[P(2) P(2)+v(2)],[P(3) P(3)+v(3)],'r','LineWidth',2)
xlabel('x'),ylabel('y'),zlabel('z')
title('\bf Rät linje:   (x, y, z) = P + tv,   - \infty < t < \infty .', 'FontSize',12)
shg
pause


figure(2)
set(2,'Position',R)

title('\bf Exempel 12:   En konisk skruvlinje', 'FontSize',12)
pause(2)
xm=-40:20:40;ym=-40:20:40;
[X,Y]=meshgrid(xm,ym);Z=zeros(size(X));
mesh(X,Y,Z);
hold on
title('\bf Exempel 12:   En konisk skruvlinje;   x = tcos(t),  y = tsin(t),  z = t   - \infty < t < \infty .', 'FontSize',12)
t=0:.05:8.*pi;x=t.*cos(t);y=t.*sin(t);z=t;
plot3(x,y,z,'LineWidth',2)
shg
pause

figure(3)
set(3,'Position',R)

title('\bf Nu ger vi oss på andragradskurvor !', 'FontSize',12)

pause(3)

title('\bf Ellipsen:   x^2/a^2 + y^2/b^2 = 1,    x = acos(t),  y = bsin(t),  0 < t < 2\pi ', 'FontSize',12)
hold on
t=0:.01:(2.*pi+.005);
a=1;b=2; x=a.*cos(t);y=b.*sin(t);
plot(x,y,'LineWidth',2),axis equal
shg
pause(2)
grid on
gtext('\bf x^2 + y^2/4 = 1', 'FontSize',13)
pause

figure(4)
set(4,'Position',R)

title('\bf Hyperbel:   x^2/a^2 - y^2/b^2 = 1,    x = acosh(t),  y = bsinh(t),    - \infty < t < \infty ', 'FontSize',12)
hold on
t=-2:.01:2;
a=3;b=2; x=a.*cosh(t);y=b.*sinh(t);
plot(x,y,'b',-x,y,'b','LineWidth',2),axis equal
shg
pause(2)
grid on
gtext('\bf x^2/9 - y^2/4 = 1', 'FontSize',13)
pause

figure(5)
set(5,'Position',R)

title('\bf Parabel:  x = ay^2  eller  y = bx^2', 'FontSize',12)
hold on;
y = -4:.02:4; x = .5.*y.^2;
plot(x,y,'LineWidth',2), axis equal
shg
pause(2)
grid on
gtext('\bf x = y^2/2', 'FontSize',13)
