1 Programming Interest Group Tutorial Eight Computational Geometry.

Slides:



Advertisements
Similar presentations
Solving Linear Systems by Graphing
Advertisements

Computational Geometry
Geometry. Floating point math Avoid floating point when you can –If you are given a fixed number of digits after the decimal, multiply & use integers.
ADA: 15. Basic Math1 Objective o a reminder about dot product and cross product, and their use for analyzing line segments (e.g. do two segments.
COMPASS Practice Test F Algebra This PowerPoint presentation will present 10 sample problems with answers. You can save this file to your computer and.
Equations of parallel, perpendicular lines and perpendicular bisectors
2.2 Parallel and Perpendicular Lines and Circles Slopes and Parallel Lines 1. If two nonvertical lines are parallel, then they have the same slopes. 2.
Analytic Geometry Section 3.3
CSE53111 Computational Geometry TOPICS q Preliminaries q Point in a Polygon q Polygon Construction q Convex Hulls Further Reading.
7.1 Solving Linear Systems by Graphing Systems of Linear Equations Solving Systems of Equations by Graphing.
Midpoint and Distance Formulas Goal 1 Find the Midpoint of a Segment Goal 2 Find the Distance Between Two Points on a Coordinate Plane 12.6.
A little bit of geometry Jordi Cortadella Department of Computer Science.
Polygons in the Coordinate Plane Techniques Examples Practice Problems.
Vocabulary Sheets Why??? Do I have to?? Code. Angle [definition] Formed by two rays with the same endpoint [picture or example of term] [symbol]
Lines in the Coordinate Plane
GRE: Graphical Representations
Week 4 Functions and Graphs. Objectives At the end of this session, you will be able to: Define and compute slope of a line. Write the point-slope equation.
Computational Geometry 2012/10/23. Computational Geometry A branch of computer science that studies algorithms for solving geometric problems Applications:
Section 1-1 Points and Lines. Each point in the plane can be associated with an ordered pair of numbers, called the coordinates of the point. Each ordered.
 Solve each equation: . Warm up. Lesson 10-1 Introduction to Analytical Geometry Objective: To find the distance and midpoint between two points on.
Linear Functions Section 1-1 Points Lines Objective: To find the intersection of two lines and to find the length and the coordinates of the midpoint of.
DAY 1 DISTANCE ON THE PLANE – PART I: DISTANCE FROM THE ORIGIN MPM 2D Coordinates and Geometry: Where Shapes Meet Symbols.
Precalculus Section 6.2 Apply the equations of circles
Distance On a coordinate plane Finding the length of a line segment.
Warm-Up 1. Put in slope-intercept form: 3x – 4y = -12
Slope Intercept form. Geometry Unit 2-3, 2-4 Equations of lines Parallel and perpendicular slopes.
1.5 Writing Equations of Parallel and Perpendicular Lines
Lesson 1-3 Formulas Lesson 1-3: Formulas.
Chapter 8 : Analytic Geometry
Geometry Creating Line Equations Part 1
6.1 Solving Systems of Linear Equations by Graphing
Lesson 3-6: Perpendicular & Distance
2.2.4 Use slope criteria for parallel and perpendicular lines to solve problems on the coordinate plane.
Coordinate Geometry Notes Name:____________________________
3-6 Perpendiculars and Distance
3-1 Graphing Systems of Equations
Grids Geometry Computational Geometry
Grids Geometry Computational Geometry
Introduction to Graphing
Linear Equations in two variables
7.1 Solving Linear Systems by Graphing
Grids Geometry Computational Geometry
Coordinate Plane Sections 1.3,
Parallel Lines: SLOPES ARE THE SAME!!
Warm-Up 1. Put in slope-intercept form: 3x – 4y = -12
Do Now Tell whether these two lines are parallel, perpendicular or neither. Given the ordered pair, (-1, 4), write an equation in point-slope form that.
Chapter 1 Graphs, Functions, and Models.
3-5 & 3-6 Lines in the Coordinate Plane & Slopes of Parallel and Perpendicular Lines.
9.3 Graph and Write Equations of Circles
3.1 Solving Linear Systems by Graphing
Geometry Equations of Circles.
Day 138 – Equation of ellipse
3.5 Parallel and PerpendicularLines in the Coordinate Plane
6-1 Solving Systems by Graphing
13.1 Cooridinate Geometry.
Introduction to Graphing
A little bit of geometry
Review Unit 6 Test 1.
Ch 12.1 Graph Linear Equations
Warm-Up 1. Put in slope-intercept form: 3x – 4y = -12
1.2 Solving Linear Systems by Graphing
The Distance & Midpoint Formulas
Circles in the Coordinate Plane
Chapter 9 Lesson 3 Pg. 699 Solving Systems of Equations by Graphing
Warm Up April 21, 2014 If the line segment AB has a ratio of 2:5, what would be the ratio of the line segment BA? 2. Find the point P between the points.
3.1 Solving Linear Systems by Graphing
Chapter 9 Lesson 3 Pg. 699 Solving Systems of Equations by Graphing
Warm-Up 1.) Using the point slope formula find the equation of a line with slope -2 , passing through the point (1, 3) 2.) Graph the line y = 3x + 4.
COMPASS Practice Test 15.
Unit 5 Geometric and Algebraic Connections
Presentation transcript:

1 Programming Interest Group Tutorial Eight Computational Geometry

2 Introduction Computational geometry is the branch of computer science that studies algorithms for solving geometric problems. Applications Computer graphics, robotics, VLSI design, computer-aided design, etc. Two dimensions, three dimensions, etc. Common objects in two dimensions point, line, line segment, vertices, polygon, circle, etc.

3 Points A point is defined by its two coordinates in the plane typedef struct { double x; double y; } point; x y p(a,b) 0 a b

4 Distance What’s the distance between two given points? double distance(point p1, point p2) { double dx, dy; dx = p1.x – p2.x; dy = p1.y – p2.y; return sqrt(dx*dx + dy*dy); }

5 Lines Consider lines in the plane Two possible representations By equations such as y = ax + b where a is the slope of the line and b is the y-intercept. by any pair of points (x 1, y 1 ) and (x 2, y 2 ) which lie on the line Then the slope will be (y 1 -y 2 )/(x 1 -x 2 ) We use the formula ax + by + c = 0 to represent a line

6 Lines typedef struct { double a;/* x-coefficient */ double b;/* y-coefficient */ double c;/* constant term */ } line; If the y-coefficient is 0, set the x-coefficient to 1; Otherwise, set the y-coefficient to 1.

7 Lines Given two points p1, p2, determine the line points_to_line(point p1, point p2, line *m) { if (p1.x == p2.x) { m->a = 1; m->b = 0; m->c = -p1.x; } else { m->b = 1; m->a = -(p1.y – p2.y) / (p1.x – p2.x); m->c = -(m->a * p1.x) – (m->b * p1.y); } Should be (fabs(p1.x-p2.x) <= EPSILON), where EPSILON is a very small positive number like

8 Lines Given a point and the slope, determine the line point_and_slope_to_line(point p, double s, line *m) { m->a = -s; m->b = 1; m->c = -( (l->a * p.x) + (l->b * p.y) ); }

9 Line Intersection Two distinct lines have one intersection point unless they are parallel int parallelQ(line m1, line m2) { return ( (fabs(m1.a - m2.a) <= EPSILON ) && (fabs(m1.b – m2.b) <= EPSILON) ); } int same_lineQ(line m1, line m2) { return ( parallelQ(m1, m2) && (fabs(m1.c – m2.c) <= EPSILON) ); }

10 Line Intersection intersection_point(line m1, line m2, point *p) { if (same_lineQ(m1, m2)) { printf(“Warning: identical lines.\n”); p->x = p->y = 0.0; } if (parallelQ(m1, m2)) { printf(“Error: Distinct parallel lines do not intersect.\n”); return ; } p->x = (m2.b * m1.c – m1.b * m2.c) / (m2.a * m1.b – m1.a * m2.b); if (fabs(m1.b) > EPSILON) /* test for vertical line */ p->y = - (m1.a * p->x + m1.c ) / m1.b; else p->y = - (m2.a * p->x + m2.c ) / m2.b; }

11 Closest Point Identify the point on line m which is closest to a given point p closest_point(point p_in, line m, point *p_c) { line perp;/* perpendicular to m if (fabs(m.b) <= EPSILON) {/* vertical line */ p_c->x = -m.c; p_c->y = p_in.y; return; } if (fabs(m.a) <= EPSILON) {/* horizontal line */ p_c->x = p_in.x; p_c->y = -m.c; return; } point_and_slope_to_line(p_in, 1/m.a, &perp); intersection_point(m, perp, p_c); }

