「椭圆java代码」python椭圆代码

博主:adminadmin 2022-12-04 11:06:09 91

本篇文章给大家谈谈椭圆java代码,以及python椭圆代码对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

java 椭圆算法

以下代码,将输出一个椭圆,再有问题,我可远程助你。如下:

/**

 *(300,100)(400,100)

 *

*/

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

public class Lipse 

{

 public static void main(String[] args)

 {

  new MainFrame();

 }

}

class MainFrame extends JFrame implements ActionListener

{

 JPanel pane=new JPanel();

 JTextField T_a,T_b;

 JButton Draw,Show;

 JLabel L_a,L_b;

 int a,b;

 MainFrame()

 {

  super("DrawLipse Window");

  Container con=this.getContentPane();

  con.setLayout(null);

  

  pane.setBounds(20,20,850,550);

  pane.setBackground(new Color(100,156,200));

  con.add(pane);

  

  L_a=new JLabel("请输入长半径:a");

  L_a.setBounds(180,580,100,20);

  con.add(L_a);

  

  L_b=new JLabel("请输入短半径:b");

  L_b.setBounds(180,630,100,20);

  con.add(L_b);

  

  

  T_a=new JTextField();

  T_a.setBounds(300,580,50,20);

  con.add(T_a);

  

  T_b=new JTextField();

  T_b.setBounds(300,630,50,20);

  con.add(T_b);

  

  Draw=new JButton("画椭圆");

  Draw.setBounds(550,580,90,30);

  Draw.addActionListener(this);

  con.add(Draw);

  

  Show=new JButton("显示坐标");

  Show.setBounds(550,620,90,30);

  Show.addActionListener(this);

  con.add(Show);

  

  this.addWindowListener(new CloseWindow());

  this.setBounds(20,20,900,700);

  this.setVisible(true);

  this.setResizable(false);

  

 }/*MainFrame()*/

 public void actionPerformed(ActionEvent e)

 {

     if(e.getSource()==Draw)

     {

      a=Integer.parseInt(T_a.getText().trim());

      b=Integer.parseInt(T_b.getText().trim());

      Line line=new Line(this);

      line.drawLipse(a,b); 

     }

     if(e.getSource()==Show)

     {

       Graphics g1=this.pane.getGraphics();

          g1.setColor(Color.PINK);

          g1.drawLine(0,300,920,300);//----x---

          g1.drawLine(410,0,410,720);//----y---

          g1.dispose();

     }

  

 }/*method actionPerformed*/

}

class Line

{

 MainFrame jb;

 Line(MainFrame jb)

 {

  this.jb=jb;

 }

 public void drawLipse(int a,int b)

 {

  int x,y;

  double d1,d2;

  x=0;  y=b;

  d1=b*b+a*a*(-b+0.25);

  Graphics g=jb.pane.getGraphics();

  g.setColor(Color.red);

  g.drawLine(x+410,y+300,x+410,y+300);

  g.drawLine(-x+410,-y+300,-x+410,-y+300);

  g.drawLine(-x+410,y+300,x+410,-y+300);

  g.drawLine(x+410,-y+300,x+410,-y+300);

  try

  {

   while(b*b*(x+1)a*a*(y-0.5))

               {

            if(d1=0)

              {

              d1+=b*b*(2*x+3);

              x++;

              }

              else

              {

              d1+=(b*b*(2*x+3)+a*a*(-2*y+2));

              x++;

              y--;

              }

              g.drawLine(x+410,y+300,x+410,y+300);

              g.drawLine(-x+410,-y+300,-x+410,-y+300);

              g.drawLine(-x+410,y+300,x+410,-y+300);

              g.drawLine(x+410,-y+300,x+410,-y+300);

              Thread.sleep(30);

         }// top of while 

     }catch(Exception e){}

     

  d2=b*b*(x+0.5)*(x+0.5)+a*a*(y-1)*(y-1)-a*a*b*b;

  try

  {

   while(y0)

      {

     if(d2=0)

       {

       d2+=b*b*(2*x+2)+a*a*(-2*y+3);

       x++;

          y--;

        }

        else

        {

        d2+=a*a*(-2*y+3);

        y--;

        }

        g.drawLine(x+410,y+300,x+410,y+300);

           g.drawLine(-x+410,-y+300,-x+410,-y+300);

           g.drawLine(-x+410,y+300,x+410,-y+300);

           g.drawLine(x+410,-y+300,x+410,-y+300);

           Thread.sleep(30);

        }/* bottom of while*/

   

     }catch(Exception e){}

  

 } /*DrawLipse*/ 

  

}

class CloseWindow extends WindowAdapter

{

 public void windowClosing(WindowEvent e)

 {

  System.exit(0);

 }

}

编java代码求椭圆和长方形的面积和周长。

没明白isLargeThan是什么意思,能说得详细点儿么?

先把满足前四个条件的程序发给你,你看看行不行。

注:一个类一个java文件,运行Test3类执行。

