Chapter 8 A Module of Regions. The Region Data Type  A region represents an area on the two-dimensional Cartesian plane.  It is represented by a tree-like.

Slides:



Advertisements
Similar presentations
1.5 Set Operations. Chapter 1, section 5 Set Operations union intersection (relative) complement {difference}
Advertisements

Introduction to Set Theory
3.8 Unions and Intersections of Sets. Set operations Let U = {x|x is an English-language film} Set A below contains the five best films according to the.
Cse536 Functional Programming 1 6/10/2015 Lecture #8, Oct. 20, 2004 Todays Topics –Sets and characteristic functions –Regions –Is a point in a Region –Currying.
Cse536 Functional Programming 1 6/12/2015 Lecture #7, Oct. 18, 2004 Today’s Topics – Trees – Kinds of trees - branching factor –functions over trees –patterns.
Chapter 2 A Module of Shapes: Part I. Defining New Datatypes  The ability to define new data types in a programming language is important.  Kinds of.
Advanced Programming Handout 9 Qualified Types (SOE Chapter 12)
Introduction to Gröbner Bases for Geometric Modeling Geometric & Solid Modeling 1989 Christoph M. Hoffmann.
Advanced Programming Handout 5 Recursive Data Types (SOE Chapter 7)
Chapter 12 Qualified Types. Motivation  What should the principal type of (+) be? Int -> Int -> Int-- too specific a -> a -> a-- too general  It seems.
Chapter 2 The Basic Concepts of Set Theory
Survey of Mathematical Ideas Math 100 Chapter 2
Venn Diagrams/Set Theory   Venn Diagram- A picture that illustrates the relationships between two or more sets { } are often used to denote members of.
Set, Combinatorics, Probability & Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Set,
CS 103 Discrete Structures Lecture 10 Basic Structures: Sets (1)
MATH 224 – Discrete Mathematics
Chapter 2 Section 3 - Slide 1 Copyright © 2009 Pearson Education, Inc. AND.
Section 2.2 Subsets and Set Operations Math in Our World.
Chapter SETS DEFINITION OF SET METHODS FOR SPECIFYING SET SUBSETS VENN DIAGRAM SET IDENTITIES SET OPERATIONS.
Mathematical Preliminaries
Before we do any of these, let's make sure we understand the sets. A, B, and C are subsets of U. May 2001: Paper 2 #1 The sets A, B, and C are subsets.
Chapter 2 With Question/Answer Animations. Section 2.1.
Discrete Mathematics Lecture # 10. Set Theory  A well defined collection of {distinct} objects is called a set.  The objects are called the elements.
Morphological Image Processing การทำงานกับรูปภาพด้วยวิธีมอร์โฟโลจิคัล
Chapter 2 Section 3 - Slide 1 Copyright © 2009 Pearson Education, Inc. AND.
Basic Definitions of Set Theory Lecture 23 Section 5.1 Wed, Mar 8, 2006.
Chapter 2 Section 2 - Slide 1 Copyright © 2009 Pearson Education, Inc. AND.
Based on slides by Patrice Belleville and Steve Wolfman CPSC 121: Models of Computation Unit 11: Sets.
Centers of Mass Review & Integration by Parts Chapter 7.1 March 20, 2007.
Basic Definitions of Set Theory Lecture 23 Section 5.1 Mon, Feb 21, 2005.
Set Operations Section 2.2.
Notions & Notations (2) - 1ICOM 4075 (Spring 2010) UPRM Department of Electrical and Computer Engineering University of Puerto Rico at Mayagüez Spring.
BYST Morp-1 DIP - WS2002: Morphology Digital Image Processing Morphological Image Processing Bundit Thipakorn, Ph.D. Computer Engineering Department.
Discrete Mathematics Lecture # 10 Venn Diagram. Union  Let A and B be subsets of a universal set U. The union of sets A and B is the set of all elements.
Section 1.2 – 1.3 Outline Intersection  Disjoint Sets (A  B=  ) AND Union  OR Universe The set of items that are possible for membership Venn Diagrams.
Morphological Image Processing (Chapter 9) CSC 446 Lecturer: Nada ALZaben.
The Basic Concepts of Set Theory. Chapter 1 Set Operations and Cartesian Products.
Unions and intersection of Sets Section 3-8 Goals Goal To find the union and intersections of sets. Rubric Level 1 – Know the goals. Level 2 – Fully.
Union and Intersection of Sets. Definition - intersection The intersection of two sets A and B is the set containing those elements which are and elements.
Dilations A dilation is a transformation that produces an image that is the same shape as the original, but is a different size. A dilation stretches or.
Section 6.1 Set and Set Operations. Set: A set is a collection of objects/elements. Ex. A = {w, a, r, d} Sets are often named with capital letters. Order.
Sets, Permutations, and Combinations. Lecture 4-1: Sets Sets: Powerful tool in computer science to solve real world problems. A set is a collection of.
Advance Fluid Mechanics
Dr. Ameria Eldosoky Discrete mathematics
The set of whole numbers less than 7 is {1, 2, 3, 4, 5, 6}
Chapter 2 Sets and Functions.
CSNB 143 Discrete Mathematical Structures
Set, Combinatorics, Probability & Number Theory
Chapter 2 The Basic Concepts of Set Theory
Chapter 1 Logic and Proofs Homework 2 Given the statement “A valid password is necessary for you to log on to the campus server.” Express the statement.
MATH 224 – Discrete Mathematics
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 2 Sets Slides are adopted from “Discrete.
CS100: Discrete structures
Set Theory A B C.
Centers of Mass Review & Integration by Parts
Set Operations Section 2.2.
        { } Sets and Venn Diagrams Prime Numbers Even Numbers
