# Geometric figure

A geometric figure is a set of points in space. For example, a point, line, line segment, ray_, angle, polygon, curve_, region_, plane_, surface_, solid_, etc.

A point is that which has no part. http://aleph0.clarku.edu/~DJoyce/java/elements/bookI/bookI.html

The study of geometric figures is a branch of mathematics called geometry. Contemporary geometry has many subfields including Euclidian geometry and toplogy.

# 1   Function

Geometry was essential to calculating the diameter of the Earth and navigation (via longitude and latitude). It is also used to calculate the distance to distant stars_. Method used to study geometry led to that development of philosophy.

# 2   Substance

## 2.1   Line

A line is a straight one-dimensional figure having no thickness and extending infinitely in both directions.

A line is uniquely determined by two points, and the line passing through points $$A$$ and $$B$$ is denoted $$\overleftrightarrow{AB}$$.

Similarly, the length of the finite line segment terminating at these points may be denoted $$\overline{AB}$$.

The equation of a line is typically written in slope-intercept form, y = m * x + b, where m is the slope and b is the y-intercept, the point where the line cross the y-axis.

## 2.2   Segment

A line segment is a part of a line that is bounded by two distinct endpoints; the convex hull of two points, called the endpoints.

## 2.3   Shape

A shape is the form of an object or its external boundary, or external surface. For example, circles, polygons, and spheres.

### 2.3.1   Polygon

A polygon is a plane figure that is bounded by a finite chain of straight line segments closing in a loop to form a closed polygonal chain or circuit.

A polygon is a region of a plane bounded by a finite number of line segments, called "edges". Points where two successive edges meet are called "vertices". [2]

A polygon is convex if for any two points, p and q, inside the polygon, the line segment pq is completely inside the polygon. [2]

The sum of the interior angles in a polygon sum to (n - 2) * 180. The intuition is this: the sum of the angles of a triangle equal 180. Every time we add a side to a polygon, we add another triangle. (A square can be divided into two triangles, a pentagon into three.)

### 2.3.2   Triangle

A triangle is a polygon with three angles.

An isosceles triangle (from Greek isosceles "equal-legged") is a triangle with two sides of equal length.

#### 2.3.2.1   Right triangle

In a right triangle, the following properties hold:

The Pythagorean theorem is a simplification of the law of cosines:

\begin{equation*} opposite^2 + adjacent^2 = hypotenuse^2 \end{equation*}

#### 2.3.2.2   Law of cosines

The law of cosines related the length of three side of a triangle to the cosine of one of its angles:

\begin{equation*} C^{2} = A^{2} + B^{2} - 2AB\cos{\theta} \end{equation*}

### 2.3.3   Square

A square is a shape that has four equal sides and four equal angles.

# 3   Three dimensional shapes

## 3.1   Cube

A cube is ...

Properties:

\begin{equation*} A = 6a^2 \end{equation*}
\begin{equation*} V = a^3 \end{equation*}

## 3.2   Sphere

The roundest thing in the universe are neutrons stars.

Properties:

\begin{equation*} A = 4 \pi r^2 \end{equation*}
\begin{equation*} V = \frac{4}{3} \pi r^3 \end{equation*}

For a given volume, the object with the smallest surface is the sphere.

# 4   Relationships

## 4.1   Distance

def distance(p1, p2):
return math.sqrt((p2.x - p1.x) ** 2 + (p2.y - p1.y) ** 2)


## 4.2   Angles

The angle between three point can be calculated from the law of cosines:

def measure_angle(p1, p2, p3):
"""
Measure the angle formed by three points.

>>> P = Point
>>> round(measure_angle(P(0, 1), P(0, 0), P(1, 0)), 1)
90.0
>>> round(measure_angle(P(0, 0), P(1, math.sqrt(3)), P(2, 0)), 1)
60.0
"""
a, b, c = distance(p1, p2), distance(p2, p3), distance(p3, p1)
return  math.degrees(math.acos((a ** 2 + b ** 2 - c ** 2) / (2 * a * b)))


## 4.3   Collinearity

Three points are collinear if the lines drawn between them are equivalent.

