zoukankan      html  css  js  c++  java
  • 绘制指定半径的圆

    package day01;
    
    /**
     * Created by sherry on 000019/3/19 13:55.
     */
    
    /*直角坐标*/
    class Coord{
        /*横坐标*/
        private int i;
        /*纵坐标*/
        private int j;
    
        /*两个坐标之间的距离(坐标值必须都是正数)*/
        public double getRange(Coord coord){
            return Math.sqrt(Math.pow(Math.abs(this.i-coord.getI()),2)+Math.pow(Math.abs(this.j-coord.getJ()),2));
        }
    
        @Override
        public String toString() {
            return "Coord{" +
                    "i=" + i +
                    ", j=" + j +
                    '}';
        }
    
        @Override
        public boolean equals(Object o) {
            if (o == null){
                return false;
            }
            Coord coord = (Coord) o;
            if (this.i == coord.getI()
                    &&this.j == coord.getJ()){
                return true;
            }else {
                return false;
            }
        }
    
        @Override
        public int hashCode() {
            int result = i;
            result = 31 * result + j;
            return result;
        }
    
        public Coord(int i, int j) {
            this.i = i;
            this.j = j;
        }
    
        public int getI() {
            return i;
        }
    
        public void setI(int i) {
            this.i = i;
        }
    
        public int getJ() {
            return j;
        }
    
        public void setJ(int j) {
            this.j = j;
        }
    }
    public class DrawCircle {
        public static void main(String[] args) {
            drawCircle(20);
        }
    
        private static void drawCircle(int r) {
            /*边框长度*/
            int d = 2*r+1;
            /*圆心坐标*/
            Coord centerOfCircle = new Coord(r,r);
    
            /*任意一点坐标*/
            Coord coord;
            for (int i = 0;i < d;i++){
                for (int j = 0;j < d;j++){
                    coord = new Coord(j,i);
                    if (coord.equals(centerOfCircle)){
                        System.out.print("A ");
                    } else if (Math.abs(coord.getRange(centerOfCircle)-r)<0.5){
                        System.out.print("B ");
                    } else {
                        System.out.print("* ");
                    }
                }
                System.out.println();
            }
        }
    }
  • 相关阅读:
    协方差矩阵
    SLAM中的关键帧是什么?有什么用?如何选择关键帧?
    EKF算法与非线性优化算法的比较
    LC217 存在重复元素
    LC42 接雨水
    LC20 有效的括号
    LC3 无重复最长子串
    LC4 寻找两个有序数组的中位数
    ubuntu16.04下安装g2o
    小米 各版本手机系统包 线刷包 卡刷包
  • 原文地址:https://www.cnblogs.com/sherrykid/p/4573895.html
Copyright © 2011-2022 走看看