Calculate third point of equilateral triangle
Given two point how do you calculate the third point which will make an equilateral triangle. This is the code i have.
publicclass Equilateral
{
publicstaticvoid main(String[]args)
{
EasyReader in =new EasyReader();
System.out.print("x1 : ");
double x1 = in.readDouble();
System.out.print("y1 : ");
double y1 = in.readDouble();
System.out.print("x2 : ");
double x2 = in.readDouble();
System.out.print("y2 : ");
double y2 = in.readDouble();
double xs = Math.pow((x2-x1),2);
double ys = Math.pow((y2-y1),2);
double d1 = Math.sqrt(xs+ys);////distance of base
double midpointX = (x1+x2)/2;
double midpointY = (y1+y2)/2;///midpoint of base
double DHBX = Math.pow((x2-midpointX),2);
double DHBY = Math.pow((x2-midpointY),2);
double DHB = Math.sqrt(DHBX+DHBY);////distance of half base
double height = DHB*(Math.sqrt(3));
}
}
[1905 byte] By [
FrancoNa] at [2007-10-3 5:26:13]

ok so this is my code now and it doesn't seem to print out the correct points
public class Equilateral
{
double x1, x2, x3, x4, y1, y2, y3, y4, xs, ys, d1, midpointX, midpointY, DHBX, DHBY, DHB, height, perpenSlope, slopeBase, b, A, B, C;
public Equilateral()
{
EasyReader in = new EasyReader();
System.out.print("x1 : ");
x1 = in.readDouble();
System.out.print("y1 : ");
y1 = in.readDouble();
System.out.print("x2 : ");
x2 = in.readDouble();
System.out.print("y2 : ");
y2 = in.readDouble();
xs = Math.pow((x2-x1),2);
ys = Math.pow((y2-y1),2);
d1 = Math.sqrt(xs+ys);////distance of base
midpointX = (x1+x2)/2;
midpointY = (y1+y2)/2;///midpoint of base
DHBX = Math.pow((x2-midpointX),2);
DHBY = Math.pow((x2-midpointY),2);
DHB = Math.sqrt(DHBX+DHBY);////distance of half base
height = (DHB/2)*(Math.sqrt(3));
slopeBase = ((y1-y2)/(x1-x2));
if(slopeBase == 0)
{
x3 = midpointX;
y3 = height + y1;
}
else
{
perpenSlope = -(1/slopeBase);
b = perpenSlope*(-1*midpointX)+midpointY;
A = 1 + Math.pow(perpenSlope,2);
B = -2*midpointX + 2*perpenSlope*b - 2*perpenSlope*midpointY;
C = Math.pow(midpointX,2) + Math.pow(b,2) - 2*b*midpointY + Math.pow(midpointY,2) - Math.pow(height,2);
x3 = ((-(B))+Math.sqrt(Math.pow(B,2)-(4*A*C)))/(2*A);
y3 = perpenSlope*x3 + b;
x4 = ((-(B))-Math.sqrt(Math.pow(B,2)-(4*A*C)))/(2*A);
y4 = perpenSlope*x4 + b;
}
System.out.println("Point 1 : ("+x3+", "+y3+")");
System.out.println("Point 2 : ("+x4+", "+y4+")");
}
}