One way to check if three points, p, q and r, are collinear is to measure the distances between them. Calculate the distances between them, and then compare the longest side with the other two. If and only if these lengths are equal are the points equal. This is an impractical algorithm in a computer program because real numbers are represented as floating-point numbers because of the involvement of the square root function, which returns an irrational number.

An improvement is to measure the area of the triangle, which would be zero if and only if the points are collinear. This reduces the need for numerical precision.

How to measure the area? The Euclidean formula 1/2bh is not the best answer, and neither is the trigonometric approach. A far better plan is to regard the sides of a triangle as vectors; the two vectors emanating from any one vertex define a parallelogram, whose area is given by the cross product of the vectors. The area of the triangle is just one half of the area of the parallelogram. Actually, this computation gives the "signed area": the result is positive if the vertices of the triangle are take in counterclockwise order and negative if taken in clockwise order. What's most important for present purposes, the sign area is zero if and only if the vertices are collinear.

The vector formula for the area is expressed most succinctly in terms of the determinant of a two-by-two matrix:

A = 1/2 * [[x_1 - x_3, y_1 - y_3],
[x_2 - x_3, y_2 - y_3]]
= 1/2[(x_1 - x_3)(y_2 - y_3) - (x_2 - x_3)(y_1 - y_3)]


Because we only care about the sign of the area, we can ignore the factor of 1/2. Thus a definition for collinearity is as follows:

def is_collinear(p1, p2, p3):
return (p1.x - p3.x) * (p2.y - p3.y) == (p2.x - p3.x) * (p1.y - p3.y)


## 4.4   Segment intersection

There are two ways to determine if two line segments intersect.

One way is to find the intersection of the two segments, and then check if the intersection lies on the x-projections of both segments.

from __future__ import division
from collections import namedtuple

Point = namedtuple('Point', ['x', 'y'])
Segment = namedtuple('Segment', ['p1', 'p2'])

class Line(object):
"""
y = 2x + 3

>>> l = Line(Point(1, 5), Point(2, 7))
>>> l.slope
2.0
>>> l.intercept
3.0
"""
def __init__(self, p1, p2):
self.p1 = p1
self.p2 = p2

@property
def rise(self):
p1, p2 = self.p1, self.p2
return (p2.y - p1.y)

@property
def run(self):
p1, p2 = self.p1, self.p2
return (p2.x - p1.x)

@property
def slope(self):
return self.rise / self.run

@property
def intercept(self):
x, y = self.p1
b = y - self.rise * (x / self.run)
return b

def find_intersection(l1, l2):
"""
m1x + b1 = m2x + b2
m1x - m2x = b2 - b1
x = (b2 - b1) / (m1 - m2)

>>> l1 = Line(Point(3, 9), Point(5, 13))
>>> l2 = Line(Point(4, 5), Point(10, 2))
>>> find_intersection(l1, l2)
(1.6, 6.2)
"""
if l1.run == l2.run == 0:
pass
elif l1.run == 0:
pass
elif l2.run == 0:
pass

x = (l2.intercept - l1.intercept) / (l1.slope - l2.slope)
y = l1.slope * x + l1.intercept
return (x, y)

def within(a, b, c):
"""Check if and only if *b* is between *a* and *c* (inclusive)"""
return a <= b <= c or a >= b >= c

def do_intersect(segment1, segment2):
"""
Two diagonal lines:

>>> do_intersect(Segment(Point(0, 0), Point(1, 1)),
...              Segment(Point(0, 1), Point(1, 0)))
True

Vertical line against horizontal line:

>>> do_intersect(Segment(Point(0, 0), Point(0, 2)),
...              Segment(Point(1, 1), Point(-1, 1)))
True

Horizontal line against vertical line:

>>> do_intersect(Segment(Point(0, 0), Point(2, 0)),
...              Segment(Point(1, 1), Point(1, -1)))
True

Colinear lines:

>>> do_intersect(Segment(Point(0, 0), Point(2, 0)),
...              Segment(Point(1, 0), Point(3, 0)))
True
>>> do_intersect(Segment(Point(0, 0), Point(2, 0)),
...              Segment(Point(-1, 0), Point(1, 0)))
True
>>> do_intersect(Segment(Point(0, 0), Point(1, 0)),
...              Segment(Point(-1, 0), Point(2, 0)))
True
>>> do_intersect(Segment(Point(0, 0), Point(1, 0)),
...              Segment(Point(2, 0), Point(3, 0)))
False
>>> do_intersect(Segment(Point(0, 0), Point(2, 2)),
...              Segment(Point(1, 1), Point(3, 3)))
True
>>> do_intersect(Segment(Point(0, 0), Point(0, 2)),
...              Segment(Point(0, 1), Point(0, 3)))
True

Intersection at segment vertices:

>>> do_intersect(Segment(Point(0, 0), Point(2, 0)),
...              Segment(Point(1, 0), Point(1, 2)))
True
"""
l1, l2 = Line(segment1.p1, segment1.p2), Line(segment2.p1, segment2.p2)
(x, y) = find_intersection(l1, l2)
return (within(segment1.p1.x, x, segment1.p2.x) and
within(segment2.p1.x, x, segment2.p2.x))


