求Java画图版,能画正多边形的代码!
public class MiniDraw implements ActionListener, MouseListener{ // Fields private JFrame frame = new JFrame("MiniDraw"); private DrawingCanvas canvas = new DrawingCanvas(); private JButton colorButton; // the button for colour, so we can change its background to the current color. private JTextField textField; // the field for entering text to put on the canvas // fields for recording the information needed to perform the next action private enum Action {Line,Rect, Oval, Triangle, Text, Dot, Move, Delete, Push, Pull}; private int pressedX; //where the mouse was pressed private int pressedY; //where the mouse was pressed private Action currentAction = Action.Line; private Color currentColor = Color.black; private List shapes = new ArrayList (); /** Constructor sets up the GUI. */ public MiniDraw(){ frame.setSize(800,600); //The graphics area canvas.addMouseListener(this); frame.getContentPane().add(canvas, BorderLayout.CENTER); //The buttons JPanel topPanel = new JPanel( ); frame.getContentPane().add(topPanel, BorderLayout.NORTH); JPanel botPanel = new JPanel( ); frame.getContentPane().add(botPanel, BorderLayout.SOUTH); addButton(topPanel, "New"); addButton(topPanel, "Open"); addButton(topPanel, "Save"); addButton(topPanel, "Delete"); addButton(topPanel, "Move"); colorButton = addButton(topPanel, "Color"); // remember the button so we can change its colour addButton(topPanel, "Push"); addButton(topPanel, "Pull"); addButton(topPanel, "Reverse"); addButton(topPanel, "Quit"); botPanel.add(new JLabel("Shapes: ")); addButton(botPanel, "Line"); addButton(botPanel, "Rect"); addButton(botPanel, "Oval"); addButton(botPanel, "Triangle"); addButton(botPanel, "Dot"); addButton(botPanel, "Text"); textField = new JTextField("Enter text", 12); botPanel.add(new JLabel(" : ")); botPanel.add(textField); frame.setVisible(true); } /** Utility method to make new button and add it to the panel Returns the button, in case we need it. */ private JButton addButton(JPanel panel, String name){ JButton button = new JButton(name); button.addActionListener(this); panel.add(button); return button; } /** Respond to button presses */ public void actionPerformed(ActionEvent e){ String button = e.getActionCommand(); //System.out.printf("Button: %s\n", button); //for debugging if (button.equals("New") ) newDrawing(); else if (button.equals("Open") ) openDrawing(); else if (button.equals("Save") ) saveDrawing(); else if (button.equals("Color") ) selectColor(); else if (button.equals("Reverse") ) reverseDrawing(); else if (button.equals("Quit") ) frame.dispose(); else{ // currentAction = Action.valueOf(button); // converts the String to an Action. } } /** Sets the current color. * Also changes the color of the Color button and sets the background color of the canvas */ private void selectColor(){ Color newColor = JColorChooser.showDialog(frame,"Choose Color for new shapes", currentColor); if (newColor!=null){ currentColor=newColor; colorButton.setBackground(currentColor); } } // Respond to mouse events /** When mouse is pressed, remember the position in order to construct the Shape when * the mouse is released. */ public void mousePressed(MouseEvent e) { int x = e.getX(); int y = e.getY(); //System.out.printf("Pressed at (%d, %d)\n", x, y); //for debugging pressedX = x; pressedY = y; } /** When the Mouse is released, depending on the currentAction, * either construct the shape that was being drawn, or perform the * action (delete or move) on the shape under the point where the mouse was pressed.*/ public void mouseReleased(MouseEvent e) { int x = e.getX(); int y = e.getY(); //System.out.printf("Released at (%d, %d)\n", x, y); //for debugging if (currentAction==Action.Move) moveShape(pressedX, pressedY, x, y); else if (currentAction==Action.Delete) deleteShape(x, y); else if (currentAction==Action.Push) pushShapeBackward(x, y); else if (currentAction==Action.Pull) pullShapeForward(x, y); else addShape(pressedX, pressedY, x, y); } public void mouseClicked(MouseEvent e) {} //needed to satisfy interface public void mouseEntered(MouseEvent e) {} //needed to satisfy interface public void mouseExited(MouseEvent e) {} //needed to satisfy interface // Helper methods for implementing the button and mouse actions /** Start a new drawing. */ public void newDrawing(){ shapes = new ArrayList(); canvas.clear(); } /** Open a file, and read all the shape descriptions into the current drawing. */ public void openDrawing(){ String fname = FileChooser.open(); if (fname==null) return; try { Scanner ...
【用几何画板如何画正多边形】作业帮
1.新建一个参数n=6,并计算n-1.(要正几边形,n就取几)2.计算360°÷n.(注意单位°)3.画一个圆O,并在圆上再任意取一个点,我这里记为A.4.双击圆心,将其标记为中心,然后选择点A,点“变换→旋转→算出来的那个'360°÷n'→确定”,得到点B,并连接AB.5.选中点A,以及算出来的“n-1”(注意顺序),点“变换”,然后按住“shift”,这时“迭代”会变成“深度迭代”,点“深度迭代”,然后点点B,确定.6.如果要做旋转动画的话,选中点A,点“编辑→操作类按钮→动画”,不做动画的话此步不必做.7.OK啦.
【正十七边形】如何绘制正多边形?如何绘制正五边形、正十五边形、...
正五边形作图见我的回答 正十五边形作图 在一个已知圆中,欧几里得以AC为边长作内接等边三角形,并以AB为边,作内接正五边形,其顶点均位于A(图3.4)。
欧几里得注意到,弧AC等于圆周长的三分之一,而弧AB则等于圆周长的1/5,因此,这两条弧的差就等于圆周长的1/3-1/5=2/15如果我们平分弦BC,并从BC弦的中点作垂线,交圆于E,这样,我们就平分了弧BC。
因此,弦BE等于圆周长的十五分之一,弦BE就是正十五边形的边长。
沿着圆周复制15条BE弦,我们就完成了正十五边形的作图。
正十七边形作图见 千多年前,古希腊数学家曾深入研究过一类作图问题,即:如何利用尺规作内接正多边形。
早在《几何原本》一书中,欧几里德就用尺规完成了圆内接正三边形、正四边形、正五边形,甚至正十五边形的作图问题。
然而,似乎更容易完成的正7、9、11……边形却未能做出。
让后来数学家尴尬的是,欧几里德之后的2000多年中,有关正多边形作图仍停留在欧几里德的水平上,未能向前迈进一步。
因此,我们可以想象得到,当1796年年仅19岁的高斯宣布他发现了正十七边形的作图方法时,会在数学界引起多么巨大的震憾了。
不过,高斯的结果多少显得有些奇怪。
他没有完成正七边形或正九边形等的作图,却偏偏隔下中间这一些直接完成了正十七边形。
为什么第一个新做出的正多边形是正十七边形而不是正七、九边形呢?在高斯的伟大发现之后,问题仍然存在:正七边形或正九边形等是否可尺规完成?或者更清楚地阐述这个问题:正多边形的边数具有什么特征时,它才能用尺规做出? 在经过继续研究后,高斯最终在1801年对整个问题给出了一个漂亮的回答。
高斯指出,如果仅用圆规和直尺,作圆内接正n边形,当n满足如下特征之一方可做出: 1) n=2m;( 为正整数) 2) 边数n为素数且形如 n=22t(t+1=0 、1、2……)。
简单说,为费马素数。
3) 边数 n具有n=2mp1p2p3...pk ,其中p1、p2、p3…pk为互不相同的费马素数。
由高斯的结论,具有素数p条边的正多边形可用尺规作图的必要条件是p为费马数。
由于我们现在得到的费马素数只有前五个费马数,那么可用尺规作图完成的正素数边形就只有3、5、17、257、65537。
进一步,可以做出的有奇数条边的正多边形也就只能通过这五个数组合而得到。
这样的组合数只有31种。
而边数为偶数的可尺规做出的正多边形,边数或是2的任意次正整数幂或与这31个数相结合而得到。
就这样,正多边形作图问题与费马数极其密切地联结在一起了!数学的一大魅力在于:看似全然无关的领域竟能以出人意料的方式彼此联系在一起。
透过“数学王子”高斯的杰出发现,人们确实可以从中充分领略到数学的这种魅力。
事实上,正是两者这种出乎意料的神秘结合,使人们对费马数有了更为持续不断的兴趣。
proe画正多边形画法
cad中你画正多边形时,提示你选择是外切或是内接,然后让你输入一个虚拟圆的半径其实这就是在让你确定你正多边形的尺寸同样一个多边形,你可以选择外切或是内接,都可以画出来,只是输入的圆半径值不一样,这得看你已知的条件是哪个你图中的那个圆是零件的轮廓 而不是你画正多边形时的那个虚拟的圆另外,角度是可以自己调整,或者选用正交模式如图同样的多边形 圆不一样大 第一个内接 第二个外切