围绕点java旋转三角形 [英] Rotating a triangle around a point java

查看:178
本文介绍了围绕点java旋转三角形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有麻烦。我需要通过使用拖动侦听器并单击侦听器来围绕它的中心旋转等边三角形。三角形应该增长,但现在改变角度,并且在三角形中间居中的位置旋转一个点。这是我的问题,它正在拖动点3并围绕点1旋转。我有一个x和y值的数组,它存储了4个值,每个值包含初始点第一次在序数值0和点1 2和3在相应的值。

$ p
$ b $ pre $ public元素DrawTriangle扩展JFrame {

在此输入代码
/ **常量NUMBER_3。 * /
private static final int NUMBER_3 = 3;

/ **常量EQUL_ANGLE。 * /
@SuppressWarnings(unused)
private static final double EQUL_ANGLE = 1;

/ ** Constant TRIANGLE_POINTS。 * /
private static final int TRIANGLE_POINTS = 4;

/ **常量_400。 * /
private static final int SIZE = 400;

/ ** x点。 * /
private int [] xPoints = new int [TRIANGLE_POINTS];

/ ** y点。 * /
private int [] yPoints = new int [TRIANGLE_POINTS];

private int xInitial;

private int yInitial;

/ ** x。 * /
私人双x = EQUL_ANGLE;

/ **新的x。 * /
private double newX;

/ **新的y。 * /
私人双重newY;

/ **
*实例化一个新的绘制三角形。
* /
public DrawTriangle(){
super(Dimitry Rakhlei);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setContentPane(new DrawTrianglePanel());
setSize(SIZE,SIZE); //你可以改变这个尺寸,但不要太大!
setVisible(true);
}

/ **
*类DrawTrianglePanel。
* /
私人类DrawTrianglePanel扩展JPanel实现MouseListener,
MouseMotionListener {
$ b $ / **
*实例化一个新的绘制三角面板。
* /
public DrawTrianglePanel(){
addMouseListener(this);
addMouseMotionListener(this);
}

/ **
*绘制三角形。
*
* @param g
* g
* see javax.swing.JComponent#paintComponent(java.awt.Graphics)
* /
public void paintComponent(Graphics g){
super.paintComponent(g);
//在此绘制代码
g.drawPolygon(xPoints,yPoints,3);
System.out.println(Paint called);
}



/ **
*(非Javadoc)。
*
* @param e
* 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();

}

/ **
*(非Javadoc)。
*
* @param e
* e
* @see java.awt.event.MouseListener#mouseReleased
*(java.awt.event.MouseEvent)
* /
public void mouseReleased(MouseEvent e){
System.out.println(Mouse released called);
}

/ **
*(非Javadoc)。
*
* @param e
* 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);
$ b $ 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; (xPoints [1] -xPoints [0])* Math.cos(x) - (yPoints [1] -yPoints [0])* Math.sin(x) X);
$ b $ 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();
}

/ **
*(非Javadoc)。
*
* @param e
* e
* @see java.awt.event.MouseListener#mouseEntered
*(java.awt.event.MouseEvent)
* /
public void mouseEntered(MouseEvent e){
System.out.println(Mouse Entered。);
}

/ **
*(非Javadoc)。
*
* @param e
* e
* @see java.awt.event.MouseListener#mouseExited
*(java.awt.event.MouseEvent)
* /
public void mouseExited(MouseEvent e){
System.out.println(Mouse exited。);
}