This solution does not correctly handle vertical lines, which have an undefined slope.

A second solution uses curve orientations. The intuition is that two segments, AB and CD, intersect if and only if the endpoints A and B are on opposite sides of the line CD, and the endpoints C and D are on opposite sides of the line AB. To test whether two points are on opposite sides of a line through two other points, we use a counterclockwise test. [2]

The orientation of a triple of points in a plane can be clockwise, counterclockwise, or collinear. Two segments, (p1, q1) and (p2, q2), intersect if an only if one of the following two condition is true:

1. General case: (p1, q1, p2) and (p1, q1, q2) have different orientations, and (p2, q2, p1) and (p2, q2, q1) have different orientations.
2. Special case: The two segments are collinear and both the x-projections and y-projections of both segments intersect

Orientation is formally defined as the sign of the determinant of the points given in homogeneous coordinates. If the determinant is zero, then the orientation is collinear. Otherwise it is clockwise or counterclockwise.

Three points, A, B, and C, are in counterclockwise order if and only the slope of the line AB is less than the slope of the line AC. That is:

counterclockwise <=> (B.y - A.y) / (B.x - A.x) < (C.y - A.y) / (C.x - A.x)


We can rewrite this as follows:

counterclockwise <=> (C.y - A.y) * (B.x - A.x) < (B.y - A.y) * (C.x - A.x)


Another way of thinking about this test is that we're computing the cross-product of two vectors, which defined as a 2x2 determinant:

counterclockwise <=> | B.x - A.x    B.y - A.y |
| C.x - A.x    C.y - A.y | > 0

from __future__ import division
from collections import namedtuple

Point = namedtuple('Point', ['x', 'y'])
Segment = namedtuple('Segment', ['p1', 'p2'])

class Orientation(object):
CLOCKWISE = 1
COLINEAR = 0
COUNTER_CLOCKWISE = -1

def orientation(p1, p2, p3):
"""
Orientation is the imaginary rotation that is needed to move a line from a
reference placement to a target placement. In two dimensions, the
orientation is given by the angle through which is has rotated.

The orientation test determines whether a point lies to the left of, to the
right of, or on a line or plane defined by other points. This test is
performed by evaluating the sign of a determinant. The determinant is
expressed in terms of the coordinates of the points. If these coordinates
are expressed as single or double precision floating-point numbers,
roundoff error may lead to an incorrect result when the true determinant is
near zero.

If the crossproduct (b-a)x(c-a) results in the +z direction then the
rotation is positive.

See: https://en.wikipedia.org/wiki/Curve_orientation

>>> P, S = Point, Segment
>>> orientation(P(0, 0), P(1, 1), P(2, 3))
-1
>>> orientation(P(0, 0), P(1, 1), P(3, 2))
1
>>> orientation(P(0, 0), P(1, 1), P(2, 0))
1
>>> orientation(P(0, 0), P(1, 1), P(-1, 2))
-1

>>> orientation(P(0, 0), P(1, 1), P(0, 1))
-1
>>> orientation(P(0, 0), P(1, 1), P(0, -1))
1

Vertical line:

>>> orientation(P(0, 0), P(0, 2), P(1, 1))
1
>>> orientation(P(0, 0), P(0, 2), P(1, 3))
1
>>> orientation(P(0, 0), P(0, 2), P(-1, 1))
-1
>>> orientation(P(0, 0), P(0, 2), P(-1, 3))
-1

Horizontal line:

>>> orientation(P(0, 0), P(2, 0), P(1, 1))
-1
>>> orientation(P(0, 0), P(2, 0), P(3, 1))
-1
>>> orientation(P(0, 0), P(2, 0), P(1, -1))
1
>>> orientation(P(0, 0), P(2, 0), P(3, -1))
1
"""
rise1, rise2 = (p2.y - p1.y), (p3.y - p1.y)
run1, run2 = (p2.x - p1.x), (p3.x - p1.x)