The Basic Concepts of Set Theory
Review of Sets and Set Operations
Chapter 2 The Basic Concepts of Set Theory
Indicator 16 System of Equations.
Chapter 1: Linear Functions, Equations, and Inequalities
Lecture Sets 2.2 Set Operations.
Day 54 – Congruence in opposite dilation
AND.
Set – collection of objects

Presentation transcript:

Chapter 8 A Module of Regions

The Region Data Type  A region represents an area on the two-dimensional Cartesian plane.  It is represented by a tree-like data structure. data Region = Shape Shape -- primitive shape | Translate Vector Region -- translated region | Scale Vector Region -- scaled region | Complement Region -- inverse of region | Region `Union` Region -- union of regions | Region `Intersect` Region -- intersection of regions | Empty deriving Show type Vector = (Float, Float)

Questions about Regions  Why is Region tree-like?  What is the strategy for writing functions over regions?  Is there a fold-function for regions? How many parameters does it have? What is its type?  Can one define infinite regions?  What does a region mean?

Sets and Characteristic Functions  How can we represent an infinite set in Haskell? E.g.: the set of all even numbers the set of all prime numbers  We could use an infinite list, but then searching it might take a very long time! (Membership becomes semi-decidable.)  The characteristic function for a set containing elements of type z is a function of type z -> Bool that indicates whether or not a given element is in the set. Since that information completely characterizes a set, we can use it to represent a set: type Set a = a -> Bool  For example: even :: Set Integer -- Integer -> Bool even x = (x `mod` 2) == 0

Combining Sets  If sets are represented by characteristic functions, then how do we represent the: union of two sets? intersection of two sets? complement of a set?  In-class exercise – define the following Haskell functions: union s1 s2 = intersect s1 s2 = complement s =  We will use these later to define similar operations on regions.

Why Regions? Regions (as defined in the text) are interesting because: They allow us to build complex “shapes” from simpler ones. They illustrate the use of tree-like data structures. They “solve” the problem of having rectangles and ellipses centered about the origin. Their meaning can be given as characteristic functions, since a region denotes the set of points contained within it.

Characteristic Functions for Regions  We define the meaning of regions by a function: containsR :: Region -> Coordinate -> Bool type Coordinate = (Float, Float)  Note that containsR r :: Coordinate -> Bool, which is a characteristic function. So containsR “gives meaning to” regions.  Another way to see this: containsR :: Region -> Set Coordinate  We can define containsR recursively, using pattern matching over the structure of a Region.  Since the base cases of the recursion are primitive shapes, we also need a function that gives meaning to primitive shapes; we will call this function containsS.

