From bd0391e8c7cf17b2992f2f423910c238de7ce849 Mon Sep 17 00:00:00 2001
From: Ivar Stefansson <ist050@uib.no>
Date: Mon, 6 Feb 2017 16:55:10 +0100
Subject: [PATCH] Revert "Delete intersection.m"

This reverts commit c23056ed6f0e016f820345301c41eb654567fe8b
---
 scripts/intersection.m | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 scripts/intersection.m

diff --git a/scripts/intersection.m b/scripts/intersection.m
new file mode 100644
index 0000000..d083df9
--- /dev/null
+++ b/scripts/intersection.m
@@ -0,0 +1,27 @@
+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
+% vi = true iff i 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
+
-- 
GitLab