det = rise2 * run1 - rise1 * run2

return (Orientation.CLOCKWISE if det < 0 else
Orientation.COLINEAR if det == 0 else
Orientation.COUNTER_CLOCKWISE)

def is_point_on_segment(segment, point):
"""Check if a point is on a segment."""
return (orientation(segment.p1, point, segment.p2) == Orientation.COLINEAR
and within(segment.p1, point, segment.p2))

def within(a, b, c):
"""Check if and only if *b* is between *a* and *c* (inclusive)"""
return a <= b <= c or a >= b >= c

def do_intersect(segment1, segment2):
"""
Two diagonal lines:

>>> do_intersect(Segment(Point(0, 0), Point(1, 1)),
...              Segment(Point(0, 1), Point(1, 0)))
True

Vertical line against horizontal line:

>>> do_intersect(Segment(Point(0, 0), Point(0, 2)),
...              Segment(Point(1, 1), Point(-1, 1)))
True

Horizontal line against vertical line:

>>> do_intersect(Segment(Point(0, 0), Point(2, 0)),
...              Segment(Point(1, 1), Point(1, -1)))
True

Colinear lines:

>>> do_intersect(Segment(Point(0, 0), Point(2, 0)),
...              Segment(Point(1, 0), Point(3, 0)))
True
>>> do_intersect(Segment(Point(0, 0), Point(2, 0)),
...              Segment(Point(-1, 0), Point(1, 0)))
True
>>> do_intersect(Segment(Point(0, 0), Point(1, 0)),
...              Segment(Point(-1, 0), Point(2, 0)))
True
>>> do_intersect(Segment(Point(0, 0), Point(1, 0)),
...              Segment(Point(2, 0), Point(3, 0)))
False
>>> do_intersect(Segment(Point(0, 0), Point(2, 2)),
...              Segment(Point(1, 1), Point(3, 3)))
True
>>> do_intersect(Segment(Point(0, 0), Point(0, 2)),
...              Segment(Point(0, 1), Point(0, 3)))
True

Intersection at segment vertices:

>>> do_intersect(Segment(Point(0, 0), Point(2, 0)),
...              Segment(Point(1, 0), Point(1, 2)))
True
"""
o1 = orientation(segment1.p1, segment1.p2, segment2.p1)
o2 = orientation(segment1.p1, segment1.p2, segment2.p2)

o3 = orientation(segment2.p1, segment2.p2, segment1.p1)
o4 = orientation(segment2.p1, segment2.p2, segment1.p2)

# TODO: This is technically unnecessary and can be ORed on
if o1 == o2 == Orientation.COLINEAR:
return any([
is_point_on_segment(segment1, segment2.p1),
is_point_on_segment(segment1, segment2.p2),
is_point_on_segment(segment2, segment1.p1),
is_point_on_segment(segment2, segment1.p2),
])
else:
return o1 != o2 and o3 != o4

# Nick had an interesting solution to this- which is calculate where the lines
# would intersect, and see if that point is on both lines.


# 5   Tessellation

A tessellation is a shape that repeats to form a pattern. Three basic shapes tessellate: triangles, squares, and hexagons.

# 6   History

Thales brought the science of geometry to Greece from Egypt_. The Egyptians knew only rules of thumb of geometry and there is no reason to believe that Thales arrived at deductive proofs such as later Greeks discovered. He seemed to have discovered how to calculate the distance of a ship at sea from observations taken at two points on land, and how to estimate the height of a pyramid from the length of its shadow. [1]

Little is known of Euclid's life except that he taught at Alexandria in Egypt. Proclus, the last major Greek philosopher, who lived around 450 AD wrote

