V
V
Victor Berdyansky2017-06-01 20:18:56
Mathematics
Victor Berdyansky, 2017-06-01 20:18:56

Given 4 consecutive points, how do you know what they form a parallelogram?

I found the length of the sides and compare them, now I am writing a code to calculate the sum of the angles adjacent to one side (= 180g.).
I would also like to consult for additional checks, I apologize in advance for poor knowledge of geometry

#include <stdio.h>
#include <math.h>
#include <locale.h>

struct point_data {
  float x;
  float y;
};

int main()
{	
  struct point_data point[4];

  point[0].x = 0;
  point[0].y = 0;
  
  point[1].x = 4;
  point[1].y = 3;
  
  point[2].x = 4;
  point[2].y = 2;
  
  point[3].x = 3;
  point[3].y = 0;
  
  float a, b, c, d;
  
  a = sqrt(pow(point[1].x - point[0].x, 2) + pow(point[1].y - point[0].y, 2));
  b = sqrt(pow(point[2].x - point[1].x, 2) + pow(point[2].y - point[1].y, 2));
  c = sqrt(pow(point[3].x - point[2].x, 2) + pow(point[3].y - point[2].y, 2));
  d = sqrt(pow(point[0].x - point[3].x, 2) + pow(point[0].y - point[3].y, 2));
        //Пока что только один угол
        float lp = point[0].x * point[1].x + point[0].y * point[1].y;
  a = sqrt(pow(point[0].x, 2) + pow(point[0].y, 2));
  b = sqrt(pow(point[1].x, 2) + pow(point[1].y, 2));
  printf("%f", lp/(a*b));

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Armenian Radio, 2017-06-01
@gbg

It is most reliable to look at pairs of sides for parallelism.
That is, if you just have 4 points, in no particular order, you take all pairs of pairs and check if there are any parallel lines among them.
To check for parallelism, you need to
1) find the direction vectors of each side (subtract the coordinates of the beginning from the end coordinates)
2) normalize these vectors (divide each of the coordinates by the length)
3) compare the coordinate-wise obtained pairs. If the coordinates are close, then the given sides are parallel.

M
Mercury13, 2017-06-01
@Mercury13

Well, of course, according to the criterion of a parallelogram: the diagonals intersect and the intersection point is divided in half! In the language of mathematics:
x1 + x3 ≈ x2 + x4
y1 + y3 ≈ y2 + y4
Why is “approximately equal”. Float is in principle inaccurate, the coincidence has to be checked with an accuracy of some epsilon. What epsilon - it already depends on the task.

P
pestilent, 2017-06-07
@pestilent

If the points must form a parallelogram exactly in the order they are given (eg A, B, C, D) and a degenerate parallelogram is allowed, simply compare the vectors AB and DC. To exclude the degenerate case, we check the vectors of neighboring sides for proportionality. If the vertices can go in any order, a small enumeration of options is needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question