Add some tests on different variations of Hough algorithm.
[master-thesis.git] / src / Tests_hough / draw_ellipses.m
diff --git a/src/Tests_hough/draw_ellipses.m b/src/Tests_hough/draw_ellipses.m
new file mode 100644 (file)
index 0000000..d793f4d
--- /dev/null
@@ -0,0 +1,44 @@
+% center : [x y]
+function draw_ellipses(axe, ellipses, plot_3d, plot_center)
+    if ~exist('plot_3d', 'var')
+        plot_3d = false;
+    end
+    
+    if ~exist('plot_center', 'var')
+        plot_center = false;
+    end
+
+    hold on;
+    
+    if plot_3d
+        z_space = [0 1];
+    else
+        z_space = [0];
+    end
+    
+    for i = 1:length(ellipses)
+        e = ellipses{i};
+        transform_mat = [cos(e.alpha) -sin(e.alpha); sin(e.alpha) cos(e.alpha)]; 
+
+        p_previous = [];
+        for phi = linspace(0, 2 * pi, 36);
+           for z = z_space
+                p = [e.x0; e.y0] + transform_mat * [e.r1 * cos(phi); e.r2 * sin(phi)]; % p : [x y]
+                if ~isempty(p_previous)
+                    line = plot3(axe, [p(1) p_previous(1)], [p(2) p_previous(2)], [z z], 'LineWidth', 1, 'Color', 'yellow');
+                    line.Color(4) = 0.5;
+                end
+                if z == 1
+                   line = plot3(axe, [p(1) p(1)], [p(2) p(2)], [0 1], 'LineWidth', 0.5, 'Color', 'yellow'); 
+                   line.Color(4) = 0.5;
+                end
+           end
+           p_previous = p;
+        end
+        
+        if plot_center
+            plot(e.x0, e.y0, 'r.', 'MarkerSize', 20);
+        end
+    end
+end
+