Not much younger than these [pupils of Plato] is Euclid, who put together the "Elements", arranging in order many of Eudoxus's theorems, perfecting many of Theaetetus's, and also bringing to irrefutable demonstration the things which had been only loosely proved by his predecessors. This man lived in the time of the first Ptolemy; for Archimedes, who followed closely upon the first Ptolemy makes mention of Euclid, and further they say that Ptolemy once asked him if there were a shorted way to study geometry than the Elements, to which he replied that there was no royal road to geometry. He is therefore younger than Plato's circle, but older than Eratosthenes and Archimedes; for these were contemporaries, as Eratosthenes somewhere says. In his aim he was a Platonist, being in sympathy with this philosophy, whence he made the end of the whole "Elements" the construction of the so-called Platonic figures.

The second type of information is that Euclid was born at Megara. This is due to an error on the part of the authors who first gave this information. In fact there was a Euclid of Megara, who was a philosopher who lived about 100 years before the mathematician Euclid of Alexandria. It is not quite the coincidence that it might seem that there were two learned men called Euclid. In fact Euclid was a very common name around this period and this is one further complication that makes it difficult to discover information concerning Euclid of Alexandria since there are references to numerous men called Euclid in the literature of this period.

Euclid's most famous work is his treatise on mathematics The Elements. The book was a compilation of knowledge that became the centre of mathematical teaching for 2000 years. Probably no results in The Elements were first proved by Euclid but the organisation of the material and its exposition are certainly due to him.

The Elements begins with definitions and five postulates. The first three postulates are postulates of construction, for example the first postulate states that it is possible to draw a straight line between any two points. These postulates also implicitly assume the existence of points, lines and circles and then the existence of other geometric objects are deduced from the fact that these exist. There are other assumptions in the postulates which are not explicit. For example it is assumed that there is a unique line joining any two points. Similarly postulates two and three, on producing straight lines and drawing circles, respectively, assume the uniqueness of the objects the possibility of whose construction is being postulated.

The fourth and fifth postulates are of a different nature. Postulate four states that all right angles are equal. This may seem "obvious" but it actually assumes that space in homogeneous - by this we mean that a figure will be independent of the position in space in which it is placed. The famous fifth, or parallel, postulate states that one and only one line can be drawn through a point parallel to a given line. Euclid's decision to make this a postulate led to Euclidean geometry. It was not until the 19th century that this postulate was dropped and non-euclidean geometries were studied.

Zeno of Sidon, about 250 years after Euclid wrote the Elements, seems to have been the first to show that Euclid's propositions were not deduced from the postulates and axioms alone, and Euclid does make other subtle assumptions.

The Elements is divided into 13 books. Books one to six deal with plane geometry. In particular books one and two set out basic properties of triangles, parallels, parallelograms, rectangles and squares. Book three studies properties of the circle while book four deals with problems about circles and is thought largely to set out work of the followers of Pythagoras. Book five lays out the work of Eudoxus on proportion applied to commensurable and incommensurable magnitudes. Book six looks at applications of the results of book five to plane geometry.

Books seven to nine deal with number theory. In particular book seven is a self-contained introduction to number theory and contains the Euclidean algorithm for finding the greatest common divisor of two numbers. Book eight looks at numbers in geometrical progression. Book ten deals with the theory of irrational numbers and is mainly the work of Theaetetus. Euclid changed the proofs of several theorems in this book so that they fitted the new definition of proportion given by Eudoxus.

Books eleven to thirteen deal with three-dimensional geometry. In book eleven the basic definitions needed for the three books together are given. The theorems then follow a fairly similar pattern to the two-dimensional analogues previously given in books one and four. The main results of book twelve are that circles are to one another as the squares of their diameters and that spheres are to each other as the cubes of their diameters. These results are certainly due to Eudoxus. Euclid proves these theorems using the "method of exhaustion" as invented by Eudoxus. The Elements ends with book thirteen which discusses the properties of the five regular polyhedra and gives a proof that there are precisely five. This book appears to be based largely on an earlier treatise by Theaetetus.

Euclid's Elements is remarkable for the clarity with which the theorems are stated and proved. The standard of rigour was to become a goal for the inventors of the calculus centuries later.

http://www-groups.dcs.st-and.ac.uk/~history/Biographies/Euclid.html

