## find if 4 points on a plane form a rectangle?

show that the 4 points form a square

find smallest rectangle in set of points

check if a rectangle is inside another rectangle python

how to check rectangle

maximum rectangle to fit list of given points on coordinate system

check if point is inside rectangle

find all overlapping rectangles

Can somebody please show me in C-style pseudocode how to write a function (represent the points however you like) that returns true if 4-points (args to the function) form a rectangle, and false otherwise?

I came up with a solution that first tries to find 2 distinct pairs of points with equal x-value, then does this for the y-axis. But the code is rather long. Just curious to see what others come up with.

**How to Check if Given Four Points Form a Rectangle,** How do you check if given four points form a rectangle? Given coordinates of four points in a plane, find if the four points form a square or not. To check for square, we need to check for following. a) All fours sides formed by points are the same. b) The angle between any two sides is 90 degree. (This condition is required as Quadrilateral also has same sides.

struct point { int x, y; } // tests if angle abc is a right angle int IsOrthogonal(point a, point b, point c) { return (b.x - a.x) * (b.x - c.x) + (b.y - a.y) * (b.y - c.y) == 0; } int IsRectangle(point a, point b, point c, point d) { return IsOrthogonal(a, b, c) && IsOrthogonal(b, c, d) && IsOrthogonal(c, d, a); }

If the order is not known in advance, we need a slightly more complicated check:

int IsRectangleAnyOrder(point a, point b, point c, point d) { return IsRectangle(a, b, c, d) || IsRectangle(b, c, a, d) || IsRectangle(c, a, b, d); }

**How do I show that the points and are the vertices of a rectangle and ,** How do you show points are vertices of a rectangle? Given four points of a rectangle, and one more point P. Write a function to check whether P lies within the given rectangle or not. Approach : Let the coordinates of four corners be A (x1, y1), B (x2, y2), C (x3, y3) and D (x4, y4). And coordinates of the given point P be (x, y) 1) Calculate area of the given rectangle, i.e., area of the

**Find Out Things About Rectangles,** How do you determine if a shape is a rectangle? 1. Orthogonal Rectangles [math]\theta(n^2)[/math] (this is my original solution, which assumed orthogonal rectangles with sides parallel to the x and y axis) Here is a good approach in two very easy steps (might not be the best performing solution

The distance from one point to the other 3 should form a right triangle:

| / /| | / / | | / / | |/___ /___|

d1 = sqrt( (x2-x1)^2 + (y2-y1)^2 ) d2 = sqrt( (x3-x1)^2 + (y3-y1)^2 ) d3 = sqrt( (x4-x1)^2 + (y4-y1)^2 ) if d1^2 == d2^2 + d3^2 then it's a rectangle

Simplifying:

d1 = (x2-x1)^2 + (y2-y1)^2 d2 = (x3-x1)^2 + (y3-y1)^2 d3 = (x4-x1)^2 + (y4-y1)^2 if d1 == d2+d3 or d2 == d1+d3 or d3 == d1+d2 then return true

**Check if four segments form a rectangle,** First, we check total unique end points of segments, if count of these points is not equal to 4 then the line segment can't make a rectangle. Then we check A quadrilateral where all interior angles are 90°, and whose location on the coordinate plane is determined by the coordinates of the four vertices (corners). Try this Drag any vertex of the rectangle below. It will remain a rectangle and its dimensions calculated from its coordinates. You can also drag the origin point at (0,0).

If the points are A, B, C & D and you know the order then you calculate the vectors:

x=B-A, y=C-B, z=D-C and w=A-D

Then take the dot products (x dot y), (y dot z), (z dot w) and (w dot x). If they are all zero then you have a rectangle.

**How to check if given four points form a square,** Given coordinates of four points in a plane, find if the four points form a square or not. To check for square, A C++ program to check if four given points form a square or not. #include Check if four segments form a rectangle. This article is Other ways would include showing that the shape has 4 right angles. If you already know that the shape is a parallelogram, you will only have to show that one of the angles is a right angle and then it would follow that all of the angles are right angles. Example: Prove that the following four points will form a rectangle when connected in order.

**find if 4 points on a plane form a rectangle?,** (ii) Find the length of all sides. (iii) In a rectangle, the length of opposite sides will be equal. (iv) The rectangle can be divided into two right triangles. (v) If the given four vertices satisfies the conditions (iii) and (iv), we may decide that the given points form a rectangle. Assuming that your square might be rotated against whatever coordinates system you have in place, you can't rely on there being any repetition of X and Y values in your four points. What you can do is calculate the distances between each of the four points. If you find the following to be true, you have a square:

**How to determine if a set of points makes up a rectangle using the ,** if 4-points (args to the function) form a rectangle, and false otherwise? I came up with a solution that first tries to find 2 distinct pairs of points Given three of the vertices of a rectangle, can you find the fourth? If you're seeing this message, it means we're having trouble loading external resources on our website. If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

**From a given set of points, how would you find the set of 4 points ,** Learn how to determine the figure given four points. Some of the types of quadrilaterals Duration: 5:27
Posted: Jan 23, 2014 If you are given 4 vertices on a plane and asked if it is a rectangle, the 4 slopes must be opposite recipricals so would the points P (2,3) - Q (5,9) - R (11, 6) and S(8, 0) form a triangle? Please help

##### Comments

- You came up with the solution? Where is it? You can show it here and we can help you make it shorter and cleaner.
- Interresting question. I notice that your solution will only work if the rectangle is parallel with the axis.
- Gman - yes in any order. Milan - this was asked of me during an interview so I don't have my code (I dont necessarily need to see code..an algorithm would be great too!). Christian - good point about it having to be parallel with the axis.
- This is a clever solution. It basically finds the circumcircle of the "rectangle" and verifies that all four corners are lie on it.
- This is VERY inefficient. Use the dot product method provided by Vlad. Squareroots need hundrets of clock cycles. Also the dot product method is more numerically stable.
- @Axel & @Curd: Was the solution edited since it original posting? I don't see any square roots. I'm assuming
`sqr(x) == x*x`

which means`ddi`

is actually the square of the distance from`cx`

to`xi`

. This should be pretty darn fast. - Okay, then I need to appologize. I thought sqr stands for squareroot.
- Some considerations concerning performance: this solution takes 20 additions/subtractions/divisions by constant 4 and 8 multiplications. It even could be optimized to drop the remaining square distance calculations if the first or second comparison failed. So the numbers above are worst case. Even this worst case is as good as the best case and 3 times better than the worst case of the solution by Vlad.
- @Larry: your test is only for being a parallelogram
- @Larry: with checking diagonals it's correct now, but your test requires taking 6 square roots.
- @Timmy: in that case one needs to do a more complicated check:
`if (IsOrthogonal(a, b, c)) return IsRectangle(a, b, c, d); else if (IsOrthogonal(a, b, d)) return IsRectangle(a, b, d, c); else return false;`

- I modified the answer accordingly
- what if a and b is a diagonal?
- Worst case: 15 additions/subtractions, 6 multiplications.