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

    1. <legend id='fJdht'><style id='fJdht'><dir id='fJdht'><q id='fJdht'></q></dir></style></legend>
    2. <small id='fJdht'></small><noframes id='fJdht'>

      <tfoot id='fJdht'></tfoot>

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

      <i id='fJdht'><tr id='fJdht'><dt id='fJdht'><q id='fJdht'><span id='fJdht'><b id='fJdht'><form id='fJdht'><ins id='fJdht'></ins><ul id='fJdht'></ul><sub id='fJdht'></sub></form><legend id='fJdht'></legend><bdo id='fJdht'><pre id='fJdht'><center id='fJdht'></center></pre></bdo></b><th id='fJdht'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='fJdht'><tfoot id='fJdht'></tfoot><dl id='fJdht'><fieldset id='fJdht'></fieldset></dl></div>
    3. 圍繞點(diǎn)旋轉(zhuǎn)三角形java

      Rotating a triangle around a point java(圍繞點(diǎn)旋轉(zhuǎn)三角形java)

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

              <tbody id='pHtca'></tbody>
              <bdo id='pHtca'></bdo><ul id='pHtca'></ul>

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

            • <tfoot id='pHtca'></tfoot>
              • 本文介紹了圍繞點(diǎn)旋轉(zhuǎn)三角形java的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                問(wèn)題描述

                我遇到了麻煩.我需要使用拖動(dòng)偵聽(tīng)器和單擊偵聽(tīng)器圍繞其中心旋轉(zhuǎn)等邊三角形.三角形應(yīng)該會(huì)增長(zhǎng),但現(xiàn)在會(huì)改變角度并旋轉(zhuǎn)一個(gè)點(diǎn),同時(shí)以三角形的中間為中心.這是我的問(wèn)題,它目前正在拖動(dòng)點(diǎn) 3 并圍繞點(diǎn) 1 旋轉(zhuǎn).我有一個(gè)值 x 和 y 的數(shù)組,它存儲(chǔ) 4 個(gè)值,每個(gè)值首先在序數(shù)值 0 處包含初始點(diǎn),在點(diǎn) 1 2 和 3 處對(duì)應(yīng)的值.

                I am having trouble. I need to rotate an equilateral triangle around it's centre by using the drag listener and click listener. The triangle should grow but now change angles and be rotated by a point while being centred at the middle of the triangle. This is my problem, it is currently dragging by the point 3 and rotating around point 1. I have an array of values x and y and it stores 4 values each containing the initial point first at ordinal value 0 and point 1 2 and 3 at the corresponding values.

                `

                public class DrawTriangle extends JFrame {
                
                enter code here
                /** The Constant NUMBER_3. */
                private static final int NUMBER_3 = 3;
                
                /** The Constant EQUL_ANGLE. */
                @SuppressWarnings("unused")
                private static final double EQUL_ANGLE = 1;
                
                /** The Constant TRIANGLE_POINTS. */
                private static final int TRIANGLE_POINTS = 4;
                
                /** The Constant _400. */
                private static final int SIZE = 400;
                
                /** The x points. */
                private int [] xPoints = new int[TRIANGLE_POINTS];
                
                /** The y points. */
                private int [] yPoints = new int[TRIANGLE_POINTS];
                
                private int xInitial;
                
                private int yInitial;
                
                /** The x. */
                private double x = EQUL_ANGLE;
                
                /** The new x. */
                private double newX;
                
                /** The new y. */
                private double newY;
                
                /**
                 * Instantiates a new draw triangle.
                 */
                public DrawTriangle() {
                    super("Dimitry Rakhlei");
                    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    setContentPane(new DrawTrianglePanel());
                    setSize(SIZE, SIZE); // you can change this size but don't make it HUGE!
                    setVisible(true);
                }
                
                /**
                 * The Class DrawTrianglePanel.
                 */
                private class DrawTrianglePanel extends JPanel implements MouseListener,
                        MouseMotionListener {
                
                    /**
                     * Instantiates a new draw triangle panel.
                     */
                    public DrawTrianglePanel() {
                        addMouseListener(this);
                        addMouseMotionListener(this);
                    }
                
                    /**
                     * Drawing the triangle.
                     *
                     * @param g
                     *            the g
                     * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
                     */
                    public void paintComponent(Graphics g) {
                        super.paintComponent(g);
                        // DRAWING CODE HERE
                        g.drawPolygon(xPoints, yPoints, 3);
                        System.out.println("Paint called");
                    }
                
                
                
                    /**
                     * (non-Javadoc).
                     *
                     * @param e
                     *            the e
                     * @see java.awt.event.MouseListener#mousePressed
                     * (java.awt.event.MouseEvent)
                     */
                    public void mousePressed(MouseEvent e) {
                        System.out.println("Mouse pressed called");
                        e.getPoint();
                        xPoints[0] = e.getPoint().x;
                        yPoints[0] = e.getPoint().y;
                        repaint();
                
                    }
                
                    /**
                     * (non-Javadoc).
                     *
                     * @param e
                     *            the e
                     * @see java.awt.event.MouseListener#mouseReleased
                     * (java.awt.event.MouseEvent)
                     */
                    public void mouseReleased(MouseEvent e) {
                        System.out.println("Mouse released called");
                    }
                
                    /**
                     * (non-Javadoc).
                     *
                     * @param e
                     *            the e
                     * @see java.awt.event.MouseMotionListener#mouseDragged
                     * (java.awt.event.MouseEvent)
                     */
                    public void mouseDragged(MouseEvent e) {
                        System.out.println("Mouse dragged called");
                        newX = e.getPoint().x;
                        newY = e.getPoint().y;
                        xPoints[1] = (int) newX;
                        yPoints[1] = (int) newY;
                
                
                        newX = xPoints[0] + (xPoints[1]-xPoints[0])*Math.cos(x) - (yPoints[1]-yPoints[0])*Math.sin(x);
                
                        newY = yPoints[0] + (xPoints[1]-xPoints[0])*Math.sin(x) + (yPoints[1]-yPoints[0])*Math.cos(x);
                
                        xPoints[2] = (int) newX;
                        yPoints[2] = (int) newY;
                
                        newX = xPoints[0] + (xPoints[1]-xPoints[0])*Math.cos(x) - (yPoints[1]-yPoints[0])*Math.sin(x);
                
                        newY = yPoints[0] + (xPoints[1]-xPoints[0])*Math.sin(x) + (yPoints[1]-yPoints[0])*Math.cos(x);
                
                        xPoints[3] = (int) newX;
                        yPoints[3] = (int) newY;
                
                        repaint();
                    }
                
                    /**
                     * (non-Javadoc).
                     *
                     * @param e
                     *            the e
                     * @see java.awt.event.MouseListener#mouseEntered
                     * (java.awt.event.MouseEvent)
                     */
                    public void mouseEntered(MouseEvent e) {
                        System.out.println("Mouse Entered.");
                    }
                
                    /**
                     * (non-Javadoc).
                     *
                     * @param e
                     *            the e
                     * @see java.awt.event.MouseListener#mouseExited
                     * (java.awt.event.MouseEvent)
                     */
                    public void mouseExited(MouseEvent e) {
                        System.out.println("Mouse exited.");
                    }
                
                    /**
                     * (non-Javadoc).
                     *
                     * @param e
                     *            the e
                     * @see java.awt.event.MouseListener#mouseClicked
                     * (java.awt.event.MouseEvent)
                     */
                    public void mouseClicked(MouseEvent e) {
                    }
                
                    /**
                     * (non-Javadoc).
                     *
                     * @param e
                     *            the e
                     * @see java.awt.event.MouseMotionListener#mouseMoved
                     * (java.awt.event.MouseEvent)
                     */
                    public void mouseMoved(MouseEvent e) {
                    }
                
                }
                
                /**
                 * The main method.
                 *
                 * @param args
                 *            the arguments
                 */
                public static void main(String[] args) {
                    new DrawTriangle();
                }
                
                };` 
                

                我的問(wèn)題是這段代碼基本上運(yùn)行正確,但我被告知旋轉(zhuǎn)的頂點(diǎn)必須在三角形的中間.我的是第一點(diǎn).

                My issue is that this code basically runs correctly but I am told the vertex point of rotation has to be in the middle of the triangle. Mine is the first point.

                推薦答案

                先看看 2D 圖形,特別是 變換形狀、文本、和圖片.

                基本上,您的多邊形"將具有可定義的大小(最大 x/y 點(diǎn)),由此,您可以確定多邊形"的中心位置,例如...

                Basically, your "polygon" will have a definable size (the maximum x/y point), from this, you can determine the center position of the "polygon", for example...

                protected Dimension getTriangleSize() {
                    int maxX = 0;
                    int maxY = 0;
                    for (int index = 0; index < xPoints.length; index++) {
                        maxX = Math.max(maxX, xPoints[index]);
                    }
                    for (int index = 0; index < yPoints.length; index++) {
                        maxY = Math.max(maxY, yPoints[index]);
                    }
                    return new Dimension(maxX, maxY);
                }
                

                這只是返回多邊形的最大 x 和 y 邊界.這允許您計(jì)算多邊形的中心位置.您馬上就會(huì)明白為什么您不需要實(shí)際指定原點(diǎn)...

                This just returns the maximum x and y bounds of your polygon. This allows you to calculate the center position of the polygon. You'll see why in a second why you don't need to actually specify the origin point...

                接下來(lái),我們計(jì)算一個(gè)AffineTransform,就是直接應(yīng)用到Graphics上下文...

                Next, we calculate a AffineTransform, which is the applied to the Graphics context directly...

                Graphics2D g2d = (Graphics2D) g.create();
                AffineTransform at = new AffineTransform();
                Dimension size = getTriangleSize();
                int x = clickPoint.x - (size.width / 2);
                int y = clickPoint.y - (size.height / 2);
                at.translate(x, y);
                at.rotate(Math.toRadians(angle), clickPoint.x - x, clickPoint.y - y);
                g2d.setTransform(at);
                g2d.drawPolygon(xPoints, yPoints, 3);
                // Guide
                g2d.setColor(Color.RED);
                g2d.drawLine(size.width / 2, 0, size.width / 2, size.height / 2);
                g2d.dispose();
                

                這不僅會(huì)平移三角形位置,還會(huì)旋轉(zhuǎn)它.這意味著您可以創(chuàng)建一個(gè)標(biāo)準(zhǔn)化多邊形(其原點(diǎn)為 0x0)并允許 Graphics 上下文將其放置在您想要的位置,這讓生活變得更加輕松......

                This not only translates the triangle position, but will also rotate it. What this means you can create a normalised polygon (whose origin point is 0x0) and allow the Graphics context to place it where you want it, this makes life SO much easier...

                現(xiàn)在,旋轉(zhuǎn)計(jì)算是基于計(jì)算兩點(diǎn)之間的角度,點(diǎn)擊"點(diǎn)和拖動(dòng)"點(diǎn)...

                Now, the rotation calculation is based on calculating the angle between two points, the "click" point and the "drag" point...

                angle = -Math.toDegrees(Math.atan2(e.getPoint().x - clickPoint.x, e.getPoint().y - clickPoint.y)) + 180;
                

                這基于 this question

                例如...

                紅線是一個(gè)簡(jiǎn)單的指南,表明三角形的尖端指向鼠標(biāo)...

                The red line is simple a guide to show that the tip of the triangle is point towards the mouse...

                import java.awt.Color;
                import java.awt.Dimension;
                import java.awt.EventQueue;
                import java.awt.Graphics;
                import java.awt.Graphics2D;
                import java.awt.Point;
                import java.awt.event.MouseEvent;
                import java.awt.event.MouseListener;
                import java.awt.event.MouseMotionListener;
                import java.awt.geom.AffineTransform;
                import javax.swing.JFrame;
                import javax.swing.JPanel;
                import javax.swing.UIManager;
                import javax.swing.UnsupportedLookAndFeelException;
                
                public class DrawTriangle extends JFrame {
                
                    /**
                     * The x points.
                     */
                    private int[] xPoints = new int[]{0, 25, 50};
                
                    /**
                     * The y points.
                     */
                    private int[] yPoints = new int[]{50, 0, 50};
                
                    double angle = 0f;
                
                    /**
                     * Instantiates a new draw triangle.
                     */
                    public DrawTriangle() {
                        super("Dimitry Rakhlei");
                        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        setContentPane(new DrawTrianglePanel());
                        pack();
                        setLocationRelativeTo(null);
                        setVisible(true);
                    }
                
                    /**
                     * The Class DrawTrianglePanel.
                     */
                    private class DrawTrianglePanel extends JPanel implements MouseListener,
                                    MouseMotionListener {
                
                        private Point clickPoint;
                
                        /**
                         * Instantiates a new draw triangle panel.
                         */
                        public DrawTrianglePanel() {
                            addMouseListener(this);
                            addMouseMotionListener(this);
                            clickPoint = new Point(100, 100);
                        }
                
                        @Override
                        public Dimension getPreferredSize() {
                            return new Dimension(200, 200);
                        }
                
                        protected Dimension getTriangleSize() {
                
                            int maxX = 0;
                            int maxY = 0;
                            for (int index = 0; index < xPoints.length; index++) {
                                maxX = Math.max(maxX, xPoints[index]);
                            }
                            for (int index = 0; index < yPoints.length; index++) {
                                maxY = Math.max(maxY, yPoints[index]);
                            }
                            return new Dimension(maxX, maxY);
                        }
                
                        /**
                         * Drawing the triangle.
                         *
                         * @param g the g
                         * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
                         */
                        @Override
                        protected void paintComponent(Graphics g) {
                            super.paintComponent(g);
                
                            Graphics2D g2d = (Graphics2D) g.create();
                            AffineTransform at = new AffineTransform();
                            Dimension size = getTriangleSize();
                            int x = clickPoint.x - (size.width / 2);
                            int y = clickPoint.y - (size.height / 2);
                            at.translate(x, y);
                            at.rotate(Math.toRadians(angle), clickPoint.x - x, clickPoint.y - y);
                            g2d.setTransform(at);
                            g2d.drawPolygon(xPoints, yPoints, 3);
                            // Guide
                            g2d.setColor(Color.RED);
                            g2d.drawLine(size.width / 2, 0, size.width / 2, size.height / 2);
                            g2d.dispose();
                
                        }
                
                        /**
                         * (non-Javadoc).
                         *
                         * @param e the e
                         * @see java.awt.event.MouseListener#mousePressed (java.awt.event.MouseEvent)
                         */
                        @Override
                        public void mousePressed(MouseEvent e) {
                            System.out.println("Mouse pressed called");
                            //          clickPoint = e.getPoint();
                            repaint();
                
                        }
                
                        /**
                         * (non-Javadoc).
                         *
                         * @param e the e
                         * @see java.awt.event.MouseListener#mouseReleased (java.awt.event.MouseEvent)
                         */
                        @Override
                        public void mouseReleased(MouseEvent e) {
                            System.out.println("Mouse released called");
                        }
                
                        /**
                         * (non-Javadoc).
                         *
                         * @param e the e
                         * @see java.awt.event.MouseMotionListener#mouseDragged (java.awt.event.MouseEvent)
                         */
                        public void mouseDragged(MouseEvent e) {
                            System.out.println("Mouse dragged called");
                
                            angle = -Math.toDegrees(Math.atan2(e.getPoint().x - clickPoint.x, e.getPoint().y - clickPoint.y)) + 180;
                
                            repaint();
                        }
                
                        /**
                         * (non-Javadoc).
                         *
                         * @param e the e
                         * @see java.awt.event.MouseListener#mouseEntered (java.awt.event.MouseEvent)
                         */
                        public void mouseEntered(MouseEvent e) {
                            System.out.println("Mouse Entered.");
                        }
                
                        /**
                         * (non-Javadoc).
                         *
                         * @param e the e
                         * @see java.awt.event.MouseListener#mouseExited (java.awt.event.MouseEvent)
                         */
                        public void mouseExited(MouseEvent e) {
                            System.out.println("Mouse exited.");
                        }
                
                        /**
                         * (non-Javadoc).
                         *
                         * @param e the e
                         * @see java.awt.event.MouseListener#mouseClicked (java.awt.event.MouseEvent)
                         */
                        public void mouseClicked(MouseEvent e) {
                        }
                
                        /**
                         * (non-Javadoc).
                         *
                         * @param e the e
                         * @see java.awt.event.MouseMotionListener#mouseMoved (java.awt.event.MouseEvent)
                         */
                        public void mouseMoved(MouseEvent e) {
                        }
                
                    }
                
                    /**
                     * The main method.
                     *
                     * @param args the arguments
                     */
                    public static void main(String[] args) {
                        EventQueue.invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                                    ex.printStackTrace();
                                }
                
                                new DrawTriangle();
                            }
                        });
                    }
                
                }
                

                現(xiàn)在,在你跳到我頭上抱怨解決方案太復(fù)雜"之前,請(qǐng)理解我是個(gè)白癡,說(shuō)真的,我 2 歲的孩子對(duì)基礎(chǔ)數(shù)學(xué)的掌握比我還好,這就是我能想出的最簡(jiǎn)單的解決方案不會(huì)融化我的大腦并使用雙陣列多邊形 API.就個(gè)人而言,我會(huì)使用 Shape API,但這不是你開(kāi)始使用的......

                Now, before you jump all over me and complain that the solution is "too complex", understand that I'm an idiot, seriously, my 2 year old has a better grasp on basic mathematics then I do, this is the most simplistic solution I can come up with that doesn't melt my brain and uses the dual array polygon API. Personally, I'd use the Shape API, but that's not what you started with...

                這篇關(guān)于圍繞點(diǎn)旋轉(zhuǎn)三角形java的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                相關(guān)文檔推薦

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

                  <tbody id='fiLfY'></tbody>

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

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

                      • <bdo id='fiLfY'></bdo><ul id='fiLfY'></ul>
                          主站蜘蛛池模板: 久久成人一区 | 青青久在线视频 | 精品一区二区三区91 | 久久久久久成人 | 国产亚洲精品久久午夜玫瑰园 | 中文字幕av在线 | 欧美色综合天天久久综合精品 | 日韩免费视频 | 日韩在线播放中文字幕 | 日本精品一区二区三区在线观看视频 | 久久久国产精品一区 | 欧美6一10sex性hd | 欧美韩一区二区三区 | 在线一区二区三区 | 99在线免费观看视频 | 亚洲欧美视频一区 | 日韩精品一区二区三区免费观看 | 久久久天天 | 男人av网 | 在线一级片 | 福利在线看 | 久久久久国产精品一区三寸 | 中文字幕一区二区三区四区五区 | 亚洲aⅴ一区二区 | 免费午夜视频在线观看 | 国产一区91精品张津瑜 | 嫩草国产| 亚洲欧美中文日韩在线v日本 | 九九精品视频在线 | 色噜噜狠狠色综合中国 | 色综合色综合网色综合 | 久久综合国产精品 | 一级毛片视频在线观看 | 97国产一区二区精品久久呦 | 玖玖色在线视频 | 美女久久久久久久 | 欧美精品1区2区3区 精品国产欧美一区二区 | 亚洲高清视频在线 | 亚洲精品乱码久久久久久按摩观 | 超碰日本| 黄色免费三级 |