Skip to content
Snippets Groups Projects
Commit 89b2e349 authored by Ivar Stefansson's avatar Ivar Stefansson
Browse files

Upload the intersection file

parent 419b5c11
No related branches found
No related tags found
No related merge requests found
function [ intersection ] = intersection( k, vk, l, vl)
%UNTITLED2 Calculates intersections of two lines specified by two sets of
%points
% lines in format [x1, y1; x2, y2]
% [11, 12; 21, 22]
% line k = ax + b, l = cx + d
% vk = true iff k vertical
if vk
c = (l(2,2) - l(1,2)) / (l(2,1)-l(1,1));
d = l(1,2) - c*l(1,1);
intersection = [k(1), c * k(1) + d];
elseif vl
a = (k(2,2) - k(1,2)) / (k(2,1)-k(1,1));
b = k(1,2) - a*k(1,1);
intersection = [l(1), a * l(1) + b];
else
a = (k(2,2) - k(1,2)) / (k(2,1)-k(1,1));
c = (l(2,2) - l(1,2)) / (l(2,1)-l(1,1));
b = k(1,2) - a*k(1,1);
d = l(1,2) - c*l(1,1);
x = (d-b)/(a-c);
%y = a * x + b;
intersection = [x, a * x + b];
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment