1## Copyright (C) 2021 David Legland 2## All rights reserved. 3## 4## Redistribution and use in source and binary forms, with or without 5## modification, are permitted provided that the following conditions are met: 6## 7## 1 Redistributions of source code must retain the above copyright notice, 8## this list of conditions and the following disclaimer. 9## 2 Redistributions in binary form must reproduce the above copyright 10## notice, this list of conditions and the following disclaimer in the 11## documentation and/or other materials provided with the distribution. 12## 13## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' 14## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 17## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 20## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 21## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23## 24## The views and conclusions contained in the software and documentation are 25## those of the authors and should not be interpreted as representing official 26## policies, either expressed or implied, of the copyright holders. 27 28function T = createHomothecy(point, ratio) 29%CREATEHOMOTHECY Create the the 3x3 matrix of an homothetic transform. 30% 31% TRANS = createHomothecy(POINT, K); 32% POINT is the center of the homothecy, K is its factor. 33% TRANS is a 3-by-3 matrix representing the homothetic transform in 34% homogeneous coordinates. 35% 36% Example: 37% 38% p = [0 0; 1 0; 0 1]; 39% s = [-0.5 0.4]; 40% T = createHomothecy (s, 1.5); 41% pT = transformPoint (p, T); 42% drawPolygon (p,'-b') 43% hold on; 44% drawPolygon (pT, '-r'); 45% 46% drawEdge (p(:,1), p(:,2), pT(:,1), pT(:,2), ... 47% 'color', 'k','linestyle','--') 48% hold off 49% axis tight equal 50% 51 52% --------- 53% Author: David Legland 54% e-mail: david.legland@inra.fr 55% INRA - TPV URPOI - BIA IMASTE 56% created the 20/01/2005. 57 58 59% HISTORY 60% 22/04/2009: rename as createHomothecy 61% 05/04/2017: improved code by JuanPi Carbajal <ajuanpi+dev@gmail.com> 62 63point = point(:); 64if length (point) > 2 65 error('Only one point accepted.'); 66end 67if length (ratio) > 1 68 error('Only one ratio accepted.'); 69end 70 71T = diag ([ratio ratio 1]); 72T(1:2,3) = point .* (1 - ratio); 73