Euclid also wrote the following books which have survived: Data (with 94 propositions), which looks at what properties of figures can be deduced when other properties are given; On Divisions which looks at constructions to divide a figure into two parts with areas of given ratio; Optics which is the first Greek work on perspective; and Phaenomena which is an elementary introduction to mathematical astronomy and gives results on the times stars in certain positions will rise and set. Euclid's following books have all been lost: Surface Loci (two books), Porisms (a three book work with, according to Pappus, 171 theorems and 38 lemmas), Conics (four books), Book of Fallacies and Elements of Music.

A classic problem in geometry is squaring the circle: the challenge of constructing a square with the same area as a given circle using only a finite number of steps with a compass and straightedge. In 1882, the task was proven impossible.

The sage Thales, sometime prior to 550 BCE, set out to develop geometry as an abstract discipline. It is generally believed that he was the first to do so; he is the first we know of to do it.

If you read the books of someone like Archimedes (287-212 BC), they're basically just collections of geometric proofs, yet they're proofs designed to talk about the natural world.

If we skip forward quite a bit and start looking at someone like Galileo (1564-1642), we see essentially the same tradition, albeit in a significantly more reader friendly version. His final book, Discourses and Mathematical Demonstrations Relating to Two New Sciences (1638) focuses on physics and it's structured exactly as its title suggests. The book focuses on three men who are having a conversation about a variety of topics concerning matter and motion. The men talk for a while, argue back and forth, and then eventually one of them (usually Salviati, who is Galileo's mouthpiece) will say "and here our learned friend has clearly demonstrated this, as we will now show", and the text will become a series of mathematical proofs.

Geometry was still in use up to Issac Newton' Principia which was written in the language of geometry, not calculus.

## 6.1   Geometry

The Greeks of Pythagoras's time had a solid understanding of geometry, although it wouldn't be for another few hundred years that Euclid formalized the science with his five postulates.

The ancient Greeks thought of all mathematics as being a branch of geometry. This can be seen in Euclid's Elements, where, for example, the Pythagorean theorem is purely a theorem of geometry.

While Euclid is responsible for putting Elements together, it's likely that much of the content (e.g., proofs of theorems) was taken from what other people had done before him. So in ~300 BCE when Euclid was doing his thing, Pythagorus' work was already in hand.

Euclid's Elements would become a best-selling work, second only to the bible in printed editions, and used until recently as the standard text for mathematics classes.

Nearly a century later, Lincoln had found his own way to Euclid. While working as a lawyer on the Illinois circuit during the early 1850s, he carried Euclid’s texts in his saddlebag. One time, his colleague William Herndon entered their shared office in Springfield to find Lincoln was surveying a vast canvas of diagrams. Lincoln was so taken with the shapes on the thick paper sheets that he barely acknowledged Herndon as he walked in. Bottles of ink lay scattered on the table, alongside pencils, a compass, a ruler, and a large pile of fresh paper—the results of a fruitless effort to “square the circle,” a classic Euclidean puzzle which involves drawing a square and a circle of equal area.

In the early 20th century, researchers tried to tackle the growing number of paradoxes by building a set of complete, consistent axioms, from which all mathematical theories could be derived. Unfortunately, Kurt Gödel’s 1931 incompleteness theorems showed this aim to be impossible. He proved that no matter how detailed the axioms, there were always some situations that they would not cover. Gödel’s work demonstrated the limitations of axiomatic systems: Mathematics could not be both complete and consistent. Axioms were simply not enough.

## 6.2   Archimedes

Archimedes showed that the sphere and the cone on one side of the fulcrum balance the cylinder on the other side. Because the formulas for the volumes of cones and cylinders were known before his time, this balancing scheme allowed him to deduce the previously unknown formula for the volume of a sphere. Archimedes summarized his result by stating that the volume of a sphere is two thirds the volume of a cylinder that contains it. Archimedes was so proud of this result that he had a diagram of a cylinder containing a sphere inscribed on his tombstone.

## 6.3   Descartes

In Euclid's system, geometric ideas were represented as spatial diagrams. Geometry continued to be practiced by representing ideas as spatial diagrams until the 1630s, when Rene Descartes showed that geometry could be represented as formulas. This shifted the dominant mode of mathematics from diagrams to formulas, leading to, among other things, the development of calculus, invented roughly 30 years after Descartes, independently, by Issac Newton and Gottfried Leibniz.