Geometry.

Slides:



Advertisements
Similar presentations
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
Advertisements

Vector Calculus Mengxia Zhu Fall Objective Review vector arithmetic Distinguish points and vectors Relate geometric concepts to their algebraic.
Convex Hull obstacle start end Convex Hull Convex Hull
CS16: Introduction to Data Structures & Algorithms
Motion Planning CS 6160, Spring 2010 By Gene Peterson 5/4/2010.
Convex Hulls in Two Dimensions Definitions Basic algorithms Gift Wrapping (algorithm of Jarvis ) Graham scan Divide and conquer Convex Hull for line intersections.
Classes of Polygons Planar polygons Non-planar polygons Simple
Convex Sets & Concave Sets A planar region R is called convex if and only if for any pair of points p, q in R, the line segment pq lies completely in R.
Lecture 3: Reduce to known problem Convex Hull (section 33.3 of CLRS). Suppose we have a bunch of points in the plane, given by their x and y coordinates.
Algorithms and Data Structures Lecture 13. Agenda: Plane Geometry: algorithms on polygons - Verification if point belongs to a polygon - Convex hull.
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
5/17/2015 1:32 AMConvex Hull1 obstacle start end.

Computational Geometry & Collision detection
GEOMETRY Chapter 3: Angle Pairs, Lines and Planes
Convex Hull Computation ● Applications of Convex Hull Computation ● Definitions ● Basic Math Functions ● Algorithms Algorithm Speed Discovered By Brute.
Computational Geometry
Computational Geometry Convex Hulls Robust Geometric Primitives Degeneracy and Stability Nick Pilkington.
CS 450: Computer Graphics REVIEW: OVERVIEW OF POLYGONS
Convex Hull. What is the Convex Hull? Imagine a set of points on a board with a nail hammered into each point. Now stretch a rubber band over all the.
Mathematics for Graphics. 1 Objectives Introduce the elements of geometry  Scalars  Vectors  Points Develop mathematical operations among them in a.
Warm Up Find AB. 1. A(0, 15), B(17, 0) 2. A(–4, 2), B(4, –2)
VECTORS. A vector is a quantity that has both magnitude and direction. It is represented by an arrow. The length of the vector represents the magnitude.
At the right is a polygon known as a trapezoid. The two parallel sides (horizontal in this case) of the trapezoid are called bases. b1b1 b2b2 b2b2 b1b1.
© 2010 Pearson Prentice Hall. All rights reserved. CHAPTER 10 Geometry.
1 Graphics CSCI 343, Fall 2015 Lecture 9 Geometric Objects.
A planar region R is called convex if and only if for any pair of points p, q in R, the line segment pq lies completely in R. Otherwise, it is called concave.
CS6234 Advanced Algorithms - Convex hull. Terminologies – ◦ Convex hull of a set Q of points is the smallest convex polygon P for which each point in.
CS 376 Introduction to Computer Graphics 02 / 14 / 2007 Instructor: Michael Eckmann.
BASIC GEOMETRIC ELEMENTS. POINTS AND LINES POINTS We may think of a point as a "dot" on a piece of paper. We identify this point with a number or a CAPITAL.
VOCAB V 100 The sum of the lengths of the sides of a polygon is the…
Vectors and the Geometry
Vector 2.
Vectors Some quantities can be described with only a number. These quantities have magnitude (amount) only and are referred to as scalar quantities. Scalar.
13 VECTORS AND THE GEOMETRY OF SPACE.
Oblique Triangles and Vectors
Contents 7.1 Vectors in 2-Space 7.2 Vectors in 3-Space 7.3 Dot Product
Copyright © Cengage Learning. All rights reserved.
Convex Hull.
8-6 Vectors Warm Up Lesson Presentation Lesson Quiz Holt Geometry.
Chapter 3 Vectors September 17, 2018 Chap 3.
10 m 16 m Resultant vector 26 m 10 m 16 m Resultant vector 6 m 30 N
Algorithm design techniques Dr. M. Gavrilova
Grids Geometry Computational Geometry
Grids Geometry Computational Geometry
Introduction to Vectors
Convex Hull obstacle start end 11/21/2018 4:05 AM Convex Hull
Grids Geometry Computational Geometry
GEOMETRY.
Computational Geometry Capter:1-2.1
Geometry.
Chapter 3 Vectors.
Data Analysis/ Probability
Convex Sets & Concave Sets
Unit 1: Angle Pair Relationships
Vectors and the Geometry
2.5. Basic Primitive Intersection
UNIT 1 Vocabulary Review
Objectives Find the magnitude and direction of a vector.
Copyright © Cengage Learning. All rights reserved.
Copyright © Cengage Learning. All rights reserved.
CMPS 3130/6130: Computational Geometry Spring 2017
8-6 Vectors Warm Up Lesson Presentation Lesson Quiz Holt Geometry.
VECTORS.
Convex Hull obstacle start end 4/30/2019 5:21 PM Convex Hull
Week 2 Vectors in Physics.
Computational Geometry Algorithms
Transformations and Congruence
Vectors and the Geometry
CHAPTER 10 Geometry.
Presentation transcript:

