Java 怎么绘制阻力圆

2019年8月20日22:38:24 评论 22

1.简介

Java 怎么绘制阻力圆?——请看下文。

2.代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */


import java.awt.Color;
import java.awt.Graphics;

public class Main {

    public static void drawResistanceCircle(Graphics g, int x, int y) {
        g.setColor(Color.RED);
        int r = (int) ((double) x * x + y * y - 800 * x - 400 * y + 200000)
                / (800 - 2 * x);
        int tmp_x = 400 - r;
        int tmp_y = 200;
        drawCircleThroughCenter(g, tmp_x, tmp_y, r);
    }

    public static void drawCircleThroughCenter(Graphics g, int x, int y,
            int r) {
        int tmp_x = x - r;
        int tmp_y = y - r;
        int tmp_width = 2 * r;
        int tmp_height = 2 * r;
        g.drawOval(tmp_x, tmp_y, tmp_width, tmp_height);
    }
}

 

3.总结

示例代码演示了 Java 怎么绘制阻力圆,具体步骤参见示例代码。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: