# 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.

## Presentation on theme: "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."— Presentation transcript:

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 Be careful when you can’t –Create EPSILON, “small enough” distance based on precision –Two numbers are equal if |x-y| < EPSILON

Lines Any 2 points determine a line –Four coordinates in 2d: x1,y1, x2, y2 –(y-y1)/(x-x1) = (y2-y1)/(x2-x1) Slope-intercept form y= mx + b (except vertical line) M is slope (tangent of line’s angle)

General Form: ax+by+c=0 Works for all 2d lines, vertical & horizontal Need canonical form –Set b=1 or b=0 (textbook) –Set a*a+b*b =1 (more typical in mathematics) –If a*a+b*b=1, then a=sin(theta), b=cos(theta)

Angle between lines Angle of line with horizontal: Atan(m) Angle between 2 lines (slope-int) atan(m1)-atan(m2) (or 180 - that) Or: atan((m2-m1)/(1+m1m2)) Angle between 2 lines (ax+by+c) Atan((a1b2-a2b1) / (a1a2+b1b2))

Intersection of Lines Directly (formula on p. 293) By search –Given 2 lines in “general position” –The intersection is the point at which y2 switches from being above y1 to below y1 –Binary search x values to find this point. Special cases: lines with same slope –Same line if they share a point –Parallel otherwise

Perpendicular Lines Slope m vs. slope -1/m Good for finding “closest point” Slope = m Slope = -1/m (right angle, 90 degrees) Point p Closest point on L1 is intersection with perp line through p

Voronoi Diagram Start with a set of points Compute the perpendicular bisectors of the line segments between the points These bisectors form the boundaries of regions around each point A test point in a point’s region is closer to that point than any other point in the set Models cell towers and wireless base stations.

Triangles 3 angles add up to 180 degrees Right triangle has one right angle –Pythagorean Theorem (a*a+b*b=c*c) –Trig: sin = a/c, cos=b/c (a is opposite), tan = sin/cos or a/b a b c Theta (sin is a/c)

General Triangle Laws Law of sines –a/sin A = b/sin B = c/sin C Law of cosines –a*a = b*b+c*c - 2bc cosA –(If A = 90 degrees, last term is 0)

Triangle Inequality If a, b and c are sides of a triangle, a+b > c If a+b=c, then the 3 vertices are collinear This is a useful test for whether 3 points are collinear: dist(p1,p2) + dist(p2,p3) = dist(p1,p3) Dist(p1,p2) = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))

Area of Polygon Given the coordinates of any polygon, the area is computed by the formula Total=0; For(int v=0;v { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/11/3273721/slides/slide_12.jpg", "name": "Area of Polygon Given the coordinates of any polygon, the area is computed by the formula Total=0; For(int v=0;v

Circles Circle is locus of all points equidistant (radius) from a single point (center) Area = pi * r*r Circumference = 2*pi*r Pi = 3.1415926 (and many more digits) Tangent: line touches circle at one point (perpendicular to radius at that point) Intersections: 0, 1 or 2 of 2 circles

Triangulation Knowing distance of 3 points from a query point Construct 3 circles of appropriate radius These circles will (approximately) intersect in one point This point is the query point

Download ppt "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."

Similar presentations