0% found this document useful (0 votes)
12 views31 pages

2024 CSN523 Lec 9-10

Uploaded by

kagzinaqiyah2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views31 pages

2024 CSN523 Lec 9-10

Uploaded by

kagzinaqiyah2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

INDIAN INSTITUTE OF TECHNOLOGY ROORKEE

CSN-523: Computational Geometry

Lecture 9-10: Data Representation for Geometric Problems

Dr. Sudip Roy


Department of Computer Science & Engineering
Representation of a Point:

 Array versus Records


1. Arrays of the appropriate number of coordinates to represent all points
2. Easier to understand Arrays versus Records
All points will be represented by arrays of the appropriate number of coordinates. It is common practice to represent a point by a record with fields named x and y, but this precludes the
use of for-loops to iterate over the coordinates.19 There may seem little need to write a for-loop to iterate over only two indices, but I find it easier to understand, and it certainly
generalizes to higher dimensions more easily.

3. Generates to higher dimensions more easily


 Integers versus Reals
1. Integer coordinates rather than floating- point number coordinates
We will represent the coordinates with integers rather than with floating-point numbers wherever possible. This will permit
us to avoid the issue of floating-point round-off error and allow us to write code that is verifiably correct within a range of
coordinate values. Numerical error is an important topic and will be discussed at various points throughout the book (e.g.,
2. No issue of floating-point round off error Sections 4.3.5 and 7.2). Obviously this habit of using integers will have to be relaxed when we compute, for example, the
point of intersection between two line segments. The type definitions will be isolated so that modification of the code to
handle different varieties of coordinate datatypes can be made in one location.

3. Verifiably correct within a range of coordinate values

2
Representation of a Point:

 Point Type Definition


1. All type identifiers begin with lowercase t
2.All defined constants entirely uppercase.
3. The suffixes i and d indicate integer and double types respectively

3
Representation of a Polygon:

 Main options
1. Array or list
2. Singly or doubly linked list
3. Linear or circular
 Arrays
1.Attractive for code clarity
2. Clumsy with insertion and deletion of points.
 We sacrifice simplicity to gain ease of deletion.
 Use a doubly linked circular list to represent a polygon

4
Representation of a Polygon:

□ The data structure for a single vertex


1. tVertexStructure
2. next and prev for links to adjacent vertices
3. vnum is integer index for printout
4. vertices is global for "head" of the list

5
Representation of a Polygon:

Loop to process all vertices

6
Implementation Issues:

7
Representation of a Polygon:

 Two basic list processing routines


1.Allocating a new element (NEW)
2.Adding a new element to the list (ADD)
 As macros, with NEW taking the type as one parameter.
1. Macros are text based and oblivious to types.
 ADD first checks to see if head is non- NULL
1.If so, insert the cell prior to head
2.If not, head points to the added cell
 See the code in next slide

8
Representation of a Polygon:

9
Area Computation of a Simple Polygon:

Problem
Given a simple polygon P of n vertices, compute
its area.

Area of a convex polygon


Find a point inside P, draw n triangles and
compute the area.

10
Area Computation of a Simple Polygon:

A better idea for convex polygon


We can triangulate P by non-crossing diagonals
into n - 2 triangles and then find the area.

A better idea for simple polygon


We can do likewise.

11
Area Computation of a Simple Polygon:
Ancient Triangles

Modern Triangles

Simple Polygon with n Triangulation

12
Area Computation of a Simple Polygon:

If P be a simple polygon with n vertices with coordinates of the vertex 𝑝 being


𝑥 , 𝑦 , 1 ≤ i ≤ n, then twice the area of P is given by

2𝐴 𝑝 𝑥𝑦 𝑦𝑥
.

13
Implementation Issues:

14
Point Inclusion in a Simple Polygon:

Problem
Given a simple polygon P of n points, and a
query point 𝑞 , is 𝑞 ∈ P?

What if P is convex?
Easy in O(n). Takes a little effort
to do it in O(log n). Left as an exercise.

Another idea for convex polygon


Stand at q and walk around the polygon. We
can show the same result for a simple polygon
also.

15
Point Inclusion in a Simple Polygon:

Another idea for convex polygon


Stand at q and walk around the polygon. We
can show the same result for a simple polygon
also.

Another technique: Ray Shooting


Shoot a ray and count the number of crossings
with edges of P. If it is odd, then q ∈ P. If it is
even, then q ∉ P. Some degenerate cases need
to be handled. Time taken is O(n).

16
Planar Subdivisions:

 Exactly one face is unbounded, the outer face

 Every other face is bounded and has an outer boundary

consisting of vertices and edges

 Any face has zero or more inner boundaries

17
Representing Planar Subdivisions:

 A subdivision representation has a vertex-object class,

an edge-object class, and a face-object class

 It is a pointer structure where objects can reach

incident (or adjacent) objects easily

18
Representing Planar Subdivisions:

Use the edge as the central object

For any edge, exactly two vertices are incident,


up to two faces are incident, and zero or more
other edges are adjacent

19
Representing Planar Subdivisions:

Use the edge as the central object,


and give it a direction

Now we can speak of Origin,


Destination, Left Face, and Right Face

20
Representing Planar Subdivisions:

Four edge are of special interest

21
Representing Planar Subdivisions:

We apply a trick/hack/impossibility:
split every edge length-wise(!) into two half-
edges
Every half-edge:
o has exactly one half-edge as its Twin
o is directed opposite to its Twin
o is incident to only one face (left)

22
DCEL:

The doubly-connected edge list is a subdivision


representation structure with an object for A half-edge object stores:

every vertex, every half-edge, and every face • Origin (vertex)


• Twin (half-edge)

A vertex object stores: • Incident Face (face)

• Coordinates • Next (half-edge in cycle of the

• IncidentEdge (some half-edge leaving it) incident face)


• Prev (half-edge in cycle of the
incident face)

23
DCEL:

A face object stores:


• Outer Component
(half-edge of outer cycle)
• InnerComponents
(list of half-edges for the inner cycles
bounding the face)

24
DCEL:

A vertex object stores: A half-edge object stores:


• Coordinates • Origin (vertex)
• IncidentEdge • Twin (half-edge)
A face object stores: • Incident Face (face)
• Outer Component • Next (half-edge in cycle of the incident
(half-edge of outer cycle) face)
• InnerComponents • Prev (half-edge in cycle of the incident
(half-edges for the inner cycles) face)

25
DCEL:

26
Storing the Polygon as DCEL:

27
Storing the Polygon as DCEL:

28
DCEL:

• planar graph with only straight-line edges


• also called planar subdivision
• a data structure: doubly connected edge list
• each edge is replaced by two directed half-edges

• the half-edges enclosing a face form a counterclockwise cycle

29
DCEL:

• vertex v
• coordinates
• an incident half-edge Incident Edge(v) = (v, w)
• half edge 𝑒⃗
• 3 edges Twin(𝑒⃗), Next(𝑒⃗), Prev(𝑒⃗)
• vertex Origin(𝑒⃗)
• a face Incident Face(𝑒⃗)
• face f
• a half-edge 𝑒⃗ (f) of its exterior boundary
• a half-edge of each face contained in f; they are
stored in a list L(f)

30
DCEL:

31

You might also like