www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@contable2/bringInside.m
function X = bringInside(c, X) %BRINGINSIDE Move a set of points so they are all inside the constraint. % % Y = BRINGINSIDE(CON, X) is the data set X but with any points outside the % constraint CON projected into the constraint. % If X(i,:) is inside the constraint, then Y(i,:) = X(i,:). % If X(i,:) is outside the constriant, then Y(:,i) will be the closest point to % X(i,:) that is inside (on the boundary of) the constraint. % % See also CONTABLE2, CONTABLE2/ISINSIDE, CONTABLE2/CONSTRAINTDISTANCE, % CONBASE/BRINGINSIDE. % Copyright 2000-2005 The MathWorks, Inc. % For a CONTABLE2 the points need to be lowered (or raised) in the z-axis % direction by their un-scaled distance activeIndices = getActiveIndices( c ); [in, d] = xreginterp2d( c.breakrows, c.breakcols, c.table, ... activeIndices([2, 1, 3]), c.le, X ); zIndex = activeIndices(3); if c.le, % "Less than" constraint ==> lower points X(~in,zIndex) = X(~in,zIndex) - d(~in); else % "Greater than" constraint ==> raise points X(~in,zIndex) = X(~in,zIndex) + d(~in); end %------------------------------------------------------------------------------| % EOF %------------------------------------------------------------------------------|