使用标准绘图填充Dr.Java中的三角形

时间:2014-04-06 21:47:18

标签: java geometry drawing

所以我有这个程序,我必须画一个尺码均匀的铁锹,棍棒,心形和钻石。我完成了形状,但无法弄清楚如何填充用于铲子和球杆的三角形。非常感谢任何帮助!

唯一问题:填充三角形。

    public class CardSymbols
    { //beginning program
      public static void main(String[] args)
       { //beginning method
         StdDraw.setXscale(-1.5, +1.5);
         StdDraw.setYscale(-1.5, +1.5);

         //Drawing a Heart
        StdDraw.setPenColor(StdDraw.RED);//color for Heart & Diamond
        double[] xh = {.6,.7,.8,.7};
        double[] yh = {-.725,-.825,-.725,-.625};;
        StdDraw.filledPolygon(xh, yh); //diamond
        StdDraw.filledCircle(+.65, -.675, .1 / Math.sqrt(2)); //half circles
        StdDraw.filledCircle(.75, -.675, .1 / Math.sqrt(2)); //half circles


        //Drawing a Diamond
        double[] xd = {.6,.7,.8,.7};
        double[] yd = {.775,.9,.775,.65};
        StdDraw.filledPolygon(xd,yd);

        //Drawing a Spade
        StdDraw.setPenColor(StdDraw.BLACK);
        double[] xs = {-.6,-.7,-.8,-.7};
        double[] ys = {-.7,-.8,-.7,-.6};
        StdDraw.filledPolygon(xs,ys); //diamond
        StdDraw.filledCircle(-0.75, -0.75,.1 / 1.4142); //half circle
        StdDraw.filledCircle(-0.65, -0.75,.1 / 1.4142); //half circle
        StdDraw.line(-0.7,-0.8, -.75,-.85); 
        StdDraw.line(-0.7,-0.8,-.65,-.85);   //forming a triangle
        StdDraw.line(-0.75,-0.85,-.65,-.85); 


        //Drawing a Club
       StdDraw.filledCircle(-0.75, 0.75,.1 / 1.4142); //half circle
       StdDraw.filledCircle(-0.65, 0.75,.1 / 1.4142); //half circle
       StdDraw.filledCircle(-0.7, 0.835,.1 / 1.4142); //half circle
       StdDraw.line(-0.7,0.7, -.75,.65); 
       StdDraw.line(-0.75,0.65,-.65,.65); //forming a triangle
       StdDraw.line(-0.65,0.65,-.7,.7); 
      } //end method
     } //end program

1 个答案:

答案 0 :(得分:0)

在线发现stdDraw。这应该做你需要的。关键是要了解coords的顺序很重要。例如,xc[1]y[1]组成一个点,依此类推。

//club
double[] xc = {-.7,-.75,-.65};
double[] yc = {.7,.65,.65};
StdDraw.filledPolygon(xc,yc);

//spade
double[] xs1 = {-.7,-.75,-.65};
double[] ys1 = {-.8,-.85,-.85};
StdDraw.filledPolygon(xs1,ys1);