久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <legend id='LYY7e'><style id='LYY7e'><dir id='LYY7e'><q id='LYY7e'></q></dir></style></legend>
  1. <tfoot id='LYY7e'></tfoot>
  2. <i id='LYY7e'><tr id='LYY7e'><dt id='LYY7e'><q id='LYY7e'><span id='LYY7e'><b id='LYY7e'><form id='LYY7e'><ins id='LYY7e'></ins><ul id='LYY7e'></ul><sub id='LYY7e'></sub></form><legend id='LYY7e'></legend><bdo id='LYY7e'><pre id='LYY7e'><center id='LYY7e'></center></pre></bdo></b><th id='LYY7e'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='LYY7e'><tfoot id='LYY7e'></tfoot><dl id='LYY7e'><fieldset id='LYY7e'></fieldset></dl></div>
      • <bdo id='LYY7e'></bdo><ul id='LYY7e'></ul>

      <small id='LYY7e'></small><noframes id='LYY7e'>

      如何在不小于或大于周長的情況下繪制圓的半徑

      How to draw the radius of a circle without it being shorter or larger than the circumference(如何在不小于或大于周長的情況下繪制圓的半徑)

          <bdo id='PD3FV'></bdo><ul id='PD3FV'></ul>

          <i id='PD3FV'><tr id='PD3FV'><dt id='PD3FV'><q id='PD3FV'><span id='PD3FV'><b id='PD3FV'><form id='PD3FV'><ins id='PD3FV'></ins><ul id='PD3FV'></ul><sub id='PD3FV'></sub></form><legend id='PD3FV'></legend><bdo id='PD3FV'><pre id='PD3FV'><center id='PD3FV'></center></pre></bdo></b><th id='PD3FV'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='PD3FV'><tfoot id='PD3FV'></tfoot><dl id='PD3FV'><fieldset id='PD3FV'></fieldset></dl></div>
          <tfoot id='PD3FV'></tfoot>

          • <small id='PD3FV'></small><noframes id='PD3FV'>

            1. <legend id='PD3FV'><style id='PD3FV'><dir id='PD3FV'><q id='PD3FV'></q></dir></style></legend>
                <tbody id='PD3FV'></tbody>
              • 本文介紹了如何在不小于或大于周長的情況下繪制圓的半徑的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在開發一個程序,我想在其中畫一條從圓心到其參數點的線.但它在圓周外和內圓周上畫線.我想根據 XY 角度在圓周上精確地畫線.

                圓中心點:

                x = 200y = 100半徑= 100

                public SecondActivity(String azim,String ele) {初始化();設置標題(我的窗口");`angle_x = Integer.parseInt(azim);angle_y = Integer.parseInt(ele);x = 200+r*Math.cos(angle_x);y = 100+r*Math.sin(angle_y);}公共無效油漆(圖形g){super.paint(g);drawCircle(g,200,100,r);畫線(g);}公共無效drawCircle(圖形g,int x,int y,int r){g.setColor(Color.BLACK);g.drawOval(x, y, r*2,r*2);}公共無效drawLine(圖形g){Graphics2D g2d = (Graphics2D) g;g2d.setColor(Color.BLUE);g2d.draw(new Line2D.Double(300.0d,200.0d,x,y));}

                解決方案

                您的代碼(和邏輯)中有幾個錯誤:

                1. 您使用 2 個角度來計算 XY 坐標,因此會得到奇怪的結果.根據這個

                2. 您使用的角度是度數,但 Math.cos(angle)Math.sin(angle) 要求 angle 以弧度表示,因此,您必須將角度轉換為弧度,如 Math.roRadians(angle),如以下問題所示:

                  I am working on a program in which I want to draw a line from circle's center to its parametric point. But it draws line out of circumference and inside circumference. I want to draw line exactly on circumference according to X and Y angles.

                  Circle center points:

                  x = 200
                  y = 100
                  radius= 100
                  

                  public SecondActivity(String azim,String ele) {
                      initialize();
                      setTitle("My WIndow");`
                  
                      angle_x = Integer.parseInt(azim);
                      angle_y = Integer.parseInt(ele);
                  
                      x = 200+r*Math.cos(angle_x);
                      y = 100+r*Math.sin(angle_y);      
                  }
                  
                  public void paint(Graphics g) {
                      super.paint(g);
                  
                      drawCircle(g,200,100,r);
                      drawLine(g);
                  }
                  
                  public void drawCircle(Graphics g,int x,int y,int r) {
                      g.setColor(Color.BLACK);
                      g.drawOval(x, y, r*2,r*2);
                  }
                  public void drawLine(Graphics g) {
                      Graphics2D g2d = (Graphics2D) g;    
                      g2d.setColor(Color.BLUE);
                      g2d.draw(new Line2D.Double(300.0d,200.0d,x,y));
                  }
                  

                  解決方案

                  You have a couple of errors in your code (and logic):

                  1. You're using 2 angles to calculate the X and Y coords, thus, giving you weird results. As per this Wikipedia image the angle theta is the same for bot coords.

                  2. You're using the angle in degrees, but Math.cos(angle) and Math.sin(angle) require that the angle is given in radians, so, you must convert the angles to radians as like Math.roRadians(angle), as shown in this question: How to use Math.cos() & Math.sin()?

                  3. Not really an error but a suggestion from @MadProgrammer in this other answer of mine to use the Shape API instead of pure .drawOval as you did while drawing the line, change drawOval to draw(new Ellipse2D.Double(...)).

                  4. You're overriding paint(Graphics g) method instead of paintComponent(Graphics g) this could cause some issues while painting. Use JPanels and override their paintComponent method and add those JPanels to your JFrame.

                  Having said all of the above, I came to a good example that follows the above advises as well as solving the issue:

                  import java.awt.Color;
                  import java.awt.Dimension;
                  import java.awt.Graphics;
                  import java.awt.Graphics2D;
                  import java.awt.geom.Ellipse2D;
                  import java.awt.geom.Line2D;
                  
                  import javax.swing.JFrame;
                  import javax.swing.JPanel;
                  import javax.swing.SwingUtilities;
                  
                  public class RadiusDrawer {
                      private JFrame frame;
                      private int centerX = 50;
                      private int centerY = 50;
                      private int x = 0;
                      private int y = 0;
                      private int r = 100;
                  
                      public static void main(String[] args) {
                          SwingUtilities.invokeLater(new RadiusDrawer()::createAndShowGui);
                      }
                  
                      private void createAndShowGui() {
                          frame = new JFrame(getClass().getSimpleName());
                  
                          frame.add(new MyCircle());
                          frame.pack();
                          frame.setVisible(true);
                          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                      }
                  
                      @SuppressWarnings("serial")
                      class MyCircle extends JPanel {
                          int cx = 0;
                          int cy = 0;
                          public MyCircle() {
                              int angle = 0;
                  
                              x = (int) (r * Math.cos(Math.toRadians(angle)));
                              y = (int) (r * Math.sin(Math.toRadians(angle)));
                  
                              y *= -1; //We must inverse the Y axis since in Math Y axis starts in the bottom while in Swing it starts at the top, in order to have or angles correctly displayed, we must inverse the axis
                  
                              calculateCenter();
                          }
                  
                          private void calculateCenter() {
                              cx = centerX + r;
                              cy = centerY + r;
                          }
                  
                          @Override
                          protected void paintComponent(Graphics g) {
                              super.paintComponent(g);
                              Graphics2D g2d = (Graphics2D) g;
                  
                              drawCircle(g2d, centerX, centerY, r);
                              drawRadius(g2d);
                          }
                  
                          private void drawCircle(Graphics2D g2d, int x, int y, int r) {
                              g2d.setColor(Color.BLACK);
                              g2d.draw(new Ellipse2D.Double(x, y, r * 2, r * 2));
                          }
                  
                          private void drawRadius(Graphics2D g2d) {
                              g2d.setColor(Color.BLUE);
                              g2d.draw(new Line2D.Double(cx, cy, cx + x, cy + y));
                          }
                  
                          @Override
                          public Dimension getPreferredSize() {
                              return new Dimension(300, 300);
                          }
                      }
                  }
                  

                  Here are some screenshots of the output at 0, 60 and 90 degrees.

                  這篇關于如何在不小于或大于周長的情況下繪制圓的半徑的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                How to convert Integer to int?(如何將整數轉換為整數?)
                How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                Inconsistent behavior on java#39;s ==(java的行為不一致==)
                Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)

                <small id='dwQ8A'></small><noframes id='dwQ8A'>

                • <i id='dwQ8A'><tr id='dwQ8A'><dt id='dwQ8A'><q id='dwQ8A'><span id='dwQ8A'><b id='dwQ8A'><form id='dwQ8A'><ins id='dwQ8A'></ins><ul id='dwQ8A'></ul><sub id='dwQ8A'></sub></form><legend id='dwQ8A'></legend><bdo id='dwQ8A'><pre id='dwQ8A'><center id='dwQ8A'></center></pre></bdo></b><th id='dwQ8A'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='dwQ8A'><tfoot id='dwQ8A'></tfoot><dl id='dwQ8A'><fieldset id='dwQ8A'></fieldset></dl></div>

                      <bdo id='dwQ8A'></bdo><ul id='dwQ8A'></ul>
                      <tfoot id='dwQ8A'></tfoot>
                        <tbody id='dwQ8A'></tbody>
                    • <legend id='dwQ8A'><style id='dwQ8A'><dir id='dwQ8A'><q id='dwQ8A'></q></dir></style></legend>

                          主站蜘蛛池模板: a国产一区二区免费入口 | 黄色在线免费观看视频网站 | 美女久久视频 | 国产一区二区三区久久久久久久久 | 91社影院在线观看 | 91成人 | 8x国产精品视频一区二区 | 日韩精品视频在线观看一区二区三区 | 成人午夜看片 | 天天澡天天狠天天天做 | 久久蜜桃av一区二区天堂 | 亚洲欧美激情网 | 91亚洲国产 | 亚洲伊人a | 免费一区二区 | 久久国内精品 | 久久av一区 | 久久精品国产a三级三级三级 | 久久久久久亚洲 | 福利精品| 日本中文在线视频 | 色橹橹欧美在线观看视频高清 | 亚洲一区二区电影在线观看 | 色婷婷在线视频 | 国产乱码精品一区二区三区中文 | 九七午夜剧场福利写真 | 一级网站| av在线一区二区三区 | 四虎在线播放 | 日韩福利电影 | 久久久久综合 | 无码日韩精品一区二区免费 | 99精品国产一区二区青青牛奶 | 一区二区电影 | 精国产品一区二区三区 | 亚洲 一区| 91麻豆精品国产91久久久资源速度 | 国内精品久久精品 | 久久国产精品-久久精品 | 久久精品国产一区 | 久久免费精品 |