COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

24
COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin

description

UTA Computational Geometry – Position of Point Problem: To determine whether a given point lies outside or inside a given polygon. Answer: Yes if the point lies inside the polygon, No otherwise Solution: Draw a line along the X –axis from the point in one direction i.e. the line can have a increasing as well as decreasing X – axis. If the line thus drawn intersects ONLY once with any edge of the polygon then the point lies inside the polygon else it lies outside the polygon

Transcript of COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

Page 1: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION

Mohammed Zeeshan FarooquiMinhaj Uddin

Page 2: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTA COMPUTATIONAL GEOMETRY

Data is defined as points, lines, surfaces, polygons etc.

Convex Non-convex Convex Polygon has every in degree less than 180 Non Convex Polygon may have one or more in

degrees greater than 180

Page 3: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTA Computational Geometry – Position of Point Problem: To determine whether a given point

lies outside or inside a given polygon. Answer: Yes if the point lies inside the polygon,

No otherwise Solution: Draw a line along the X –axis from

the point in one direction i.e. the line can have a increasing as well as decreasing X – axis.

If the line thus drawn intersects ONLY once with any edge of the polygon then the point lies inside the polygon else it lies outside the polygon

Page 4: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTA Computational Geometry – Position of Point (..contd.) Example:

_ _ _ _ _ _ _ _ _ __ _ _.P

The above point intersects only once with an edge of the polygon hence it lies insidepolygon

Page 5: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTA Computational Geometry – Position of Point (…contd) Example:

_ _.P___ __ _ _ __ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .P_ _ _ _

(a) (b)

(a) The line extending from point P intersects the polygon edges more than once (twice in thisExample), hence P lies outside the polygon

(b) In case of Non Convex Polygon, a given point lies inside the polygon if the line segment Extending from it intersects the polygon edges an ODD number of times else it lies outside

Page 6: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTA Convex Hulls

Informally,Convex hull is defined as an Convex Polygon whose vertices come from the original points and its perimeter encapsulates all the points.

Definition:The Convex Hull of a set Q of points is the smallest convex polygon P, for which each point in Q is either on the boundary of P or in its interior.If there is a plane Q , consisting of nails sticking out from a board. Then the Convex Hull of Q can be thought of the shape formed by a tight rubber band that surrounds all the nails

Page 7: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTA Convex Hulls

Example of an Convex Hull

Po

P1

P3

P10

P12

P11

P9

P6

P7

P8

P5

P4

P2

Page 8: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTA Convex Hull – Jarvis March Convex Hull Jarvis March Graham ScanJarvis March: Computation of Convex Hull For Every Point, join with all the original points

and for the resulting line segments compute the angle with respect to origin, the smallest angle thus obtained gives the next point.

Running time is O(n2) Actual running time is O(n*h), where h is the

number of points on the convex hull.

Page 9: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTA Convex Hull – Jarvis March (…contd.)

Example of Jarvis March

P1

P9 P7

P2

P6

P3

P5

P4

P8

P0

Jarvis March’s algorithm starts from P0 ie the anchor point.

Then it wraps the next outer point and makes this as the new anchor point and repeats the procedure for the rest of the points…….

Till every point is wrapped inside.

Page 10: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTA Convex Hull – Graham Scan

Graham Scan – Computation of Convex Hull Sort angles in counter clock wise direction Create Polygon by connecting points in sorted

order Thereby a Non Convex Polygon results( Could

also be convex) Now wrap the above Non – Convex polygon by

a convex polygon.

Page 11: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTA Convex Hull – Graham Scan (…contd.) Algorithm (Package Wrapping or Gift Wrapping) Start from bottom i.e. left most point going counter clockwise Join with the next point in the counter clock wise direction so

long as the resulting line segment makes left turns (>180) it will be included.

If the line segment forms an angle <180, then discard current path, walk back to the previous points and join successfully with new points and measure the resulting angle.

Running time is O(nlogn), as walking around takes 2n, since each is traversed only twice in the worst case and once the edge is dropped it is never again considered and the sorting of angles takes O(logn), hence the resulting running time is O(nlongn)

Page 12: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTAConvex Hull – Graham Scan (…contd.)

As shown, Grahams starts from a point (p0) and calculates all the angles it makes to all the points and sorts the angles in an order

Page 13: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTAConvex Hull – Graham Scan (…contd.)

It selects the point with the least angle and starts traversing (P0-P1).

Then P1 to P2 & from P2 to P3 it realizes that it takes a right turn, so it backtracks and selects P1 – P3 directly, it being shorter

Page 14: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTAConvex Hull – Graham Scan (…contd.)

The algorithm continues, based on the above mentioned conditions till it reaches back to the initial point. Hence forming the Convex Hull as shown:

Page 15: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTAConvex Hull – Graham Scan (…contd.)

Page 16: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTAConvex Hull – Graham Scan (…contd.)

Page 17: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTAConvex Hull – Graham Scan (…contd.)

Once the initial point is reached the algorithm self terminates, and the Convex Hull is formed.

Page 18: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTAMultiplication of Large Numbers Matrix Multiplication: Traditional method Takes O(n2) time Traditional Method Given two matrices A and B compute their

product. A

B

Page 19: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTAMultiplication of Large Numbers (…contd.) Divide the two arrays into two parts each, A

into Al and Ar, and B into Bl and Br. Al Ar

Bl Br

Page 20: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTAMultiplication of Large Numbers (…contd.) A = Al10n/2 + Ar B = Bl10n/2 + Br

A.B = (Al10n/2 + Ar)( Bl10n/2 + Br) = AlBl10n + AlBr10n/2 + ArBl10n/2 + ArBr

Time Complexity : T(n)

T(n) = 4T(n/2) + O(n) = O(n2)

Page 21: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTAMultiplication of Large Numbers (…contd.) The goal is to reduce the time complexity from

O(n2). The intuition is that since we use recursion in

our multiplication of the equation, if we can reduce the number of calls to the recursive function Multiply(x,y) the overall complexity of the problem can be significantly reduced.

Page 22: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTAMultiplication of Large Numbers (…contd.) Consider the equation from the previous slide:

AlBl10n + AlBr10n/2 + ArBl10n/2 + ArBr This equation can be re-arranged as under: AlBl10n/2 + (AlBr + ArBl)10n/2 + ArBr Now, we call the multiplication function

Mult(X,Y) recursively as follows: X = Mult(Al,Bl) Y = Mult(Ar,Br) P = Al + Ar Q = Bl + Br

Page 23: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTAMultiplication of Large Numbers (…contd.) Z = Mult(p,q) U = Z – X – Y Return: X10n + U10n/2 + Y, Where

X10n = AlBl10n/2

U10n/2 = (AlBr + ArBl)10n/2 Y = ArBr Thus, in this approach we have replaced four

calls to the Mult(X,Y) function in the traditional method to three calls.

Page 24: COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

CSE@UTAMultiplication of Large Numbers (…contd.)

Thus the resulting time complexity is:T(n) = 3T(n/2) + O(n) = 3[3T(n/22) + n/2] + n = 32T(n/22) + 3n/2 + n

= nlog23 = n1.7