public class Point {

private double x;

private double y;

public Point() {

x=0;

y=0;

}

public Point(double x,double y){

this.x=x;

this.y=y;

}

public double getX(){

return this.x;

}

public double getY(){

return this.y;

}

public void setX(double x){

this.x=x;

}

public void setY(double y){

this.y=y;

}

public Point translate(double u,double v){

this.x=this.x+u;

this.y=this.y+v;

return new Point (this.x,this.y);

}

}

public class Rectangle extends Point {

private double height;

private double wideth;

public Rectangle() {

super();

}

public Rectangle(Point p,double h,double w){

super(p.getX(),p.getY());

this.height=h;

this.wideth=w;

}

public double getPerimeter(){

return 2*(height+wideth);

}

public double getArea(){

return height*wideth;

}

}

public class Ellipse extends Point{

private double height;

private double wideth;

public Ellipse() {

super();

}

public Ellipse(Point p,double h,double w){

super(p.getX(),p.getY());

this.height=h;

this.wideth=w;

}

public double getPerimeter(){

return 2*3.14*Math.sqrt((height*height+wideth*wideth)/2);

}

public double getArea(){

return 3.14*height*wideth;

}

}

public class Test3 {

public static void main(String[] args) {

Point p=new Point(1.2,4.6);

Rectangle r=new Rectangle(p,9.2,8.7);

Ellipse e=new Ellipse(p,3.2,9.2);

Point p1=p.translate(2.8,2.9);

System.out.println("移动后的点为x="+p1.getX()+" y="+p1.getY());

System.out.println("长方形的周长为:"+r.getPerimeter());

System.out.println("长方形的面积为:"+r.getArea());

System.out.println("椭圆形的周长为:"+e.getPerimeter());

System.out.println("椭圆形的面积为:"+e.getArea());

}

}

请写出用java代码画一个圆

靠,楼上的回答那么长啊,只要一个函数,就是

drawOval(int x,int y,int w,int h); 这是是画椭圆形的函数,但是它也可以画圆形。

比如 drawOval(100,100,50,50); 就在坐标50,50画一个直径100的圆,只要把,最后的2个参数设成一样就是一个圆。要画直径200的话,就把最后2个参数设成200,200 一切OK了

JAVA 任意椭圆方向画法

使用 AffineTransform 把Ellipse2D 旋转一下就可以了。

import java.awt.image.BufferedImage;

import java.awt.geom.AffineTransform;

import java.awt.geom.Ellipse2D;

import java.awt.Color;

import java.awt.Shape;

import java.awt.Graphics2D;

import java.awt.RenderingHints;

import java.io.File;

import javax.imageio.ImageIO;

public class DemoPNG {

    public static void main(String[] args) throws Exception {

        BufferedImage bi = new BufferedImage(600, 800, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = bi.createGraphics();

        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        g2d.setPaint(Color.WHITE);

        g2d.fillRect(0,0,600, 800);

        g2d.setPaint(Color.RED);

        Ellipse2D s1 = new Ellipse2D.Double(100, 100, 400, 600);

        g2d.draw(s1);

        AffineTransform transform = AffineTransform.getRotateInstance(Math.PI/4, 300, 400);

        Shape r1 = transform.createTransformedShape(s1);

        g2d.fill(r1);

        AffineTransform transform2 = AffineTransform.getRotateInstance(Math.PI/2, 300, 400);

        Shape r2 = transform2.createTransformedShape(s1);

        g2d.draw(r2);

        g2d.dispose();

        ImageIO.write(bi, "PNG", new File("demo.png"));

    }

}

使用Java在窗口中部显示一个带文字的椭圆

操作步骤:

第1步:我们在Photoshop(本例使用CS5版本)里新建一个空白文件,然后选择路径工具里的椭圆工具画一个类似下图的椭圆形状;

第2步:选择文字工具(快捷键为T),把光标移到路径上任意一个地方做为输入起点,此时文字光标发生变化;

第3步:我们开始输入字符,在输入完成后,我们会看到起点处显示一个叉,终点显示一个实心黑点(当输入的文字过长,则终点与起点会重合在一起);

第4步:文字输完后,我们还能再调整,比如可以再使用文字工具在之前输入的文字处单击,就能激活文字修改;

第5步:前面做的是路径是一个封闭的路径,我们还可以做不规则的;

第6步:同样的我们输入文字,把两个路径文字放在一起后的效果就可以了。

向左转|向右转

Java如何编译椭圆周长的程序

publicclassCircle{圆的半径,privatedoublemRadius,publicCircle(doublemRadius){,this.mRadius=mRadius,}获取圆的周长,publicdoublegetLength,{return2Math.PImRadius,},获取圆的面积publicdoublegetArea{returnMath.PImRadiusmRadius。这样即可在Java编译椭圆周长的程序。

椭圆java代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于python椭圆代码、椭圆java代码的信息别忘了在本站进行查找喔。

The End

发布于:2022-12-04,除非注明,否则均为首码项目网原创文章,转载请注明出处。