Quantcast
Channel: MATLAB Central Newsreader - tag:"centerline"
Viewing all articles
Browse latest Browse all 15

Re: Edges from centerline

$
0
0
On May 13, 1:43 pm, "Alfonso " <alfonso0...@hotmail.it> wrote:
> Hi again,
>
> thank you for the previous code that you sent me last time. It was very helpful.
> But I ask you one last thing: can you please send me the code of the function FlipLineIfNecessary ?
> Because sometimes I find points one one edge, sometimes on the other and I have to fix this little problem.
>
> Thank you in advance,
>
> Alfonso

---------------------------------------------------------------------------------------------
%=====================================================================
function [x3 x4 y3 y4] = FlipLineIfNecessary(x3, x4, y3, y4, lastLine)
% Determine distance from passed in endpoint 3 to the two endpoints
of the prior line.
distance3Squared = (x3 - lastLine.x3)^2 + (y3 - lastLine.y3)^2;
distance4Squared = (x3 - lastLine.x4)^2 + (y3 - lastLine.y4)^2;
% If distance3Squared is the smallest, we're ok.
% If not, we need to swap endpoints 3 and 4.
if distance3Squared < distance4Squared
% No need to do anything.
return;
else
% Need to swap.
[x3 x4] = Swap(x3, x4);
[y3 y4] = Swap(y3, y4);
end

return; % from FlipLineIfNecessary()

function [a b] = Swap(a, b)
temp = a;
a = b;
b = temp;
return; % from Swap()

Viewing all articles
Browse latest Browse all 15

Trending Articles