Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在圆内创建三角形_Java_Applet_Expo_Trigonometry - Fatal编程技术网

Java 在圆内创建三角形

Java 在圆内创建三角形,java,applet,expo,trigonometry,Java,Applet,Expo,Trigonometry,我正在尝试为我的类创建一个程序,该程序在一个圆的内部创建一个三角形,所有顶点都接触圆的周长。类似 : 这是我的密码: // Lab06Cst.java // The Expo Graphics Program II // This is the student, starting version, of Lab 06C. import java.awt.*; import java.applet.*; public class TimothyG_Lab06Cst extends Applet

我正在尝试为我的类创建一个程序,该程序在一个圆的内部创建一个三角形,所有顶点都接触圆的周长。类似 :

这是我的密码:

// Lab06Cst.java
// The Expo Graphics Program II
// This is the student, starting version, of Lab 06C.

import java.awt.*;
import java.applet.*;

public class TimothyG_Lab06Cst extends Applet
{
 public void paint(Graphics g)
 {
      // Substitute your own name here.
      Expo.drawHeading(g,"Timothy Grant","6C");
      //EXPO
      /* E */
      Expo.fillRectangle(g,50,60,60,110);
      Expo.fillRectangle(g,50,60,80,70);
      Expo.fillRectangle(g,50,80,70,90);
      Expo.fillRectangle(g,50,100,80,110);
      /* X */
      Expo.fillRectangle(g,90,60,100,80);
      Expo.fillRectangle(g,90,90,100,110);
      Expo.fillRectangle(g,100,80,110,90);
      Expo.fillRectangle(g,110,60,120,80);
      Expo.fillRectangle(g,110,90,120,110);
      /* P */
      Expo.fillRectangle(g,130,60,140,110);
      Expo.fillRectangle(g,140,60,160,70);
      Expo.fillRectangle(g,150,70,160,90);
      Expo.fillRectangle(g,140,80,150,90);
      /* O */
      Expo.fillCircle(g,195,85,25);
      Expo.setColor(g,255,255,255);
      Expo.fillCircle(g,195,85,15);
      Expo.setColor(g,0);

      //Pentagon
      Expo.drawRegularPolygon(g,50,160,30,5);

      //Symbol
      double r = 40.0;
      double angle1 = Math.random()* (2 * Math.PI);
      double angle2 = Math.random()* (2 * Math.PI);
      double angle3 = Math.random()* (2 * Math.PI);
      double x_1 = r * Math.cos(angle1);
      double y_1 = r * Math.sin(angle1);
      double x_2 = r * Math.cos(angle2);
      double y_2 = r * Math.sin(angle2);
      double x_3 = r * Math.cos(angle3);
      double y_3 = r * Math.sin(angle3);
      double a = Math.sqrt(Math.pow(x_2 - x_1, 2) + Math.pow(y_2 - y_1, 2));
      double b = Math.sqrt(Math.pow(x_3 - x_2, 2) + Math.pow(y_3 - y_2, 2));
      double c = Math.sqrt(Math.pow(x_1 - x_3, 2) + Math.pow(y_1 - y_3, 2));
      Expo.drawCircle(g,125,230,40); //The circle the triangle goes in

      Expo.drawLine(g, (int) x_1, (int) y_1, (int) x_2, (int) y_2);
      Expo.drawLine(g, (int) x_2, (int) y_2, (int) x_3, (int) y_3); //Should be drawing the triangle
      Expo.drawLine(g, (int) x_3, (int) y_3, (int) x_1, (int) y_1);


 }
}

“符号”的代码应该是在圆中创建一个三角形,但它只是在0,0周围创建了一个三角形,当我移动小程序窗口时,它会弹出。世博会文档是

这是您的问题:您需要向圆的中心添加偏移

  double center_x = 125 + 40/2; //x start + 1/2 * radius
  double center_y = 230 + 40/2; //y start + 1/2 * radius
  double x_1 = center_x + r * Math.cos(angle1);
  double y_1 = center_y + r * Math.sin(angle1);
  double x_2 = center_x + r * Math.cos(angle2);
  double y_2 = center_y + r * Math.sin(angle2);
  double x_3 = center_x + r * Math.cos(angle3);
  double y_3 = center_y + r * Math.sin(angle3);

如果您对现有的实现感兴趣(而不是修复您已经完成的工作),我可以向您介绍PolygonFactory:“世博会文档在这里”问题在哪里?在这之后,我是否应该找到三角形的质心以及质心和周长之间的距离,以便在三角形内部放置另一个圆?我可以,但我不知道还有什么。@TimothyGrant我不能回答你的问题,但请记住单击我答案上的复选标记来标记这个问题的答案。对不起,我忘了。修好了!