Sunteți pe pagina 1din 3

1.

Write a Matlab code to find a circle inscribed inside the triangle


with maximum radius.

clc
clear all
x1=input('give value of x1 ');x2=input('give value of x2 ');
x3=input('give value of x3 ');
y1=input('give value of y1 ');y2=input('give value of y2 ');
y3=input('give value of y3 ');
z=2*ones(101,1)';
a=sqrt((x3-x2)^2+(y3-y2)^2);
b=sqrt((x3-x1)^2+(y3-y1)^2);
c=sqrt((x1-x2)^2+(y1-y2)^2);
s=(a+b+c)/2;
fac=sqrt(((s-b)*(s-c))/(s*(s-a))); %this is value of tanA/2
r=(s-a)*fac;
c1=(a*x1+b*x2+c*x3)/(a+b+c);
c2=(a*y1+b*y2+c*y3)/(a+b+c);
x=x1:(x2-x1)/100:x2; %x3<x1<x2
y=y1+((y2-y1)/(x2-x1))*(x-x1); %y1<y2<y3
xx=x2:(x3-x2)/100:x3;
yy=y2+((y3-y2)/(x3-x2))*(xx-x2);
xxx=x3:(x1-x3)/100:x1;
yyy=y3+((y1-y3)/(x1-x3))*(xxx-x3);
plot(x,y,xx,yy,xxx,yyy)
hold on
circleNEW(c1,c2,r)
plot3(x,y,z,xx,yy,z,xxx,yyy,z)

Command window
give value of x1 3
give value of x2 5
give value of x3 2.5
give value of y1 2
give value of y2 3
give value of y3 5
2. A triangle is given in 3D space. A surface is described as z=k. write
a Matlab program to show the intersection between the triangle and
surface.

clc
clear all
z1=input('give value of x1 ');z2=input('give value of x2');
z3=input('give value of x3 ');
y1=input('give value of y1 ');y2=input('give value of y2');
y3=input('give value of y3 ');
x=2*ones(101,1)';
z=z1:(z2-z1)/100:z2; %x3<x1<x2
y=y1+((y2-y1)/(z2-z1))*(z-z1); %y1<y2<y3
zz=z2:(z3-z2)/100:z3;
yy=y2+((y3-y2)/(z3-z2))*(zz-z2);
zzz=z3:(z1-z3)/100:z1;
yyy=y3+((y1-y3)/(z1-z3))*(zzz-z3);
plot3(x,y,z,x,yy,zz,x,yyy,zzz)
hold on
[xx1, yy1] = meshgrid(1:2/100:5); % Generate x and y data
z = 4*ones(size(xx1, 1)); % Generate z data
surf(xx1, yy1, z) % Plot the surface

Command window

give value of x1 3
give value of x2 5
give value of x3 2.5
give value of y1 2
give value of y2 3
give value of y3 5

S-ar putea să vă placă și