How can I draw an equilateral triangle using the graphics method especially the draw polygon method. My issue is that to make an equilateral triangle I need the square root 3/2 and the drawPolygon method I can only use int[],int[],int, the compiler will not let me double because it differ in lengh.
Any help is appreciated.
import java.awt.*;
public class Triangle extends Shape {
// Instance variables
private int leng;
// Constructor
public Triangle(int x, int y, Color color,
int leng) {
super(x, y, color);
this.leng=leng;
}
// Instance methods
public void draw(Graphics g) {
double[] Xcoord = { getX(), getX() + leng, getX() + leng / 2};
double[] Ycoord = { getY(), getY(), getY()*(1.0+ Math.sqrt(3) / (2.0))};
g.drawPolygon(Xcoord,Ycoord,3);
}
public int getHeight() {
return leng;
}
public int getWidth() {
return leng;
}
}