【发布时间】:2020-02-11 20:31:28
【问题描述】:
我正在尝试为我的班级创建一个程序,该程序在圆内创建一个三角形,所有顶点都接触圆的周边。如同 this:
这是我的代码:
// 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 附近创建三角形,并在我移动小程序窗口时显示出来。世博文档是here
【问题讨论】:
-
如果您对现有实现感兴趣(而不是修复您已经完成的工作),我可以将您指向 PolygonFactory:sourceforge.net/p/tus/code/HEAD/tree/tjacobs/ui/shape/…
-
“世博会文件在这里”(你的)问题在哪里?
标签: java applet expo trigonometry