C points forming a rectangle

I have this piece of code for finding out whether 4 x,y coordinates make a rectangle which works perfectly well, but, I need to make it so that it only works if the points are entered in the correct order, ie: Point #1: 0 0 Point #2: 20 0 Point #3: 20 50 Point #4: 0 50 would say "Is a rectangle" but: Point #1: 0 0 Point #2: 20 0 Point #3: 0 50 Point #4: 20 50 Would say "Is not a rectangle" (because the points arent in the right order)

This is what i have:

1
2
3
4
5
6
7
8
9
  static bool IsRectangle(float x1, float y1, float x2, float y2,
                       float x3, float y3, float x4, float y4)
    {
    x2 -= x1; x3 -= x1; x4 -= x1; y2 -= y1; y3 -= y1; y4 -= y1;
    return
    (x2 + x3 == x4 && y2 + y3 == y4 && x2 * x3 == -y2 * y3) ||
    (x2 + x4 == x3 && y2 + y4 == y3 && x2 * x4 == -y2 * y4) ||
    (x3 + x4 == x2 && y3 + y4 == y2 && x3 * x4 == -y3 * y4);
    }


Im totally unsure as to how to limit it to only work in the correct order... :( Thank you
It sounds like you're defining "correct" order as counter-clockwise starting from the lower left. If that's true then x3>x1 and y3>y1. In other words, the point 3 is above and to the right of point 1. Also, once you know points 1 and 3, you know where points 2 and 4 should be, so you can check if they are where they should be.
Topic archived. No new replies allowed.