Problem Statement
Create a class Morph that contains method coordSum that is given the 3 vertices of an original triangle, the 3 vertices of the morphed triangle, and a point P in the original triangle (possibly on its boundary) and that calculates where P ends up in the morphed triangle. It returns the sum of the x and y coordinates of P's final location.
The parameters are int[]s x and y giving the 3 vertices of the original triangle, int[]s newx and newy giving the 3 vertices of the morphed triangle, and ints px and py giving the coordinates of a point in the original triangle. The i-th element of x and y is to be morphed into the i-th element of newx and newy.
Definition
- Class:
- Morph
- Method:
- coordSum
- Parameters:
- int[], int[], int[], int[], int, int
- Returns:
- double
- Method signature:
- double coordSum(int[] x, int[] y, int[] newx, int[] newy, int px, int py)
- (be sure your method is public)
Notes
- If the return has either a relative or absolute error less than 1.0E-9 it is acceptable.
Constraints
- x, y, newx, and newy will each contain exactly 3 elements.
- All values (px, py, and each element of x, y, newx, and newy) will be between -1000 and 1000 inclusive.
- The points given by x,y will not be colinear.
- The points given by newx,newy will not be colinear.
- px,py will be contained in the (closed) triangle given by x and y.
Examples
{0,0,4}{0,3,0}{3,3,7}{1,4,1}2
0
Returns: 6.0
The first triangle is morphed onto the second by translation of 3 in the x direction and 1 in the y direction. So 2,0 ends up at 5,1 and the returned value is 5+1 = 6.{0,0,4}{0,3,0}{3,7,3}{1,1,4}2
0
Returns: 5.5
These are the same triangles as in the preceding example, but the vertices are mapped differently. The point 2,0 ends up at 3,2.5{0,0,4}{0,3,0}{3,7,3}{1,1,4}4
0
Returns: 7.0
The point 4,0 is the third vertex of the original triangle, so it is morphed to the third vertex of the new triangle which is 3,4.