Mercurial > hg > trimatlab
annotate mt_calibrate.m @ 8:e1534c7329e2
FIX: missing end
author | samer |
---|---|
date | Mon, 13 Feb 2012 11:21:15 +0000 |
parents | ffd7efa3e5c0 |
children |
rev | line source |
---|---|
samer@0 | 1 % mt_calibrate - Set spatial calibration of melody triangle system. |
samer@0 | 2 % |
samer@0 | 3 % mt_calibrate :: |
samer@0 | 4 % mt_system ~'system to calibrate', |
samer@0 | 5 % I:[[1,E]->[3]] ~'list triangle corners being updated', |
samer@0 | 6 % P:[[3,E]] ~'X-Y coordinates of the E corners being updated' |
samer@0 | 7 % -> mt_system ~'calibrated system'. |
samer@0 | 8 |
samer@0 | 9 function Sys=mt_calibrate(Sys,I,PI) |
samer@0 | 10 |
samer@0 | 11 if nargin>2, Sys.refpoints(:,I) = PI; end |
samer@0 | 12 P = Sys.refpoints; |
samer@2 | 13 fprintf('\nCalibrating for triangle vertices at:\n'); disp(P); |
samer@0 | 14 p0 = P(:,1); |
samer@3 | 15 [Sys.map, Sys.revmap] = info_map_fn(p0,P(:,2:3)-repmat(p0,1,2)); |
samer@0 | 16 end |
samer@0 | 17 |
samer@3 | 18 function [f,g]=info_map_fn(p0,M) |
samer@3 | 19 iM=inv(M); |
samer@3 | 20 f=@(p)clip_tri(iM*(p-p0)); |
samer@3 | 21 g=@(p)p0+M*p; |
samer@0 | 22 end |
samer@0 | 23 |
samer@0 | 24 function x=clip_tri(x) |
samer@0 | 25 if x(2)<0 |
samer@0 | 26 x(2)=0; |
samer@0 | 27 if x(1)<0, x(1)=0; |
samer@0 | 28 elseif x(1)>1, x(1)=1; |
samer@0 | 29 end |
samer@0 | 30 elseif x(1)<0 |
samer@0 | 31 x(1)=0; |
samer@0 | 32 if x(2)<0, x(2)=1; |
samer@0 | 33 elseif x(2)>1, x(2)=1; |
samer@0 | 34 end |
samer@0 | 35 else |
samer@0 | 36 d = [1,1]*x - 1; |
samer@0 | 37 if d>0 |
samer@0 | 38 x = x - d/2; |
samer@0 | 39 if x(1)<0, x=[0;1]; |
samer@0 | 40 elseif x(2)<0, x=[1;0]; |
samer@0 | 41 end |
samer@0 | 42 end |
samer@0 | 43 end |
samer@0 | 44 end |
samer@0 | 45 |