3

Suppose you're given coordinates of four points $x_1,x_2,x_3,x_4$ , given the fact that the points lie in a plane and polygon is convex. Figure out the shape formed by these four.

So, in a 'brute force' way I have two methods. One is sketching the points in space and the second is to figure out the angles and lengths to classify if it is a parallelogram, square etc.

Are there any other faster algorithms / alternate methods to quickly figure out the shape formed by these points?

Allowed shapes:

  1. Parellogram
  2. Rhombus
  3. Rectangle
  4. Square
  5. Trapezoid

3 Answers3

1

If you know that the points occur along the perimeter of the quadrilateral in the sequence $x_1,$ $x_2,$ $x_3,$ $x_4$ (clockwise or counterclockwise does not matter), then define the vectors

\begin{align} \mathbf a &= x_2 - x_1, \\ \mathbf b &= x_3 - x_2, \\ \mathbf c &= x_4 - x_3, \\ \mathbf d &= x_1 - x_4. \end{align}

Suppose you have written each vector in two-dimensional Cartesian coordinates. Let's denote these coordinates by subscripts $x$ and $y$, that is, $u_x$ and $u_y$ are the first and second coordinates of the vector $\mathbf u.$ Define the "dot" product of two vectors $\mathbf u$ and $\mathbf v$ by

$$\mathbf u \cdot \mathbf v = u_xv_x + u_yv_y $$

and the "cross" product of two vectors $\mathbf u$ and $\mathbf v$ by

$$\mathbf u \times \mathbf v = u_xv_y - u_yv_x. $$

(The "cross" product is the dot product of $\mathbf u$ with a vector of the same length as $\mathbf v$ in a direction $90$ degrees from the direction of $\mathbf v$.)

Then $\mathbf a,$ $\mathbf b,$ $\mathbf c,$ and $\mathbf d$ give the distance and direction you travel along each edge of the quadrilateral as you make one full circuit around the perimeter.

If $\mathbf a \times \mathbf c = 0$ then the two opposite sides represented by $\mathbf a$ and $\mathbf c$ are parallel. If $\mathbf b \times \mathbf d = 0$ then the two opposite sides represented by $\mathbf b$ and $\mathbf d$ are parallel.

If neither pair is parallel, you have an unclassified quadrilateral.

If one pair is parallel and the other is not, you have a trapezoid.

If both pairs are parallel you have some variety of parallelogram (using the definition of "parallelogram" in which rectangles and rhombi are parallelograms), which you can further classify using the following criteria:

If $\mathbf a \cdot \mathbf b = 0$ then the two adjacent sides represented by $\mathbf a$ and $\mathbf b$ are perpendicular. Otherwise they are not perpendicular.

If $\mathbf a \cdot \mathbf a = \mathbf b \cdot \mathbf b$ then the two sides are equal in length. Otherwise they are unequal in length.

Using those facts, you can decide whether the shape is a square, a non-square rhombus, a non-square rectangle, or a parallelogram that is neither a rectangle nor a rhombus.


If you have two-dimensional Cartesian coordinates for all points but do not know the sequence in which the given points appear around the quadrilateral, then make a guess that they have been presented in some cyclic sequence (either clockwise or counterclockwise without skipping). Define the vectors $\mathbf a,$ $\mathbf b,$ $\mathbf c,$ and $\mathbf d$ as at the start of this answer.

Compute $\mathbf a \times \mathbf b,$ $\mathbf b \times \mathbf c,$ and $\mathbf c \times \mathbf d.$ If the answers all have the same sign, the points are in cyclic order and you can simply continue as described above. Otherwise you will have to swap two points.

If $\mathbf a \times \mathbf b$ and $\mathbf b \times \mathbf c$ have opposite signs, you can swap the labels of the two endpoints of $\mathbf a$ or $\mathbf c$. If $\mathbf b \times \mathbf c$ and $\mathbf c \times \mathbf d$ have opposite signs, you can swap the labels of the two endpoints of $\mathbf b$ or $\mathbf d$. (But don't swap two pairs of points!)


If you are not guaranteed that the four points are vertices of a non-trivial convex quadrilateral then you need some additional tests to ensure that no point is on or inside the triangle formed by the other three.

David K
  • 98,388
0

With four given points a parabola passing through them can be uniquely defined numerically by means of its equation:

$$ y = ax+b +\sqrt{ cd+d} $$

Negative sign produces same parabola beyond "nose" $N$ with infinite slope.

enter image description here

Narasimham
  • 40,495
0

Let A, B, C & D be the four given points in a plane. Then the quadrilateral will be :

(a) Square if $A B=B C=C D=D A \& A C=B D$

(b) Rhombus if $A B=B C=C D=D A$ and $A C \neq B D$

(c) Parallelogram if $A B=D C, B C=A D ; A C \neq B D$

(d) Rectangle if $A B=C D, B C=D A, A C=B D$