function [w] = morphweight(x,y,P,Q,a,b,p) % w = morphweight(x,y,P,Q,a,b,p). compute morphing weights of points % given column vectors x,y of the same length, % a 2D line segment with endpoints P, Q, % and parameters a,b,p, compute the column vector w of weights % w(i) for each point (x(i),y(i)) according to the Beier-Neeley % weight function ((length^p) / (a + dist))^b, where length is % the length of the line segment PQ, and dist is the distance of % the point to the line segment % use the algorithm presented in lecture: x = x - P(1) ; y = y - P(2); Q = Q - P; lensquared = Q' * Q; len = sqrt(lensquared); dott = Q(1)*x + Q(2)*y; behind = dott < 0; infront = dott > lensquared; between = ~behind & ~infront; dist(behind) = sqrt(x(behind).^2 + y(behind).^2); dist(infront) = sqrt((x(infront)-Q(1)).^2 + (y(infront)-Q(2)).^2); dist(between) = abs(x(between) * Q(2) - y(between) * Q(1)) / len; w = (len^p ./ (a+dist)).^b;