rendered paste bodypackage draw3d;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
public class figur extends JPanel{
private static final long serialVersionUID = 1L;
public final int EMAX = 100;
public final int KOMAX = 100;
public double ko[][];
public int ka[][];
int anzko; //aktueller punkt
int anzka; //aktuelle kante
int anzkoold;
int anzkaold;
public figur(){
ko = new double[KOMAX][3];
ka = new int[EMAX][2];
anzko = 0;
anzka = 0;
anzkoold = 0;
anzkaold = 0;
this.setBounds(new Rectangle(100, 100, 54, 35));
this.setBackground(Color.WHITE);
}
double ko2d(double x, double y){
return x + .5 * y;
}
void turn (char direction, int deg, JPanel x){
double w = deg * Math.PI /180;
double[][] turnm;
double[] tmp = {0, 0, 0};
double[][] xrot = {{1,0,0},{0,Math.cos(w),-Math.sin(w)},
{0, Math.sin(w), Math.cos(w)}};
double[][] yrot = {{Math.cos(w),0,-Math.sin(w)},{0,1,0},
{Math.sin(w), 0,Math.cos(w)}};
double[][] zrot = {{Math.cos(w),-Math.sin(w), 0},
{Math.sin(w), Math.cos(w),0}, {0,0,1}};
switch (direction){
case 'x':
turnm = xrot;
break;
case 'y':
turnm = yrot;
break;
case 'z':
turnm = zrot;
break;
default:
turnm = null;
}
for(int j = 0; j<anzko; j++){
for (int i = 0; i < 3 ; i++){
tmp[i] = turnm[i][0] * ko[j][0] + turnm[i][1] * ko[j][1]
+ turnm[i][2] * ko[j][2];
}
ko[j][0] = tmp[0];
ko[j][1] = tmp[1];
ko[j][2] = tmp[2];
}
repaint();
return;
}
public int setPointse(double xk, double yk, double zk){
if (anzko < KOMAX && xk <= 100 && yk <= 100 && zk <= 100
&& xk >= -100 && yk >= -100 && zk >= -100){
ko[anzko][0] = xk;
ko[anzko][1] = yk;
ko[anzko][2] = zk;
anzko++;
return 1;
} else {
return 0;
}
}
public int setEdges(int from, int to){
if (anzka < EMAX && from >= 0 && from <= anzko
&& to >= 0 && to <= anzko){
ka[anzka][0] = from;
ka[anzka][1] = to;
anzka++;
return 1;
} else {
return 0;
}
}
public void paint(Graphics g){
int x1, x2, y1, y2;
//Graphics g;
//g = d.getGraphics();
//d.repaint();
this.setBackground(Color.WHITE);
for(int i = 0; i<anzka; i++){
x1 =(int) ko2d(ko[ka[i][0]][0],ko[ka[i][0]][2]);
y1 =(int) ko2d(ko[ka[i][0]][1],ko[ka[i][0]][2]);
x2 =(int) ko2d(ko[ka[i][1]][0],ko[ka[i][1]][2]);
y2 =(int) ko2d(ko[ka[i][1]][1],ko[ka[i][1]][2]);
g.drawLine(x1, y1, x2, y2);
}
}
}
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.JTextPane;
import javax.swing.JScrollPane;
import javax.swing.JList;
import java.awt.Graphics;
import java.awt.GridBagLayout;
import java.awt.Color;
public class draw3d extends JFrame {
figur k;
getPoints gepoin;
getEdges geedg;
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JPanel zeichnung = null;
private JButton Save = null;
private JButton Load = null;
private JButton getPonts = null;
private JButton getEdges = null;
private JButton Exit = null;
private JButton zminusRotate = null;
private JButton zRotate = null;
private JButton xRotate = null;
private JButton XminusRotate = null;
private JButton YRotate = null;
private JButton YminusRotate = null;
private JTextPane RotateText = null;
private JScrollPane jScrollPane = null;
private JScrollPane jScrollPane1 = null;
private JList PointList = null;
private JList EdgeList = null;
/**
* This method initializes Exit
*
* @return javax.swing.JButton
*/
private JButton getExit() {
if (Exit == null) {
Exit = new JButton();
Exit.setBounds(new Rectangle(438, 224, 100, 25));
Exit.setText("Exit");
Exit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.exit(0);
}
});
}
return Exit;
}
/**
* This method initializes zRotate
*
* @return javax.swing.JButton
*/
private JButton getZRotate() {
if (zRotate == null) {
zRotate = new JButton();
zRotate.setBounds(new Rectangle(335, 78, 50, 30));
zRotate.setText("Z");
zRotate.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
k.turn('z', 2, zeichnung);
}
});
}
return zRotate;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
figur k = new figur();
draw3d thisClass = new draw3d(k);
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
/*SwingUtilities.invokeLater(new Runnable() {
public void run() {
draw3d thisClass = new draw3d(k);
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});*/
}
/**
* This is the default constructor
*/
public draw3d(figur ka) {
super();
k = ka;
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(555, 370);
this.setContentPane(getJContentPane());
this.setTitle("FDSD");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.add(getZRotate(), null);
jContentPane.add(k);
}
return jContentPane;
}
} // @jve:decl-index=0:visual-constraint="10,10"