Geometry

Geometric Problems Usually refers to problems involving points, lines, polygons Will focus on 2D problems here. Some 3D extensions are straightforward General characteristics Geometric algorithms usually built on simpler geometric structures/algorithms Often there are many special cases Often need to be sure to account for floating-point error

Points Points in 2D: For point p, just a pair of values: px and py Store as a struct, class, or pair Distance between points p and q: 𝑝 𝑥 − 𝑞 𝑥 2 + 𝑝 𝑦 − 𝑞 𝑦 2

Lines and Line Segments 3 main representations: Implicit, Pair of Points, Point and Ray Implicit form: ax + by + c = 0 If b=1, this is equivalent to y=mx+b. But, it’s also capable of representing vertical lines (such as x=1). Store as 3 values: a, b, c Represents the infinite line To find a point on the line, we must solve for a value, e.g. by setting x or y to a specific value and solving for the other. Some of the information, however, is redundant – an infinite line should need only 2 parameters, but this requires 3

Lines and Line Segments 3 main representations: Implicit, Pair of Points, Point and Ray Pair of points: p and q Store as a structure with 2 points Thus, 4 total degrees of freedom: 2 for the line, and 1 for each endpoint Can represent a line segment, not just an infinite line Implies a direction: p to q (as opposed to q to p) A common way that lines are specified as input – two known points and we want the line (shortest path) between them But, on its own, not the most useful form

Lines and Line Segments 3 main representations: Implicit, Pair of Points, Point and Ray Point and Ray A point p, and a direction vector (ray) v Both p and v can be stored as points (the vector has an x and a y component, just like a point) Can obtain from a pair of points: v = q-p That is, vx = qx-px, vy=qy-py Gives a parameterization of the line: p+vs s in [0,1] is the original line segment s < 0 are points before p, s > 1 are points after q

Intersecting Lines To intersect lines, need to solve for common point Implicit form of line: see book Parametric form of lines: Assume lines L1 and L2, defined by p1+v1s and p2+v2t i.e. parameterized by s and t So, we must have p1x+v1xs = p2x+v2xt and p1y+v1ys = p2y+v2yt Can solve for s and t: 𝑠= 𝑝 1𝑦 𝑣 2𝑥 + 𝑝 2𝑥 𝑣 2𝑦 − 𝑝 1𝑥 𝑣 2𝑦 − 𝑝 2𝑦 𝑣 2𝑥 𝑣 1𝑥 𝑣 2𝑦 − 𝑣 1𝑦 𝑣 2𝑥 𝑡= 𝑝 1𝑦 𝑣 1𝑥 + 𝑝 2𝑥 𝑣 1𝑦 − 𝑝 1𝑥 𝑣 1𝑦 − 𝑝 2𝑦 𝑣 1𝑥 𝑣 1𝑥 𝑣 2𝑦 − 𝑣 1𝑦 𝑣 2𝑥 Notice: parallel (no intersection) when denominators are 0 Once we solve for s and/or t, can plug values in to find point of intersection But, often, all we need are the s and t values

