Problem Statement
A parallelogram is a quadrilateral with two sets of parallel sides.
You are given three distinct points A(xA,yA), B(xB,yB) and C(xC,yC) in the plane.
Consider all non-degenerate parallelograms such that A, B, and C are three of its vertices. Your method should return the difference between the largest and the smallest possible perimeter of such a parallelogram. If there is no such parallelogram, return -1 instead.
Definition
- Class:
- Parallelograms
- Method:
- getDifference
- Parameters:
- int, int, int, int, int, int
- Returns:
- double
- Method signature:
- double getDifference(int xA, int yA, int xB, int yB, int xC, int yC)
- (be sure your method is public)
Constraints
- xA, yA, xB, yB, xC and yC will be between -5,000 and 5,000, inclusive.
- A, B, and C will be three different points.
Examples
0
0
0
1
1
0
Returns: 0.8284271247461898
For this input there are three possible parallelograms, with the fourth vertex at (1,1), (1,-1), or (-1,1). In the first case, we get a 1 by 1 square with a perimeter of 4. In both the second and third cases, we get a parallelogram with side lengths 1 and sqrt(2), with a perimeter of approximately 4.828427.0
0
4
0
0
3
Returns: 4.0
In this case the largest possible perimeter is 18 and the smallest possible perimeter is 14.0
0
1
0
47
0
Returns: -1.0
No parallelogram can have three vertices on the same line. Therefore, the answer for this test case is -1.1
2
3
4
8
7
Returns: 11.547796284592874
2
-1
-7
2
-1
0
Returns: -1.0
One more example of three points on the same line.