var A:Number = 360 / ecken;
for (var i:int = 0; i<ringe; ++i)//Das mit den Ringen, kommt daher das ich den Codeausschnitt
//aus einem Mühlespiel das ich gemacht habe entnommen habe.
{
var E:int = (i+1)*50;
for (var i2:int = 0; i2<ecken; ++i2)
{
var A2:Number = (A*i2+(A/2))/180*Math.PI;
new Point(Math.sin(A2) * E,Math.cos(A2) * E);
}
}
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.GeneralPath;
public class GeneralPathExample extends Frame {
private static final long serialVersionUID = 1L;
public GeneralPathExample() {
addWindowListener(new MyFinishWindow());
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
g.setColor(Color.red);
GeneralPath gp = new GeneralPath();
gp.moveTo(60, 120);
gp.lineTo(80, 120); // vordere Unterboden
gp.quadTo(90, 140, 100, 120); // Vorderreifen
gp.lineTo(160, 120); // mittlere Unterboden
gp.quadTo(170, 140, 180, 120); // Hinterreifen
gp.lineTo(200, 120);
gp.curveTo(195, 100, 200, 80, 160, 80); // Heck
gp.lineTo(110, 80); // Dach
gp.lineTo(90, 100); // Frontscheibe
gp.lineTo(60, 100); // Motorhaube
gp.lineTo(60, 120); // Front
g2d.draw(gp);
}
public static void main(String[] args) {
GeneralPathExample f = new GeneralPathExample();
f.setTitle("GeneralPath Example");
f.setBounds(100, 100, 500, 400);
f.setVisible(true);
}
}
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class MyFinishWindow extends WindowAdapter {
public void windowClosing(WindowEvent arg0) {
System.exit(0);
}
}
double x,y;
x = x0 - d/2*Math.cos(360/e);
y = y0 + d/2*Math.sin(360/e);
Ja, du bist blind [c]Math.atan2[/c], [c]Math.hypot[/c]
int x = (int)(Math.cos(a) * radius);
int y = (int)(Math.sin(a) * radius);
import java.awt.Point;
import java.util.Vector;
public class Vieleck {
private final int abstand;
private Vector<Point> points = new Vector<Point>();
public Vieleck(int radius) {
abstand = radius;
}
private void log(double ang, int x, int y) {
System.out.println("Neuer Punkt: Winkel = " + Math.toDegrees(ang) + " Grad, X = " + x + ", Y = " + y);
}
public void generatePolygon( int anzahl) {
points.removeAllElements();
final double angle = Math.toRadians(360.0 / anzahl);
for(double a=0.0; a<2*Math.PI; a+=angle) {
int x = (int)(Math.cos(a) * abstand);
int y = (int)(Math.sin(a) * abstand);
log(a, x, y);
points.add(new Point(x, y));
}
}
@Override
public String toString() {
return points.toString();
}
public static void main(String[] args) {
Vieleck ve = new Vieleck(10);
for (int i=1; i<=4; i++) {
ve.generatePolygon(i);
System.out.println(ve);
}
}
}
Titel | Forum | Antworten | Datum | |
---|---|---|---|---|
I | Hilfe: Klasse Vieleck | Allgemeine Java-Themen | 5 |