Arc

Published on February 2017 | Categories: Documents | Downloads: 70 | Comments: 0 | Views: 487
of 3
Download PDF   Embed   Report

Comments

Content

% Draw an arc between two points
p1=[-2 -2 -3];
p2=[10 15 20];
% Circle x²+y²+z²=Constant
%=> z=sqrt(Constant-x²-y²-);
Center=((p2+p1))./2;
xc=Center(1);
yc=Center(2);
zc=Center(3);
% Radius
R=norm((p2-p1))/2;
%Min=min(min(p1,p2));
%Max=max(max(p1,p2));
%x=linspace(Min,Max,20);
%y=linspace(Min,Max,20);
x=linspace(p1(1),p2(1),200);
y=linspace(p1(2),p2(2),200);
z=zc+sqrt((R^2)-((x-xc).^2)-((y-yc).^2));
figure, plot3(x,y,z), grid on, hold on
plot3(p1(1),p1(2),p1(3),'*','MarkerSize',10),
plot3(p2(1),p2(2),p2(3),'*','MarkerSize',10),
hold on, plot3(xc,yc,zc,'*','MarkerSize',10)
-----------------------------------------------------------------% CCW arc from P1 to P2 with length L
% (reverse points for CW arc)
P1=[150,300]; P2=[500,600];
P=P2-P1;
[ThC,C]=cart2pol(P(1),P(2));
f=inline('2*L*sin(Th/2)-C*Th','Th','L','C');
options=optimset('Display','off');
for inc=50:100:950
L=C+inc;
Th=fzero(f,sqrt(24*(1-C/L)),options,L,C);
R=C/(2*sin(Th/2));
[x,y]=pol2cart(ThC+(pi-Th)/2,R);
CC=P1+[x,y];
P=P1-CC;
ThP1=cart2pol(P(1),P(2));
[x,y]=pol2cart(linspace(ThP1,ThP1+Th),R);
plot(x+CC(1),y+CC(2)); hold on
end
daspect([1,1,1]); grid; hold off
-------------------------------------------------------------------v = 0:.01:1;
[x,y]= meshgrid(v,v);
z = sin(4*x+5*y).*cos(7*(x-y))+exp(x+y);
mesh(x,y,z)

% pick two arbitrary points
P1 = [.2 .3];
P2 = [.6 .9];
% bulid a parametric curve
t = (0:.01:1)';
% a straight line between the points
L_1 = (1-t)*P1 + t*P2;
% plus a parabolic offset, as a function of the
% parameter C. Thus as C --> 0, the curve approaches
% a straight line.
C = .5;
N = (P1-P2)*[0 -1;1 0];
L_2 = L_1 + C*(t.*(1-t))*N;
% Interpolate the parabolic curve to get z(x,y)
z_path = interp2(x,y,z,L_2(:,1),L_2(:,2));
% and plot the parabolic path in the surface
hold on
plot3(L_2(:,1),L_2(:,2),z_path,'r-')
------------------------% y=x^2/4p
% p is focal distance from vertex
%(x,y) is any point on curve
x=linspace(-5,5,100); % 100 point on curve
p=5; %
y=(x.^2)/4*p;
plot(x,y);
hold on;
stem(0,p,'r')
---------------------% parabola equation y = a * x^2 + y0
x0 = 0; y0 = 0.1;
x1 = 10; y1 = 1;
a = (y1 - y0) / (x1 * x1)
%
%
x
y

because y is horizontal axis and x is vertical axis
draw like this:
= [-x1 : 0.1 : x1]'; % draw range of x
= a * x.^2 + y0; % equation of parabola

plot(y, x, 'r')
hold on
plot(-y, x, 'g')
hold off

% draw red parabola
% draw green parabola

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close