0% found this document useful (0 votes)
4 views

Lecture Notes_ Computational geometry

Uploaded by

aishorjoshuchi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lecture Notes_ Computational geometry

Uploaded by

aishorjoshuchi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Problem 1: Given the coordinates of the three vertices of a triangle in a two-dimensional plane,

determine the area of the triangle.

Solution:

Suppose the coordinates of the vertices are (x1, y1), (x2, y2) and (x3, y3).

In that case, the area of the triangle can be found by calculating the following expression:
= 1/2((𝑥1 − 𝑥2)(𝑦2 − 𝑦3) − (𝑥2 − 𝑥3)(𝑦1 − 𝑦2))
= 1/2 (𝑥1𝑦2 + 𝑥2𝑦3 + 𝑥3𝑦1 − 𝑥1𝑦3 − 𝑥3𝑦2 − 𝑥2𝑦1)

It is to be noted that this equation can give a negative value at times. When computing the area,
even if the result of the equation becomes a negative value (e.g. -17), we will simply output the
absolute value of the result (e.g. 17) and ignore the (-)ve sign.

However, the sign of the result of the expression (positive or negative), can have interesting side
effects.

If (x1, y1), (x2, y2) and (x3, y3) are arranged in a clockwise direction, the value of the
determinant will be negative.

If (x1, y1), (x2, y2) and (x3, y3) are arranged in an anti-clockwise direction, the value of the
determinant will be negative.
Problem 2:

A car is moving on a road starting from the point (x1, y1) and reaches an intersection point at the
coordinate (x2, y2). The car wants to move to a road that leads to the point (x3, y3). Detect if it will
have to turn left, right or go straight.

Solution:

Consider the following cases:

Case 1:
Case 2:

Case 3:

Problem 3:

Two line segments, connecting the points (x1, y1), (x2, y2) and (x3, y3), (x4, y4) respectively are
given. Find out if they intersect or not.

Solution:

Let us define the points P1 (x1, y1) and P2 (x2, y2), Q1(x3, y3) and Q4(x4, y4) respectively. Let us
define Sign(x1, y1, x2, y2, x3, y3) as a function that returns +1 if the area of the triangle connecting
(x1, y1), (x2, y2) and (x3, y3) is positive and returns -1 otherwise. In that case, observe that in the
following case, where the two lines intersect, Sign(x1, y1, x3, y3, x2, y2) and Sign(x1, y1, x4, y4, x3,
y3) have the opposite return values. Similarly Sign(x3, y3, x1, y1, x4, y4) and Sign(x3, y3, x2, y2, x4,
y4) have opposing return values as well.

The key observation here is that two such line segments will intersect if Sign(x1, y1, x3, y3, x2,
y2)!=Sign(x1, y1, x4, y4, x2, y2) and Sign(x3, y3, x1, y1, x4, y4) != Sign(x3, y3, x2, y2, x4, y4), and
otherwise, they will not.

Note: This formulation does overlook a few special cases, but handling those tricky cases is
beyond the scope of this lecture.

You can learn more from here: http://www.dcs.gla.ac.uk/~pat/52233/slides/Geometry1x1.pdf


Problem 4:

Given an n-sided polygon, the coordinates of whose vertices are given, find out if another point
P(x, y) is included inside the polygon or not.

Solution:

Draw a line from P to another point that is far, far away (i.e. a point so far away that is surely
outside the polygon). Now, find out the number of sides of the polygon that your drawn line
intersects with. If the line intersects with an odd number of segments of the polygon, P is inside
the polygon. Otherwise, it is outside.

You might also like