Rectangle Rectangle s1 s2 `containsS` (x,y) = let t1 = s1/2 t2 = s2/2 in -t1<=x && x<=t1 && -t2<=y && y<=t2 s1 s2 t1 t2

Ellipse Ellipse r1 r2 `containsS` (x,y) = (x/r1)^2 + (y/r2)^2 <= 1 r1 r2

The Left Side of a Line a = (ax,ay) b = (bx,by) For a ray directed from point a to point b, a point p is to the left of the ray (facing from a to b ) when: isLeftOf :: Coordinate -> Ray -> Bool (px,py) `isLeftOf` ((ax,ay),(bx,by)) = let (s,t) = (px-ax, py-ay) (u,v) = (px-bx, py-by) in s*v >= t*u type Ray = (Coordinate, Coordinate) p = (px,py)

Polygon A point p is contained within a (convex) polygon if it is to the left of every side, when they are followed in counter- clockwise order. p Polygon pts `containsS` p = let shiftpts = tail pts ++ [head pts] leftOfList = map isLeftOfp (zip pts shiftpts) isLeftOfp p' = isLeftOf p p' in and leftOfList

Right Triangle RtTriangle s1 s2 `containsS` p = Polygon [(0,0),(s1,0),(0,s2)] `containsS` p s1 (0,0) (0,s2) (s1,0) s2

Putting it all Together containsS :: Shape -> Vertex -> Bool Rectangle s1 s2 `containsS` (x,y) = let t1 = s1/2; t2 = s2/2 in -t1<=x && x<=t1 && -t2<=y && y<=t2 Ellipse r1 r2 `containsS` (x,y) = (x/r1)^2 + (y/r2)^2 <= 1 Polygon pts `containsS` p = let shiftpts = tail pts ++ [head pts] leftOfList = map isLeftOfp (zip pts shiftpts) isLeftOfp p' = isLeftOf p p' in and leftOfList RtTriangle s1 s2 `containsS` p = Polygon [(0,0),(s1,0),(0,s2)] `containsS` p

Defining containsR Using Recursion containsR :: Region -> Vertex -> Bool Shape s `containsR` p = s `containsS` p Translate (u,v) r `containsR` (x,y) = r `containsR` (x-u,y-v) Scale (u,v) r `containsR` (x,y) = r `containsR` (x/u,y/v) Complement r `containsR` p = not (r `containsR` p) r1 `Union` r2 `containsR` p = r1 `containsR` p || r2 `containsR` p r1 `Intersect` r2 `containsR` p = r1 `containsR` p && r2 `containsR` p Empty `containsR` p = False

An Algebra of Regions  Note that, for any r1, r2, and r3 : (r1 `Union` (r2 `Union` r3)) `containsR` p if and only if: (r1 `Union` r2) `Union` r3)) `containsR` p which we can abbreviate as: (r1 `Union` (r2 `Union` r3)) ((r1 `Union` r2) `Union` r3)  In other words, Union is associative.  We can prove this fact via calculation.

Proof of Associativity (r1 `Union` (r2 `Union` r3)) `containsR` p  (r1 `containsR` p) || ((r2 `Union` r3) `containsR` p)  (r1 `containsR` p) || ((r2 `containsR` p) || (r3 `containsR` p))  ((r1 `containsR` p) || (r2 `containsR` p)) || (r3 `containsR` p)  ((r1 `Union` r2) `containsR` p) || (r3 `containsR` p)  ((r1 `Union` r2) `Union` r3) `containsR` p (Note that the proof depends on the associativity of (||), which can also be proved by calculation, but we take it as given.)

More Axioms  There are many useful axioms for regions: 1)Union and Intersect are associative. 2)Union and Intersect are commutative. 3)Union and Intersect are distributive. 4)Empty and univ = Complement Empty are zeros for Union and Intersect, respectively. 5)r `Union` Complement r univ and r `Intersect` Complement r Empty  This set of axioms captures what is called a boolean algebra.