diff --git a/ea/ub9/QuickHull.m b/ea/ub9/QuickHull.m new file mode 100644 index 0000000..cfb0813 --- /dev/null +++ b/ea/ub9/QuickHull.m @@ -0,0 +1,7 @@ +function [ output_args ] = QuickHull( input_args ) +%UNTITLED2 Summary of this function goes here +% Detailed explanation goes here + + +end + diff --git a/mr/ub10/A3c/step1.fig b/mr/ub10/A3c/step1.fig new file mode 100644 index 0000000..8cd2b16 --- /dev/null +++ b/mr/ub10/A3c/step1.fig Binary files differ diff --git a/mr/ub10/A3c/step2.fig b/mr/ub10/A3c/step2.fig new file mode 100644 index 0000000..da19758 --- /dev/null +++ b/mr/ub10/A3c/step2.fig Binary files differ diff --git a/mr/ub10/A3c/step3.fig b/mr/ub10/A3c/step3.fig new file mode 100644 index 0000000..4a32f82 --- /dev/null +++ b/mr/ub10/A3c/step3.fig Binary files differ diff --git a/mr/ub10/A3c/step4.fig b/mr/ub10/A3c/step4.fig new file mode 100644 index 0000000..42f4163 --- /dev/null +++ b/mr/ub10/A3c/step4.fig Binary files differ diff --git a/mr/ub10/A3c/step5.fig b/mr/ub10/A3c/step5.fig new file mode 100644 index 0000000..fd65259 --- /dev/null +++ b/mr/ub10/A3c/step5.fig Binary files differ diff --git a/mr/ub10/A3c/step6.fig b/mr/ub10/A3c/step6.fig new file mode 100644 index 0000000..d033294 --- /dev/null +++ b/mr/ub10/A3c/step6.fig Binary files differ diff --git a/mr/ub10/EX1.m b/mr/ub10/EX1.m new file mode 100644 index 0000000..a9ca7be --- /dev/null +++ b/mr/ub10/EX1.m @@ -0,0 +1,66 @@ +p=[24,10;27,1;35,1;38,4;34,9;44,8;50,19;44,25;24,25;30,18;24,10;27,1] +x=p(:,1); +y=p(:,2); + +[~,xmin]=min(x); +[~,xmax]=max(x); +xmin +xmax +%expanded red +%new added green +%poligon red + +figure(1) +scatter(x,y); +line(p([1,7],1),p([1,7],2),'Color',[1 0 0]) +line(p([1,3],1),p([1,3],2),'Color',[0 1 0]) +line(p([7,3],1),p([7,3],2),'Color',[0 1 0]) + +figure(2) +scatter(x,y); +line(p([1,7],1),p([1,7],2),'Color',[0 0 1]) +line(p([7,3],1),p([7,3],2),'Color',[0 0 1]) +line(p([1,3],1),p([1,3],2),'Color',[1 0 0]) +line(p([1,2],1),p([1,2],2),'Color',[0 1 0]) +line(p([3,2],1),p([3,2],2),'Color',[0 1 0]) + +figure(3) +scatter(x,y); +line(p([1,7],1),p([1,7],2),'Color',[0 0 1]) +line(p([7,3],1),p([7,3],2),'Color',[1 0 0]) +line(p([1,2],1),p([1,2],2),'Color',[0 0 1]) +line(p([3,2],1),p([3,2],2),'Color',[0 0 1]) +line(p([7,6],1),p([7,6],2),'Color',[0 1 0]) +line(p([3,6],1),p([3,6],2),'Color',[0 1 0]) + +figure(4) +scatter(x,y); +line(p([1,2],1),p([1,2],2),'Color',[0 0 1]) +line(p([3,2],1),p([3,2],2),'Color',[0 0 1]) +line(p([7,6],1),p([7,6],2),'Color',[0 0 1]) +line(p([3,6],1),p([3,6],2),'Color',[0 0 1]) +line(p([9,7],1),p([9,7],2),'Color',[0 1 0]) +line(p([9,1],1),p([9,1],2),'Color',[0 1 0]) + +figure(5) +scatter(x,y); +line(p([1,2],1),p([1,2],2),'Color',[0 0 1]) +line(p([3,2],1),p([3,2],2),'Color',[0 0 1]) +line(p([7,6],1),p([7,6],2),'Color',[0 0 1]) +line(p([3,6],1),p([3,6],2),'Color',[0 0 1]) +line(p([9,7],1),p([9,7],2),'Color',[1 0 0]) +line(p([9,1],1),p([9,1],2),'Color',[0 0 1]) +line(p([9,8],1),p([9,8],2),'Color',[0 1 0]) +line(p([8,7],1),p([8,7],2),'Color',[0 1 0]) + +figure(6) +scatter(x,y); +line(p([1,2],1),p([1,2],2),'Color',[0 0 1]) +line(p([3,2],1),p([3,2],2),'Color',[0 0 1]) +line(p([7,6],1),p([7,6],2),'Color',[0 0 1]) +line(p([3,6],1),p([3,6],2),'Color',[0 0 1]) +line(p([9,1],1),p([9,1],2),'Color',[0 0 1]) +line(p([9,8],1),p([9,8],2),'Color',[0 0 1]) +line(p([8,7],1),p([8,7],2),'Color',[0 0 1]) + + diff --git a/mr/ub10/Untitled.ipynb b/mr/ub10/Untitled.ipynb new file mode 100644 index 0000000..17a07f5 --- /dev/null +++ b/mr/ub10/Untitled.ipynb @@ -0,0 +1,117 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 41, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "import matplotlib.pyplot as plt" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "\n", + "def qhull(pts):\n", + " maxx = max(pts, key=lambda pt: pt[0])\n", + " minx = min(pts, key=lambda pt: pt[0])\n", + " hull_up = handle_line(pts, (minx, maxx))\n", + " hull_down = handle_line(pts, (maxx, minx))\n", + " return hull_up + hull_down" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "def handle_line(pts, line):\n", + " left = [p for p in pts if leftOf(p, line)]\n", + " if len(left) == 0: return []\n", + " pivot = max(left, key=lambda pt: distanceToLine(pt, line))\n", + " \n", + " l = handle_line(left, (line[0], pivot))\n", + " r = handle_line(left, (pivot, line[1]))\n", + " hull= [line[0]] + l + [pivot] + r + [line[1]]\n", + " return hull\n", + "\n", + "def distanceToLine(pt, (f, t)):\n", + " return np.linalg.norm(cross(t - f, f - pt)) / np.linalg.norm(t - f)\n", + "def leftOf(pt, (f, t)):\n", + " return dot(ortho(t - f), (pt - f)) < -0.00000001\n", + "def ortho(v):\n", + " return np.array([-v[1], v[0]])" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "pts = np.array([[24,10],[27,1],[35,1],[38,4],[34,9],[44,8],[50,19],[44,25],[24,25],[30,18],[24,10],[27,1]])\n", + "pts[:,1]\n", + "plt.figure()\n", + "plt.scatter(pts[:,0],pts[:,1])\n", + "plt.show()\n", + "plt.figure()\n", + "plt.scatter([1,2,3],[1,3,4])\n", + "plt.show()\n", + "#print(qhull(pts))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/mr/ub10/assignment10.pdf b/mr/ub10/assignment10.pdf new file mode 100644 index 0000000..e76391a --- /dev/null +++ b/mr/ub10/assignment10.pdf Binary files differ