/ **
*(非Javadoc)。
*
* @param e
* e
* @see java.awt.event.MouseListener#mouseClicked
*(java.awt.event.MouseEvent)
* /
public void mouseClicked(MouseEvent e){
}
$ b $ / **
*(非Javadoc)。
*
* @param e
* e
* @see java.awt.event.MouseMotionListener#mouseMoved
*(java.awt.event.MouseEvent)
* /
public void mouseMoved(MouseEvent e){
}

}
$ b $ / **
* main方法。
*
* @param args
*参数
* /
public static void main(String [] args){$ b $ new DrawTriangle();
}

};`

我的问题是,代码基本上可以正常运行,但我被告知旋转的顶点必须位于三角形的中间。 Mine是第一点。

解决方案

首先看一下二维图形,特别是转换形状,文本和图像

基本上,你的多边形将有一个可定义的大小例如... ...

  x / y点),从中可以确定多边形的中心位置,例如... 

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

}
返回新维(maxX,maxY);
}

这只是返回多边形的最大x和y边界。这使您可以计算多边形的中心位置。你会明白为什么在第二个为什么你不需要真正指定原点...



接下来,我们计算一个 AffineTransform ,它直接应用于图形上下文...

  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);
//指南
g2d.setColor(Color.RED);
g2d.drawLine(size.width / 2,0,size.width / 2,size.height / 2);
g2d.dispose();

这不仅可以翻译三角形的位置,还可以旋转它。这意味着你可以创建一个规范化的多边形(其原点是0x0),并允许 Graphics 上下文将它放在你想要的地方,这使得生活更容易。 。

现在,旋转计算是基于计算两点之间的角度,即点击点和拖动点...

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

这是基于这个问题



例如...

p>



红线很简单,可以指示三角形的顶端指向鼠标...

  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;

公共类DrawTriangle扩展JFrame {

/ **
* x点。
* /
private int [] xPoints = new int [] {0,25,50};

/ **
* y点。
* /
private int [] yPoints = new int [] {50,0,50};

double angle = 0f;

/ **
*实例化一个新的绘制三角形。
* /
public DrawTriangle(){
super(Dimitry Rakhlei);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setContentPane(new DrawTrianglePanel());
pack();
setLocationRelativeTo(null);
setVisible(true);
}

/ **
*类DrawTrianglePanel。
* /
私人类DrawTrianglePanel扩展JPanel实现MouseListener,
MouseMotionListener {

private Point clickPoint;

/ **
*实例化一个新的绘制三角面板。
* /
public DrawTrianglePanel(){
addMouseListener(this);
addMouseMotionListener(this);
clickPoint = new Point(100,100);
}

@Override
public Dimension getPreferredSize(){
return new Dimension(200,200);
}

保护Dimension getTriangleSize(){

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

}
返回新维(maxX,maxY);
}

/ **
*绘制三角形。
*
* @param g 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);
//指南
g2d.setColor(Color.RED);
g2d.drawLine(size.width / 2,0,size.width / 2,size.height / 2);
g2d.dispose();

}

/ **
*(非Javadoc)。
*
* @参数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();

}

/ **
*(非Javadoc)。
*
* @参数e
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
* /
@Override
public void mouseReleased(MouseEvent e){
System.out.println(Mouse released called);
}

/ **
*(非Javadoc)。
*
* @参数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();
}

/ **
*(非Javadoc)。
*
* @参数e
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
* /
public void mouseEntered(MouseEvent e){
System.out.println(Mouse Entered。);
}

/ **
*(非Javadoc)。
*
* @参数e
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
* /
public void mouseExited(MouseEvent e){
System.out.println(Mouse exited。);
}

/ **
*(非Javadoc)。
*
* @参数e
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
* /
public void mouseClicked(MouseEvent e){
}

/ **
*(非Javadoc)。
*
* @参数e
* @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
* /
public void mouseMoved(MouseEvent e){
}

}

/ **
*主要方法。
*
* @param args参数
* /
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();
}

新DrawTriangle();
}
});
}

}

现在,我抱怨说这个解决方案太复杂,明白我是个白痴,认真的说,我2岁时对基础数学有了更好的把握,然后我会这样做,这是我可以提出的最简单的解决方案,不会融化我的大脑,并使用双排列多边形API。就我个人而言,我会使用 Shape API,但这不是您开始使用的...


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();
}

};` 

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.

解决方案

Start by taking a look at 2D Graphics, in particular Transforming Shapes, Text, and Images.

Basically, you "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);
}

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...

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();

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...

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;

Which is based on the solution in this question

For example...

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();
            }
        });
    }

}

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...

这篇关于围绕点java旋转三角形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