Dokumen - Tips - Computational Geometry Introduction Felkel Computational Geometry 19 5 Complexity
Dokumen - Tips - Computational Geometry Introduction Felkel Computational Geometry 19 5 Complexity
INTRODUCTION
PETR FELKEL
FEL CTU PRAGUE
[email protected]
https://cw.felk.cvut.cz/doku.php/courses/a4m39vg/start
[Berg]
Copyright: http://webhelp.esri.com/arcgisdesktop
– Understanding of the
geometric properties of the problem
– Proper applications of
algorithmic techniques (paradigms) and data structures
Nowadays:
– focus on practical implementations, not just on
asymptotically fastest algorithms
– nearly correct result is better than nonsense or crash
Is it OK for you?
[Berg]
CAD/CAM
– Intersections and unions of objects
– Visualization and tests without need to build a prototype
– Manufacturability
[Berg]
[Berg]
V – set of points
[Maur]
[Berg]
Prerequisite
– The input data set must be separable
– Solutions of subsets are independent
– The result can be obtained by merging of sub-results
b
Event types for segments:
- start
a
- end
- intersection
– Search trees
Region of the
constant answer:
All points in this
region are nearest
to the yellow point
C
B p* C*
p
↔
A
B*
[siggraph2008-CGAL-course]
Felkel: Computational geometry
(32)
Geometry in theory is exact
ccw(s,q,r) & ccw(p,s,r) & ccw(p,q,s) => ccw(p,q,r)
q r
[siggraph2008-CGAL-course]
Felkel: Computational geometry
(33)
Geometry with float. arithmetic is not exact
ccw(s,q,r) & !ccw(p,s,r) & ccw(p,q,s) => ccw(p,q,r)
q r
[siggraph2008-CGAL-course]
Felkel: Computational geometry
(34)
Floating-point arithmetic is not exact
a) Limited numerical precision of real numbers
Numbers represented as normalized
23 bits stored
±m2e 4 Bytes
52 bits stored
8 Bytes
[http://cs.wikipedia.org/wiki/Soubor:Single_double_extended2.gif]
2-1 1
– p = 0.510 = 00111111000000000000000000000000 2
1
– p = 0.500000810 = 00111111000000000000000000001101 2
– Mantissa of p is shifted 4 bits right to align with 12
(to have the same exponent 23)
p = 0.500000810 = 01000001000010000000000000000000 21101
–> four least significant bits (LSB) are lost
– The result is 11.5 instead of 11.4999992
Felkel: Computational geometry
(36)
Floating-point arithmetic is not exact
b) Smaller numbers are shifted right during additions
and subtractions to align the digits of the same order
Example for float:
12 – p for p ~ 0.5 (such as 0.5+2^(-23) )
– Mantissa of p is shifted 4 bits right to align with 12
–> four least significant bits (LSB) are lost
24 – p for p ~ 0.5
– Mantissa of p is shifted 5 bits right to align with 24 -> 5 LSB are lost
Try it on [http://www.h-schmidt.net/FloatConverter/IEEE754.html or
http://babbage.cs.qc.cuny.edu/IEEE-754/index.xhtml]
௫ ௫ ௬ ௬ ௬ ௬ ௫ ௫
r
௫ ௬
q
Three points
– lie on common line =0
– form a left turn = +1 (positive)
– form a right turn = –1 (negative)
p
Felkel: Computational geometry
(38)
Experiment with orientation predicate
orientation(p,q,r) = sign((px-rx)(qy-ry)-(py-ry)(qx-rx))
r = [24, 24]
Ideal return values
dy, + left turn
q = [12, 12]
double
p = [0.5 + dx, 0.5 + dy], dx = k.253
– right turn [0.5, 0.5]
Value of the LSB
p
dx,
– right turn
p
Pivot r Pivot p
Felkel: Computational geometry
(41)
Floating point orientation predicate double exp=-53
Pivot p
௫ ௫ ௬ ௬ ௬ ௬ ௫ ௫
4 bits lost 4 bits lost
௫ ௫ ௬ ௬ ௬ ௬ ௫ ௫
5 bits lost 5 bits lost
௫ ௫ ௬ ௬ ௬ ௬ ௫ ௫
௫ ௫ ௫
[Kettner04]
[siggraph2008-CGAL-course]
Felkel: Computational geometry
(48)
Solution
1. Use predicates, that always return the correct
result -> Schewchuck, YAP, LEDA or CGAL
2. Change the algorithm to cope with floating point
predicates but still return something meaningfull
(hard to define)
3. Perturb the input so that the floating point
implementation gives the correct result on it
Computational Geometry
Algorithms Library
Slides from [siggraph2008-CGAL-course]
[siggraph2008-CGAL-course]
Felkel: Computational geometry
(52)
Exact geometric computing
Predicates Constructions
[siggraph2008-CGAL-course]
Felkel: Computational geometry
(53)
CGAL Geometric Kernel (see [Hert] for details)
Encapsulates
– the representation of geometric objects
– and the geometric operations and predicates on these objects
Number type