12 Line Segments A line segment is the portion of a line which lines between two given points inclusive. typedef struct { point p1, p2; /* endpoints of line segment */ } segment;

13 Line Segment Intersections To test whether two segments intersect It’s complicated due to tricky special cases int segment_intersect(segment s1, segment s2) { line m1, m2; point p;/* intersection point */ points_to_line(s1.p1, s1.p2, &m1); points_to_line(s2.p1, s2.p2, &m2); if (same_lineQ(m1, m2) )/* overlapping or disjoint segments */ return ( point_in_box(s1.p1, s2.p1, s2.p2) || point_in_box(s1.p2, s2.p1, s2.p2) || point_in_box(s2.p1, s1.p1, s1.p2) || point_in_box(s2.p2, s1.p1, s1.p2) ); if ( parallelQ(m1, m2) ) return 0; intersection_point(m1, m2, &p); return (point_in_box(p, s1.p1, s1.p2) && point_in_box(p, s2.p1, s2.p2) ); }

14 Line Segment Intersections Whether a point lies in a box? #define max(A, B)((A) > (B) ? (A) : (B)) #define min(A, B)((A) < (B) ? (A) : (B)) int point_in_box (point p, point b1, point b2) { return ( (p.x >= min(b1.x, b2.x)) && (p.x <= max(b1.x, b2.x)) && (p.y >= min(b1.y, b2.y)) && (p.y <= max(b1.y, b2.y)) ); }

15 Triangles and Trigonometry Angle is the union of two rays sharing a common endpoint. Trigonometry is the branch of mathematics dealing with angles and their measurement. Two measures of angles Radians: from 0 to 2π Degree: from 0 to 360 Right angle: 90 o or π/2 radians

16 Triangles and Trigonometry Right triangle contains a right internal angle. Pythagorean theorem: |a| 2 + |b| 2 = |c| 2 a and b are the two shorter sides, c is the longest side, or hypotenuse. a b c

17 Triangles and Trigonometry Two important trigonometric formulae Law of Sines: Law of Cosines: a b c A B C

18 Area of a Triangle The signed area of a triangle can be calculated directly from its coordinate representation A(T) = (a x b y – a y b x + a y c x – a x c y + b x c y – c x b y )/2 double signed_triangle_area (point a, point b, point c) { return ( (a.x*b.y – a.y*b.x + a.y*c.x – a.x*c.y + b.x*c.y – c.x*b.y) / 2.0 ); } double triangle_area (point a, point b, point c) { return fabs(signed_triangle_area(a,b,c)); }

19 Circles A circle is defined as the set of points at a given distance (or radius) from its center (x c, y c ). A disk is circle plus its interior. typedef struct { point c;/* center of circle */ double r;/* radius of circle */ } point;

20 Polygons Polygons are closed chains of non- intersecting line segments. We can represent a polygon by listing its n vertices in order around the boundary of the polygon. typedef struct { int n; /* number of points in polygon */ point p[MAXPOLY]; /* array of points */ } polygon;