Vectors Vector has x and y components: vx, vy Vectors have Direction Direction can be thought of as the angle from horizontal tan 𝜃 = 𝑣 𝑦 𝑣 𝑥 Note: Use atan2(numerator,denominator) function in C++ to get full range of angles Vectors have Magnitude 𝑣 = 𝑣 𝑥 2 + 𝑣 𝑦 2

Dot Product Given two vectors, v and w, the dot product is defined as vxwx+vywy The dot product is also equal to 𝑣 𝑤 cos 𝜃 Where q is the angle between the two vectors Can be used to project one vector along another Computes portion of one vector in direction of another w q v |w|cosq / |v|

Distance between point and a line Assume line is point-ray form: p and v are given. Want distance to point q. Form vector from p to q – call it w. Compute v’ = v/|v| (a unit-length vector in the same direction as v) Compute dot product of w and v’ (call this u) This is the amount of w projected in the direction of v The point a = p+uv’ is the nearest point on the line to the point q So, just compute distance from a to q. This is the same as the magnitude of w-uv’ If we want distance to line segment, then use only if 0<=u<=1 Otherwise, we are closer to an endpoint of the line segment

Cross product and sidedness test Defined in 3D, but can be used in 2D to do a sidedness test Cross product of v and w is vxwy-vywx This is the magnitude of the perpendicular vector in 3D If Cross product is positive, then w is to the left of v If Cross product is negative, then w is to the right of v This is often called a sidedness test: Given points a, b, c Form vector v from a to b (v=b-a) Form vector w from a to c (w=c-a) (or can form w from b to c) Determine sign of cross product between v and w Determines if c is on the left or right of the line from a to b

Cross product and area The magnitude of the cross product of v and w is 𝑣 𝑤 sin 𝜃 This is the area of a parallelogram formed by v and w So, the area of the triangle with edges v and w is ½ the magnitude of the cross product. Positive if w is to the left of v, negative if to the right w q v

Area of a Polygon Order vertices in counterclockwise order. Take every pair of vertices (vi and vi+1) and compute vi,xvi+1,y-vi,yvi+1,x Sum these values up Then, divide by 2 This is the area of the polygon What is really going on: we are forming triangles from the origin and the two vertices. Then, we compute the area of the triangle using the cross product.

Point inside polygon test Order vertices in counterclockwise order. Take all pairs of vertices (including first and last) Compute the angle from the query point q to each of the 2 vertices Add the angle if it’s a left-hand side when going from vertex i to i+1 Subtract if it’s a right-side turn If the point is inside the polygon, the angles will sum to 360 degrees (2*PI radians) Be sure to allow for numerical error – it is unlikely to be exactly 2*PI radians If outside, they will sum to 0

Convex Hull Given a set of points, find the set of points that contain all other points Think of it as wrapping a rubber band around all points, and letting go – the points the band is touching will be the ones on the convex hull.

Graham Scan for computing Convex Hull Several algorithms for computing Convex Hull Graham Scan is one of the easiest to implement Find the lowest point (smallest y value – if tie, choose leftmost = smallest x) This point must be on the convex hull (any extreme point in some direction will be) Order all other points in order by angle from this point Then, add points from smallest to largest angle Check last 3 points added – if left side (left hand turn), keep point Otherwise, remove previous point, and retest with remainder

Find lowest point, and order points in order

Add lowest point (must be on convex hull)

Add next point and check if left turn It is, so keep the point

Add next point and check if left turn It is not, so we will delete previous

Check the last 3 – they now do form a left turn

Add another point and check for left turn It is left, so keep the point

Add another point and check for left turn It is not, so we’ll remove previous

Check again for a left hand turn It is not, so we’ll remove previous

Now the last 3 points form a left hand turn

This will continue until the full convex hull is found