public class Test {
public static void rect2lozenge(double x1, double y1, double x2, double y2, int angle)
{
double newx1, newy1, newx2, newy2, newx3, newy3, newx4, newy4;
double xx11;
double yy11;
double r = Math.sqrt((x2-x1)/2*(x2-x1)/2 + (y2-y1)*(y2-y1));
double rad = Math.toRadians(angle);
newx1 = (x2+x1)/2 + r*Math.cos(rad);
newy1 = y1 + r*Math.sin(rad);
xx11 = (y2-y1)*Math.sin(rad);
yy11 = (y2-y1)*Math.cos(rad);
newx2 = newx1 - xx11;
newy2 = newy1 + yy11;
newx4 = (x2+x1)/2 - r*Math.cos(rad);
newy4 = y1 - r*Math.sin(rad);
newx3 = newx4 - xx11;
newy3 = newy4 + yy11;
System.out.println("rad: " + rad);
System.out.println("xx11: " + xx11 + ", yy11: " + yy11);
System.out.println("newx1: " + newx1 + ", newy1: " + newy1 +
"newx2: " + newx2 + ", newy2: " + newy2 +
"\nnewx3: " + newx3 + ", newy3: " + newy3 +
"newx4: " + newx4 + ", newy4: " + newy4);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
double x1, x2, y1, y2;
x1 = -10;
x2 = +10;
y1 = 0;
y2 = +2;
System.out.println("x1: " + x1 + ", y1: " + y1 + ", x2: " + x2 + ", y2: " + y2);
rect2lozenge(x1, y1, x2, y2, 45);
}
}