Checking whether 4 points in the plane define a square?

how to check if 4 points in a plane define a square? that the function that sets the point and the square area value as input parameters returns four squares (determine the corresponding type) with sides parallel to the x axis and y axis

this is how i start:

#include <stdio.h>
#include<math.h>
struct point{
float x;
float y;
}
typedef struct point POINT;
struct square{
struct point p1;
struct point p2;
struct point p3;
struct point p4;
}
typedef struct square SQUARE;

int main()
{
int point;
printf("point coordinate");
printf("\n\n");

printf("enter data\n");
+3
source share
3 answers

Calculate all 6 squares of the distances between each pair of points. I.e:

(x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)

Sort them.
The four smallest of them should be (approximately) equal, and the two larger should be (approximately) twice as large.

Do you need a measure of “how square is square”?

+4
source
  • p1 , .. -p1.
  • p2 - , p1. ( .).
  • p1 p2, -. p1 p2 ( , 0 ).
  • , p3 p4 y ( ).
  • , p3 p4 x p1 p2 ( ).
+1

, - . , :

  • X, Y

  • / ( , , , )

, 1.

(Note that this answer assumes that you are testing a square that is in the same orientation as the X / Y axis - if the square can be rotated and then an arbitrary angle, then it gets a little more complicated.)

0
source

Source: https://habr.com/ru/post/1742577/


All Articles