exp_clipline.m

来自「具有图形操作界面的支持向量机多类分类实验系统.全部用Matlab实现,可以实现多」· M 代码 · 共 37 行

M
37
字号
% CLIPLINE clips line into given window.
%
% Synopsis:
%  [x1,y1,x2,y2,inside] = clipline(W,b,window)
%
% Description:
%  This function returns 2d points (x1,y1) and (x2,y2) 
%  of a line segment given by line
%    W'*x + b = 0
%
%  clipped to the given window.
%
% Input:
%  W [2x1] Normal of line.
%  b [1x1] Line threshold.
%  window [4x1] Contains [left right top bottom].
%
% Output:
%  x1 [1x1], y1 [1x1] The first point of line segment.
%  x2 [1x1], y2 [1x1] The second point of line segment.
%  inside [1x1] 1 if line W'*x+b=0 intersects the window. 
%  
% Example:
%  figure; hold on;
%  axis([-1 1 -1 1]);
%  window = 0.5*axis;
%  [x1,y1,x2,y2]=clipline([-1;1],0,window);
%  plot([x1 x2],[y1 y2]);

figure; hold on;
  axis([-1 1 -1 1]);
  window = 0.5*axis;
  [x1,y1,x2,y2]=clipline([-1;1],0,window);
  plot([x1 x2],[y1 y2]);
  
  %  [x1,y1,x2,y2]=clipline([-1;1],-0.5,window);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?