📄 sutherland_hodgeman_algorithum.m
字号:
%this programme is to solve the polygen cut line function
zonepoint=[10 10];
error=0.0001;
p=[5 15;15 10;5 -5;-2 2];
[n,dim]=size(p);
pp=[p;p(1,:)];
j=1;
bittable=[1 2 4 8];
for i=1:4
for k=1:n+1
bit2and=2^(i-1);
temp(k)=getzonecode(zonepoint,pp(k,:)); %get the all the point's code grouped by 1st line
code(k)=bitand(temp(k),bit2and);
end
for k=1:n
judge1=bitand(code(k),code(k+1));
if judge1~=0 %this line is totally unvisible,record no points
else
if code(k)==0&&code(k+1)==0 %this line is totally visible,keep the terminal point
output(j,:)=pp(k+1,:);
j=j+1;
elseif code(k)==0&&code(k+1)~=0 %this line has only p1 in area while p2 outside
sectpoint=intersectp(pp(k,:),pp(k+1,:),zonepoint,error,bit2and,0);
output(j,:)=sectpoint;
j=j+1;
else %this line has only p2 in area while p1 outside
sectpoint=intersectp(pp(k,:),pp(k+1,:),zonepoint,error,bit2and,1);
output(j,:)=sectpoint;
j=j+1;
output(j,:)=pp(k+1,:);
j=j+1;
end
end
end
end
plot(p(:,1),p(:,2),'b');hold on;
plot([0 0 10 10 0],[0 10 10 0 0],'r');hold on;
plot(output(:,1),output(:,2),'g');grid on;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -