Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM...

25
Documentation on the java TM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin Institut für Theoretische Physik Abstract This documentation describes the usage of this Java applet 1 and provides the theory that is groundwork of it. The applet illustrates the rotation of a coordinate system along the euler angles. The rotation can be done with the mouse or automatically after typing in the desired angles into the concerning controls. This applet has been created within the “OWL-project” “e-Module zur Veranschaulichung der Theoretischen Physik”. 2 1 Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both. 2 Translated to english by Stanislav Ax 21.03.2014

Transcript of Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM...

Page 1: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

Documentation on the javaTM packetEuler angles

Simon Kraeusel

15-th october 2008

Technische Universität BerlinInstitut für Theoretische Physik

Abstract

This documentation describes the usage of this Java applet1 and provides the theorythat is groundwork of it. The applet illustrates the rotation of a coordinate systemalong the euler angles. The rotation can be done with the mouse or automatically aftertyping in the desired angles into the concerning controls.

This applet has been created within the “OWL-project” “e-Module zurVeranschaulichung der Theoretischen Physik”.2

1Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States,other countries, or both.

2Translated to english by Stanislav Ax 21.03.2014

Page 2: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

Contents1 Introduction 3

2 Usage 42.1 The control plane (on the right side of the main window) . . . . . . . . . 42.2 The graphic plane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

3 Theory(brief) 53.1 Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

ImprintInstitut für Theoretische PhysikHardenbergstr. 36, Sekr. EW 7-1

10623 Berlin

Project: “Offensive Wissen durch Lernen”“e-Module zur Veranschaulichung der Theoretischen Physik”

Head of the project: Prof. Dr. Eckehard Schöll, PhDContact: [email protected]

2

Page 3: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

Figure 1: view on applet in the very beginning

1 IntroductionThis applet shall provide an illustration of the rotation of coordinate systems along theeuler angles. This happens with the help of a three-dimensional environment with a 3Dobject and 2 coordinate systems. To achieve the illustration the 3D object (withreference system) becomes rotated relatively to the original reference system.Visualizatons that this applet may provide

• An animation of the rotation of a coordinate system

• A three dimensional image of a logo

• Two relatively to each other rotatable coordinate systems (representation of the unitvector by colored lines and logo)

• The illustration of the rotational angles in a (3,2,3) notation

• Adjustment of the camera angle by mouse independent of the both coordinatesystems

Visualizatons that this applet may not provide

• The illustration of the rotational angle if adjusting the euler angles manually

• the surface of the three dimensional logo

3

Page 4: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

2 UsageA window with the controls and with a plane for graphical visualizations is startedimmediately after the automatical initialization of the applet. The initialization beginsas soon the webpage which provides the applet is called.

2.1 The control plane (on the right side of the main window)

Figure 2: controls of the main window. The left one for the manual adjustment andthe right one for automatical adjustment by the program.

This control panel is devided into two sections as visible in figure 2. In the upper halfthree sliders for manual adjustment of the euler angles are visible. If using the sliderone sees that the logo begins to move and a red coordinate system becomes visible. Itshould be noted that the common rotation of the coordinate systems in relation toeach other will only result if the angles will be manipulated in the right order since therotation matrices do not commutate. Starting with the angle Ψ will rotate thecoordinate system (green) along the euler angles and will make the right rotationvisible if one is located within the red coordinate system.The controls within the area “animation” lead to an automatically illustration of theeuler angles. By pushing the start button the rotation around every euler angle will beanimated one after the other. They will be turned until the values in the text boxesare reached. After launching the applet the text boxes for values for the automaticalanimation of the euler angles are already filled in. They may be changed by the user.Only integer values will be accepted by the applet. All integers will be submitted indegree to the applet.

2.2 The graphic planeA green coordinate system and a 3D logo is visible here in the beginning. With themouse the cameras point of view on the coordinate systems can be adjusted at any timeeven during an automatical animation. To do this the mouse has to be moved while

4

Page 5: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

keeping the left mouse button pressed. Relatively to the movement of the mouse to thex direction and to the y direction a rotation of the whole system is caused then. If bothmouse buttons kept being pushed then the window content can be zoomed in and out.As visible in figure 3 no representation of the angles will be entered into the graphicplane if one is manipulating the euler angles manually.

Figure 3: three versions of the main window are shown in this figure. On the left isthe view briefly after the start of the applet. In the middle is a view whilemanipulating the angles manually and on the right is the view on the applet while it isrotating the coordinate systems automatically.

3 Theory(brief)3.1 Basics

Figure 4: from the left to the right the euler angles φ, θ,Ψ in (z,y,z) convention areshowed if the red coordinate system is rotated along the black.

The euler angles providing the orientation of an arbitrary coordinate system in relationto an inertial system. For example the orientation of an arbitrary rigid body. For this

5

Page 6: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

the orientation is splited into three fundamental rotations. This rotations can bechosen freely but they have to span the set of rotations within the R3. There anyrotation R in R3 is an element of the special orthogonal group SO(3)3. Thefundamental rotations can be chosen of:

Rx(α) =

1 0 00 cos(α) sin(α)0 −sin(α) cos(α)

, Ry(β) =

cos(β) 0 −sin(β)0 1 0

sin(β) 0 cos(β)

,

Rx(α) =

cos(γ) sin(γ) 0−sin(γ) cos(γ) 0

0 0 1

,

The presented matrices are representing rotations around the x, y and z axes. Thereexisting 33 possible combinations of this rotations but only 12 that span the space4 ofthe rotation (SO(3)).No uniform convention is existing that shows which of the 12 should be chosen but 3 ofthem are used usually.

• (z,y,z)-convention: In this convention each rotation R is splitted into the belowshown combinatons. This convention is also used by the applet.

R = Rz(Ψ)Ry(θ)Rz(Φ)

Hence in a rotation around the inertial z axis (Φ), then around the changed y axis (θ)and finally around the changed z axis Ψ. The sequence of this rotation can beconsidered in figure 4. Remarkable about this notation is that the first two rotationsare oriented into a direction that is the same like the orientation of the sphericalcoordinates. The last rotation around the new z axis is hence the missing informationof the direction of the two other axes.

• (z,x,z)-convention:

R = Rz(γ)Rx(β)Rz(α)

This convention is often used as for example in the computer graphic

• (z,y,x)-convention:

R = Rz(Ψ)Ry(θ)Rx(Φ)3R ∈ SO(3) =⇒ RRT = 1, det(R) = +14It is possible to use the same rotation matrix two times since SO(3) is not abelian: [Ra, Rb] 6= 0 =⇒

RaRb 6= RbRa.

6

Page 7: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

This convention is mainly used within the aeronautics. (DIN 9300, Yaw-Pitch-Roll)It should be noted that the splitting of the euler angles is not a bijective function.That means that the reversebility is not warrantied. Any combination of the threeeuler angles is representing exactly one direction within the rotational space. Butsingularities are existing as for example in the case of a vanishing Θ angle in (z,y,z)notation.

7

Page 8: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

4 QUELLCODE

4 Quellcode

Listing 1: Hauptklasse des Applets/∗∗∗ This f i l e (MainFrame . java ) i s par t o f t he Euler Angle p ro j e c t .∗∗ requ i red f i l e s : niceGraphics package ( tuShape . java , DrawPanelIn3D) and customTextFie ld∗∗ used by : −∗∗ −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−∗Hier s t a r t e d der Compiler , und das Fenster samt Kontrol lPane l wird aufgebaut . Die ...

Hauptaechl ichen ze ichen−∗ rout inen f inden s i c h in DrawPanelIn3D . Java .∗

∗∗ @author Simon Kraeusel∗/

import java . awt . BorderLayout ;import java . awt . Dimension ;import java . awt . event . ActionEvent ;import java . awt . event . Act i onL i s tener ;

import javax . swing . ∗ ;import javax . swing . event . ChangeEvent ;import javax . swing . event . ChangeListener ;

import ni ceGraph i cs . ∗ ;

public class MainFrame extends JApplet implements ChangeListener , Act i onL i s tener {

/∗∗∗∗/

private stat ic f ina l long s e r i a lVer s i onUID = 8731871807939998623L ;JPanel contro lPane l ;DrawPanelIn3D graph i csPane l ;T e x t f i e l d S l i d e r ang l eS l i d e rPh i= new Tex t f i e l d S l i d e r ( T e x t f i e l d S l i d e r . ...

VERTICAL, 0 , 360 , 0 , ”<html><f ont s i z e = +1> \u03c6</font></html>” ) ;T e x t f i e l d S l i d e r ang l eS l i derTheta= new T ex t f i e l d S l i d e r ( T e x t f i e l d S l i d e r . ...

VERTICAL, 0 , 360 , 0 , ”<html><f ont s i z e = +1> \u03d1</font></html>” ) ;T e x t f i e l d S l i d e r an g l e S l i d e rP s i= new Tex t f i e l d S l i d e r ( T e x t f i e l d S l i d e r . ...

VERTICAL, 0 , 360 , 0 , ”<html><f ont s i z e = +1> \u03c8</font></html>” ) ;JButton go = new JButton ( ” Star t ” ) ;customTextField [ ] t e x tF i e l d s = new customTextField [ 3 ] ;

public stat ic void main ( Str ing [ ] a rgs ) {JApplet theApplet = new MainFrame ( ) ;

theApplet . i n i t ( ) ; // Needed i f overr idden in app l e t}

public void i n i t ( ) {javax . swing . Sw i n gU t i l i t i e s . invokeLater (new Runnable ( ) {public void run ( ) {

createAndShowGUI ( ) ;}

}) ;}private void createAndShowGUI ( ) {

JFrame frame = new JFrame( ”Euler Winkel ” ) ;frame . s e tDefau l tC loseOperat i on ( JFrame .EXIT ON CLOSE) ;// frame . s e tPre f e r r e dS i z e (new Dimension (620 ,540) ) ;JPanel thePanel = new JPanel (new BorderLayout ( ) ) ;// thePane l . s e t S i z e (600 ,500) ;graph i csPane l = new DrawPanelIn3D (500 ,500) ;g raph i csPane l . setMaximumSize (new Dimension (500 , 500) ) ;JScro l lPane s c r o l lPane = new JScro l lPane ( graph i csPane l ) ; // t h i s pane l i s ...

needed because DrawPanelIn3D i s not r e s i z a b l e

8

Page 9: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

4 QUELLCODE

s c r o l lPane . setBorder ( BorderFactory . c r eateRa i s edBeve lBorder ( ) ) ;thePanel . add ( scro l lPane , BorderLayout .CENTER) ;contro lPane l = new JPanel ( ) ;// cont ro lPane l . s e tPre f e r r e dS i z e (new Dimension (100 , 500) ) ;graph i csPane l . s e tLabe l ( ”Copyright \u00A9 2008 TU−Ber l i n (S . Kraeusel & J . ...

Probst ) ” , true ) ;i n i tConro lPane l ( ) ;thePanel . add ( this . controlPanel , BorderLayout .EAST) ;frame . setContentPane ( thePanel ) ;frame . pack ( ) ;frame . s e tV i s i b l e ( true ) ;

}private void i n i tConro lPane l ( ) {

contro lPane l . setBorder ( BorderFactory . c r eateRa i s edBeve lBorder ( ) ) ;contro lPane l . setLayout (new BoxLayout ( this . controlPane l , BoxLayout . ...

PAGE AXIS) ) ;JPanel s l i d e rPan e l = new JPanel ( ) ;s l i d e rPan e l . add ( this . ang l eS l i d e rPh i ) ;s l i d e rPan e l . add ( this . ang l eS l i derTheta ) ;s l i d e rPan e l . add ( this . a n g l e S l i d e rP s i ) ;ang l eS l i d e rPh i . setTextFie ldFormatStr ing ( ang l eS l i d e rPh i . ...

getTextFie ldFormatStr ing ( ) + ”\u00B0” ) ;ang l eS l i derTheta . setTextFie ldFormatStr ing ( ang l eS l i d e rPh i . ...

getTextFie ldFormatStr ing ( ) ) ;a n g l e S l i d e rP s i . setTextFie ldFormatStr ing ( ang l eS l i d e rPh i . ...

getTextFie ldFormatStr ing ( ) ) ;s l i d e rPan e l . setBorder ( BorderFactory . c r eateTi t l edBorde r ( ” Di r ect ” ) ) ;this . contro lPane l . add ( s l i d e rPan e l ) ;a n g l e S l i d e rP s i . addChangeListener ( this ) ;ang l eS l i derTheta . addChangeListener ( this ) ;ang l eS l i d e rPh i . addChangeListener ( this ) ;JPanel animationPanel= new JPanel ( ) ;animationPanel . setBorder ( BorderFactory . c r eateTi t l edBorde r ( ”Animation ” ) ...

) ;animationPanel . setLayout (new BoxLayout ( animationPanel , BoxLayout . ...

PAGE AXIS) ) ;JPanel [ ] t extPane l s = new JPanel [ 3 ] ;for ( int i = 0 ; i < t e x tF i e l d s . l ength ; i++) {

t e x tF i e l d s [ i ]=new customTextField (0 , 360 , 3 , 70) ;textPane l s [ i ] = new JPanel ( ) ;animationPanel . add ( textPane l s [ i ] ) ;

}textPane l s [ 0 ] . add (new JLabel ( ”<html><f ont s i z e = +1> \u03c6</font></ ...

html>” ) ) ;textPane l s [ 0 ] . add ( t e x tF i e l d s [ 0 ] ) ;t extPane l s [ 1 ] . add (new JLabel ( ”<html><f ont s i z e = +1> \u03d1</font></ ...

html>” ) ) ;textPane l s [ 1 ] . add ( t e x tF i e l d s [ 1 ] ) ;t extPane l s [ 2 ] . add (new JLabel ( ”<html><f ont s i z e = +1> \u03c8</font></ ...

html>” ) ) ;textPane l s [ 2 ] . add ( t e x tF i e l d s [ 2 ] ) ;animationPanel . add ( go ) ;this . contro lPane l . add ( animationPanel ) ;go . addActionListener ( this ) ;

}public void stateChanged (ChangeEvent arg0 ) {

graph i csPane l . t e s t e r=fa l se ;g r aph i csPane l . s e tEu l erAng l es ( this . a n g l e S l i d e rP s i . getValue ( ) /180.0∗Math ...

. PI ,this . ang l eS l i derTheta . getValue ( ) /180.0∗Math . PI ,this . ang l eS l i d e rPh i . getValue ( ) /180.0∗Math . PI ) ;

}

public void act ionPer formed ( ActionEvent arg0 ) {

i f ( arg0 . getSource ( )==go ) {this . g r aph i csPane l . s tar tAnimation (

this . t e x tF i e l d s [ 0 ] . value ( ) /180.0∗Math . PI ,this . t e x tF i e l d s [ 1 ] . value ( ) /180.0∗Math . PI ,this . t e x tF i e l d s [ 2 ] . value ( ) /180.0∗Math . PI ) ;

9

Page 10: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

4 QUELLCODE

}}

}

Listing 2: Erstellt Slider mit Texteingabeimport java . awt . BorderLayout ;import java . awt . Dimension ;import java . text . DecimalFormat ;import java . text . ParseException ;

import javax . swing . JLabel ;import javax . swing . JPanel ;import javax . swing . JS l i d e r ;import javax . swing . JTextFie ld ;import javax . swing . SwingConstants ;import javax . swing . event . ChangeEvent ;import javax . swing . event . ChangeListener ;import javax . swing . event . DocumentEvent ;import javax . swing . event . DocumentListener ;import javax . swing . text . BadLocationException ;import javax . swing . text . Document ;

/∗∗∗ JS l i d e r wi th a JLabel on top and a JTextFie ld on the bottom .∗ Version 0.4 − June 30 th , 2008

∗/

public class Tex t f i e l d S l i d e r extends JPanel implements ChangeListener {

JLabel label ;private JS l i d e r s l i d ;private JTextFie ld t f i e l d ;private boolean TextF i e l dV i s i b l e = true ;private double adjustValue = 1 . 0 ;private Str ing f ormatStr ing = ”%.0 f ” ; //”%.2g ” ;public stat ic int VERTICAL = JS l i d e r .VERTICAL;public stat ic int HORIZONTAL = JS l i d e r .HORIZONTAL;

public T ex t f i e l d S l i d e r ( int o r i en ta t i on , int min , int max , int i n i t , S t r ing ...capt i on ) {

s l i d = new JS l i d e r ( o r i en ta t i on , min , max , i n i t ) ;s l i d . setMinorTickSpacing (1) ;s l i d . s e tPa intTi cks ( fa l se ) ;// s l i d . setSnapToTicks( t rue ) ;

t f i e l d = new JTextFie ld (4) ;t f i e l d . setText ( ””+i n i t ) ;

label = new JLabel ( capt i on ) ;

f ina l ChangeListener s l i d l i s t e n = new ChangeListener ( ) {public void stateChanged ( ChangeEvent ce ) {

JS l i d e r sour ce = ( JS l i d e r ) ce . getSource ( ) ;int value = ( int ) sour ce . getValue ( ) ;t f i e l d . setText ( Str ing . format ( formatStr ing , Double . valueOf ( value ∗ ...

adjustValue ) ) ) ;return ;

}} ;

f ina l DocumentListener f i e l d l i s t e n = new DocumentListener ( ) {public void inser tUpdate (DocumentEvent e ) {

Document doc = (Document ) e . getDocument ( ) ;double value = 0 . 0 ;try {

// use DecimalFormat () to take the l o c a l e in to ...account , i . e . ” understand ” a comma

value = new DecimalFormat ( ) . parse ( doc . getText ...(0 , doc . getLength ( ) ) ) . doubleValue ( ) ;

}catch ( ParseException e1 ) {

10

Page 11: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

4 QUELLCODE

System . out . p r i n t l n ( ”ParseException : ” + e1 . ...getMessage ( ) ) ;

}catch ( BadLocationException e2 ) {}

value /= adjustValue ;

/∗ va lue =(va lue > max) ? max : va lue ;va lue =(va lue < min) ? min : va lue ; ∗/

s l i d . removeChangeListener ( s l i d l i s t e n ) ;s l i d . setValue ( ( int ) Math . round ( value ) ) ;s l i d . addChangeListener ( s l i d l i s t e n ) ;

return ;}public void removeUpdate (DocumentEvent e ) {}

public void changedUpdate (DocumentEvent e ) {}} ;

setLayout (new BorderLayout ( ) ) ;// setBorder ( BorderFactory . createEmptyBorder (3 ,0 ,3 ,0) ) ;

// setBorder (UIManager . getBorder (” Tit ledBorder . border ”) ) ;

s l i d . addChangeListener ( s l i d l i s t e n ) ;t f i e l d . getDocument ( ) . addDocumentListener ( f i e l d l i s t e n ) ;s l i d . addChangeListener ( this ) ;

i f ( o r i e n t a t i o n == VERTICAL) {// s l i d . s e tPre f e r r e dS i z e (new Dimension (25 , max − min) ) ;

label . s e tHor i zonta lA l i gnment ( SwingConstants .CENTER) ;t f i e l d . s e tHor i zonta lA l i gnment ( SwingConstants .RIGHT) ;

add ( label , BorderLayout .NORTH) ;add ( s l i d , BorderLayout .CENTER) ;t f i e l d . s e tV i s i b l e ( Tex tF i e l dV i s i b l e ) ;add ( t f i e l d , BorderLayout .SOUTH) ;

}else {

// s l i d . s e tPre f e r r e dS i z e (new Dimension(max − min , s l i d . g e tPre f e r r e dS i z e ...( ) . h e i g h t ) ) ;

label . s e tP r e f e r r e dS i z e (new Dimension (label . g e tP r e f e r r edS i z e ( ) . width + 5 ,label . g e tP r e f e r r edS i z e ( ) . he i ght ) ) ;

label . s e tVer t i ca lA l i gnment ( SwingConstants .TOP) ;label . s e tHor i zonta lA l i gnment ( SwingConstants .LEADING) ;t f i e l d . s e tHor i zonta lA l i gnment ( SwingConstants .RIGHT) ;

add ( label , BorderLayout .LINE START) ;add ( s l i d , BorderLayout .CENTER) ;t f i e l d . s e tV i s i b l e ( Tex tF i e l dV i s i b l e ) ;add ( t f i e l d , BorderLayout .LINE END) ;

}}

public int getValue ( ) {return s l i d . getValue ( ) ;

}

public void setValue ( int value ) {s l i d . setValue ( value ) ;

}

public boolean getVa lueI sAdjus t ing ( ) {return s l i d . getVa lueI sAdjus t ing ( ) ;

}

11

Page 12: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

4 QUELLCODE

public int getMaximum () {return s l i d . getMaximum () ;

}

public void setMaximum( int value ) {s l i d . setMaximum( value ) ;

}

public int getMinimum() {return s l i d . getMinimum() ;

}

public void setMinimum ( int value ) {s l i d . setMinimum ( value ) ;

}

public void s e tTextF i e ldEdi tab l e (boolean e d i t a b l e ) {t f i e l d . s e tEd i t ab l e ( e d i t a b l e ) ;

}

public boolean getTextF i e ldEdi tab l e ( ) {return t f i e l d . i s Ed i t a b l e ( ) ;

}

public void s e tTex tF i e l dV i s i b l e (boolean v i s i b l e ) {TextF i e l dV i s i b l e = v i s i b l e ;t f i e l d . s e tV i s i b l e ( v i s i b l e ) ;

}

public boolean ge tTex tF i e l dV i s i b l e ( ) {return TextF i e l dV i s i b l e ;

}

/∗∗∗ @param s Se t s the s t r i n g t ha t i s used to format the va lue t ha t i s shown in ...

t he TextFie ld .∗ <p>∗ The d e f a u l t i s ”%.0 f ” .∗/

public void setTextFie ldFormatStr ing ( Str ing s ) {f o rmatStr ing = s ;

}

/∗∗∗ @return Returns the s t r i n g t ha t i s used to format the va lue t ha t i s shown ...

in the TextFie ld .∗/

public Str ing getTextFie ldFormatStr ing ( ) {return f o rmatStr ing ;

}

/∗∗∗ I f you don ’ t want the TextFie ld do show the same va lue as the S l ider , you ...

can∗ ad j u s t i t by mu l t i p l y i n g with va lue .∗ The TextFie ld w i l l then always show the va lue∗ t e x t f i e l d −va lue = s l i d e r−va lue ∗ <b> va lue </b>.∗ <p>∗ The d e f a u l t i s <b> va lue </b> = 1.0 , which means , no ad j u s t i n g .∗∗/

public void setTextFie ldAdjustValue (double value ) {i f ( value != 0 .0 && ! Double . i s I n f i n i t e ( value ) && ! Double . isNaN( value ) )

adjustValue = value ;t f i e l d . setText ( Str ing . format ( formatStr ing , Double . valueOf ( s l i d . ...

getValue ( ) ∗ adjustValue ) ) ) ;}

/∗∗∗ @return va lue = t e x t f i e l d −va lue / s l i d e r−va lue ;∗ <p>∗ see {@link se tTex tFie ldAdjus tVa lue}

12

Page 13: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

4 QUELLCODE

∗/public double getTextFie ldAdjustValue ( ) {

return adjustValue ;}

/∗∗∗ Se t s a s i z e f o r the capt ion .∗ Only u s e f u l i f more than one Tex tF i e l d S l i d e r are used , so the s l i d e r s∗ can a l i gn under/next to each other∗∗ @param newDimension the capt ion ’ s new s i z e in p i x e l s∗/

public void s e tCapt i onS i ze ( Dimension newDimension ) {label . s e tP r e f e r r e dS i z e ( newDimension ) ;

}

/∗∗∗ Returns the capt ion ’ s s i z e .∗ Use fu l i f more than one Tex tF i e l d S l i d e r are used , so the s l i d e r s∗ can a l i gn under/next to each other∗∗ @param newDimension the capt ion ’ s new s i z e in p i x e l s∗/

public Dimension getCapt i onS i ze ( ) {return label . g e tP r e f e r r edS i z e ( ) ;

}

public void s e tPa intTi cks (boolean arg0 ) {s l i d . s e tPa intTi cks ( arg0 ) ;

}

public boolean getPa intTi cks ( ) {return s l i d . getPa intTi cks ( ) ;

}

public void setMajorTickSpacing ( int n) {s l i d . setMajorTickSpacing (n) ;

}

public int getMajorTickSpacing ( ) {return s l i d . getMajorTickSpacing ( ) ;

}

public void setMinorTickSpacing ( int n) {s l i d . setMinorTickSpacing (n) ;

}

public int getMinorTickSpacing ( ) {return s l i d . getMinorTickSpacing ( ) ;

}

public void setEnabled (boolean enabled ) {super . setEnabled ( enabled ) ;label . setEnabled ( enabled ) ;s l i d . setEnabled ( enabled ) ;t f i e l d . setEnabled ( enabled ) ;

}

ChangeListener change l i s t en ;boolean doesL i s ten = fa l se ;

public void addChangeListener ( ChangeListener c l ) {change l i s t en = c l ;doesL i s ten = true ;

}

public void stateChanged (ChangeEvent e ) {i f ( doesL i s ten ) {

change l i s t en . stateChanged (new ChangeEvent ( this ) ) ;}

13

Page 14: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

4 QUELLCODE

}

}

Listing 3: Erstellt den 2. Tab/∗∗∗ This f i l e (DrawPanelIn3D . java ) i s par t o f t he Euler Angle Projec t∗∗ requ i red f i l e s : TUShape . java∗∗ used by : MainFrame . java∗∗ −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−∗ Hier be f inden s i c h f a s t a l l e Zeichenrout inen . Das Drawpanel i s t vom Typ JPanel , ...

e r s t e l l t e in JLabel ueber∗ die Gesamte Groesse und s e t z t dorthinen ein BufferedImage . Vom BufferedImage kann ...

d i e Graphics2D Ze ichenk lasse∗ g e ho l t werden . d i e Funktion paintComponent ( Graphics g ) wird von repain t ( ) au fgeru fen ...

. Dort be f inden s i c h

∗ dann a l l e noe t i gen ze i chen funk t ionen . ( das Bi ld wird fA 1

4r j e de s neue frame schwarz ...

A 1

4bermalt , dann neu g e z e i c hne t )

∗Ausserdem kann h i e r d i e Animation g e s t a r t e t werden in dem das Objekt um die ...EulerWinkel gedreht wird .

∗∗ @author Simon Kraeusel∗/

package ni ceGraph i cs ;

import java . awt . ∗ ;import java . awt . event . ∗ ;import java . awt . geom . GeneralPath ;import java . awt . image . ∗ ;import javax . swing . ∗ ;// import javax . swing . event . ∗ ;

public class DrawPanelIn3D extends JPanel implements Act i onL i s tener , MouseListener , ...MouseMotionListener{

/∗∗∗∗/

private stat ic f ina l long s e r i a lVer s i onUID = 1L ;private BufferedImage image ; // remembers drawing commands

private Graphics2D g2 ;private JLabel p i c tu r e ;private Str ing text=”dummy” ;

private int previousMousePosit ionX =0;private int previousMousePosit ionY =0;private boolean button1Pressed = true ;private boolean button2Pressed = fa l se ;private boolean button3Pressed = fa l se ;public boolean t e s t e r=fa l se ;private TUShape tu = new TUShape ( ) ;

public stat ic f ina l int DELAY = 500 ;

private boolean l a b e l i s V i s i b l e = fa l se ;private Str ing label = ”” ;

public stat ic void main ( Str ing [ ] a rgs ) {javax . swing . Sw i n gU t i l i t i e s . invokeLater (new Runnable ( ) {

public void run ( ) {createAndShowGUI ( ) ;

}}) ;

14

Page 15: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

4 QUELLCODE

}private stat ic void createAndShowGUI ( ) {

JFrame frame = new JFrame( ”SHAPES” ) ;frame . s e tDefau l tC loseOperat i on ( JFrame .EXIT ON CLOSE) ;

DrawPanelIn3D thePanel = new DrawPanelIn3D (600 ,600) ;

frame . setContentPane ( thePanel ) ;frame . pack ( ) ;frame . s e tV i s i b l e ( true ) ;}

public DrawPanelIn3D ( int xSize , int yS i ze ) {

this . image = new BufferedImage ( xSize , ySize , BufferedImage . ...TYPE INT ARGB) ;

this . s e tP r e f e r r e dS i z e (new Dimension ( xSize , yS i ze ) ) ;this . setBackground ( Color .BLACK) ;this . p i c tu r e = new JLabel (new ImageIcon ( image ) ) ;this . p i c tu r e . s e tV i s i b l e ( true ) ;this . p i c tu r e . setBackground ( Color .BLACK) ;this . add ( p i c tu r e ) ;this . g2 = ( Graphics2D ) image . getGraphics ( ) ;this . g2 . s e tCo lor ( Color .BLACK) ;new Timer (DELAY, this ) . s t a r t ( ) ; // f i r e s the ac t i onL i s t ene r every ha l f secondthis . addMouseMotionListener( this ) ;this . addMouseListener ( this ) ;

}

/∗∗∗ s e t s the eu l e r ang le s f o r the TUShapes coord inate system∗ ( a coord inate system embedded in a Coordinate System tha t can be ro t a t e d by ...

mouse input )∗ @param phi∗ @param the t a∗ @param ps i∗/

public void s e tEu l erAng l es (double phi , double theta , double ps i ) {tu . s e tEu l erAng l es ( phi , theta , p s i ) ;r epa i n t ( ) ;

}

/∗∗∗ s e t s the Orig in o f the coord inate Systems in which tuShape i s drawn∗ @param x∗ @param y∗ @param z∗/

public void setCOSOrigin ( int x , int y , int z ) {tu . s e tOr i g i n (x , y , z ) ;this . r epa i n t ( ) ;

}

/∗∗∗ i s c a l l e d by the repain t command and draws e v e r y t h i ng t ha t i s necessary .∗ I t a l s o c a l l s t he super func t ion . Maybe i t would be b e t t e r to draw ...

e v e r y t h i ng with the input parameter∗ g ins t ead of c a l l i n g the graphic s g2 o f the bu f f e r e d image to draw the 3d ...

Shapes ?But again , I th ink i t∗ would bypass then the whole Graphics2D bui sness o f the bu f f e r e d image , ...

s ince the g i s only Graphics .∗ g i s used to draw the whole c l a s s ( extended JPanel ) , whi l e buf feredImage −> ...

Graphics2D would use new ,∗ b e t t e r drawingcommands .∗/

public void paintComponent ( Graphics g ) {super . paintComponent ( g ) ;

g2 . s e tCo lor ( Color . b lack ) ;g2 . f i l l R e c t (0 , 0 , 600 , 600) ;g2 . s e tCo lor ( Color . white ) ;

15

Page 16: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

4 QUELLCODE

tu . drawDashedLine ( g2 , Color . red ) ;g2 . s e tS t r oke (new Bas i cStroke (2 , Bas i cStroke .CAP BUTT, Bas i cStroke . ...

JOIN ROUND) ) ;tu . drawEulerMovedCoordinateSystem (g2 , Color . red ) ;

tu . drawCoordinateSystem ( g2 , Color . green ) ;g2 . s e tCo lor ( Color . white ) ;g2 . s e tS t r oke (new Bas i cStroke ( ) ) ;tu . drawTUShape ( ( Graphics2D ) g2 ) ;i f ( t e s t e r ) {

this . drawAngleRep ( ) ;tu . drawAngleLabel ( g2 ) ;

}

i f ( l a b e l i s V i s i b l e ) {g2 . s e tCo lor ( Color .WHITE) ;g2 . drawString ( label , 10 , image . getHeight ( ) − 25) ;

}

//g2 . drawStr ing (”\u03c6 ” , 20 , 50) ;

/∗ g2 . se tCo lor ( Color . l i gh tGray ) ;g2 . f i l l R e c t (10 , 10 , 250 , 20) ;g2 . se tCo lor ( Color . b l a c k ) ;g2 . drawStr ing ( t ex t ,25 ,25) ; ∗/

}

public void s e tLabe l ( Str ing l l a b e l , boolean s e tV i s i b l e ) {l a b e l i s V i s i b l e = s e tV i s i b l e ;this . label = l l a b e l ;

}

public Graphics2D getTheGraphics ( ) {return this . g2 ;

}

/∗∗∗ can be used to ge t the image d i r e c t l y in order to a l t e r i t p i x e l by p i x e l ...

ins t ead through the∗ graphics2D c l a s s∗ @return∗/

public BufferedImage getImage ( ) {return this . image ;

}

public void p i c t u r eV i s i b l e (boolean x ){this . p i c tu r e . s e tV i s i b l e (x ) ;

}

public void setImage ( BufferedImage g l o ) {this . remove ( p i c tu r e ) ;this . p i c tu r e = new JLabel (new ImageIcon ( g l o ) ) ;this . p i c tu r e . s e tV i s i b l e ( true ) ;this . add ( p i c tu r e ) ;

}

public void act ionPer formed ( ActionEvent e ) {this . r epa i n t ( ) ;

}

public void mouseClicked (MouseEvent arg0 ) { text+=”CLicked ” ; r epa i n t ( ) ; }public void mouseEntered(MouseEvent arg0 ) { text=”Enterd” ;}public void mouseExited (MouseEvent arg0 ) { text=”Exited ” ;}public void mousePressed (MouseEvent arg0 ) {

i f ( arg0 . getButton ( )==MouseEvent .BUTTON1) {text=”Pressed , MousePosition s tor ed ”+arg0 . getButton ( )+” ”+ ...

MouseEvent .BUTTON1; r epa i n t ( ) ;previousMousePosit ionX=arg0 . getX ( ) ;previousMousePosit ionY=arg0 . getY ( ) ;

16

Page 17: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

4 QUELLCODE

this . button1Pressed=true ;} else i f ( arg0 . getButton ( )==MouseEvent .BUTTON3) {

previousMousePosit ionX=arg0 . getX ( ) ;previousMousePosit ionY=arg0 . getY ( ) ;text=”Pressed , MousePosition s tor ed ”+” 3” ; r epa i n t ( ) ;this . button3Pressed=true ;

} else i f ( arg0 . getButton ( )==MouseEvent .BUTTON2) {previousMousePosit ionX=arg0 . getX ( ) ;previousMousePosit ionY=arg0 . getY ( ) ;text=”Pressed , MousePosition s tor ed ”+” 2” ; r epa i n t ( ) ;this . button2Pressed=true ;

} else {text=”Pressed , MousePosition not s tor ed ” + arg0 . getButton ( ) ; ...

r epa i n t ( ) ;this . button1Pressed=fa l se ;this . button3Pressed=fa l se ;

}

}public void mouseReleased (MouseEvent arg0 ) {

i f ( arg0 . getButton ( )==MouseEvent .BUTTON1) {text=”Released ” ; r epa i n t ( ) ;previousMousePos itionX =0; previousMousePosit ionY =0;this . button1Pressed=fa l se ;

} else i f ( arg0 . getButton ( )==MouseEvent .BUTTON3) {this . button3Pressed=fa l se ;

} else i f ( arg0 . getButton ( )==MouseEvent .BUTTON2) {this . button2Pressed=fa l se ;

} else {text=”wrong button Released ” ; r epa i n t ( ) ;

}}

public void mouseDragged (MouseEvent arg0 ) {i f ( ( /∗ but ton1Pressed&&∗/ button3Pressed ) | | this . button2Pressed ) {

// in t mouseMovementX=arg0 . getX ()−previousMousePosit ionX ;int mouseMovementY=arg0 . getY ( )−this . previousMousePosit ionY ;previousMousePosit ionX=arg0 . getX ( ) ;previousMousePosit ionY=arg0 . getY ( ) ;tu . t r a n s l a t eO r i g i n (0 , mouseMovementY ∗2 , 0) ;r epa i n t ( ) ;

} else i f ( button1Pressed ) {int mouseMovementX=arg0 . getX ( )−previousMousePosit ionX ;int mouseMovementY=arg0 . getY ( )−this . previousMousePosit ionY ;previousMousePosit ionX=arg0 . getX ( ) ;previousMousePosit ionY=arg0 . getY ( ) ;tu . rotateX (0 . 005∗mouseMovementY ) ;tu . r otateZ (0 . 005∗mouseMovementX ) ;this . r epa i n t ( ) ;t ext=”Dragged” ;

} else {text=”wrong button Dragged ”+arg0 . getButton ( ) ; this . r epa i n t ( ) ;

}}public void mouseMoved (MouseEvent arg0 ) {

text=”moved” ; r epa i n t ( ) ;}

Animation anim ;

/∗∗∗ S t ar t s the animation f o r the eu l e r ang le s !∗ @param angle1 : measured in radiant ( phi )∗ @param angle2 : measured in radiant ( t he t a )∗ @param angle3 : measured in radiant ( p s i )∗/

public void startAnimation (double angle1 , double angle2 , double angle3 ) {anim = new Animation ( angle1 , angle2 , angle3 , tu , this ) ;new Thread ( anim ) . s t a r t ( ) ;

}public void stopAnimation ( ) {

17

Page 18: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

4 QUELLCODE

anim . stop ( ) ;}public void drawAngleRep ( ) {

for ( int i = 0 ; i < 3 ; i++) {i f ( tu . getAngleRep ( i ) !=null ) {

Dimension [ ] po ints = tu . getAngleRep ( i ) ;GeneralPath po l y l i n e = new GeneralPath ( ) ;p o l y l i n e . moveTo ( po ints [ 0 ] . width , po ints [ 0 ] . he i ght ) ;for ( int index = 1 ; index < po ints . l ength ; index++ ) {

po l y l i n e . l ineTo ( po ints [ index ] . width , po ints [ index ] . h e i ght ) ...;

} ;g2 . s e tCo lor ( Color . red ) ;g2 . draw ( po l y l i n e ) ;}

}

}

}class Animation implements Runnable , Act i onL i s tener {

private double phi , theta , p s i ;private TUShape theShape ;private DrawPanelIn3D var ;private Timer t imer=new Timer (50 , this ) ;private double speed =0.02;private int time=0;

public Animation (double angle1 , double angle2 , double angle3 , TUShape tus , ...DrawPanelIn3D a ) {

phi=angle1 ;p s i=angle3 ;theta=angle2 ;theShape=tus ;var=a ;

}

public void run ( ) {theShape . c r eateVi sua lAng l eRepre sentat i ons ( ) ;t imer . s t a r t ( ) ;

}public void stop ( ) {

// var . t e s t e r=f a l s e ;t imer . s top ( ) ;

}private void i n t e r r up t ( int time ) {

try {t imer . wait ( time ) ;

} catch ( Inter ruptedExcept i on e ) {e . pr intStackTrace ( ) ;

}}

public void act ionPer formed ( ActionEvent arg0 ) {int endTime1=( int ) ( phi / speed ) ;int endTime2=( int ) ( theta / speed )+endTime1 ;int endTime3=( int ) ( p s i / speed )+endTime2 ;i f ( time<=endTime1) {

theShape . s e tEu l erAng l es (0 , 0 , time ∗ speed ) ;theShape . addPointToVisualAngle (0) ;var . r epa i n t ( ) ;

} else i f ( time<=endTime2) {theShape . addPointToVisualAngle (1) ;theShape . s e tEu l erAng l es (0 , ( time−endTime1) ∗ speed , phi ) ;var . r epa i n t ( ) ;

} else i f ( time<=endTime3) {theShape . addPointToVisualAngle (2) ;theShape . s e tEu l erAng l es ( ( time−endTime2) ∗ speed , theta , phi ) ;var . r epa i n t ( ) ;

} else {

18

Page 19: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

4 QUELLCODE

stop ( ) ;}time++;i f ( time%5==0){

var . t e s t e r=true ; // var . drawAngleRep() ;}

}

}

Listing 4: Zum Zeichnen der diskreten Verteilung/∗∗∗ This f i l e (TUShape . java ) i s par t o f t he Euler Angle Projec t∗∗ requ i red f i l e s :∗∗ used by : DrawPanelIn3D . java∗∗ −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−∗Hier be f inden s i c h a l l e Koordinatentransformat ionen . Es Ex i s t i e r en 4 ...

Koordinatensysteme . 3 Davon sind 3∗Dimensional , das v i e r t e i s t das der Graphics2D S c h n i t t s t e l l e ( Vorsicht : l i n k shaend i g e s ...

KOS) .∗KOS 1: Hierin Befinden s i c h a l l e Punkte der TUShape sowie d i e roten ...

KoordinatenVektoren(mitsamt der l a b e l ) .∗ Es kann r e l a t i v zu KOS2 mit H i l f e der Euler winke l gedreht werden . ...

Dazu werden a l l e d r e i Winkel∗ mit den Fi e l d s phi , ps i , t h e t a g e spe i c he r t . Damit kann dann j ede r Punkt ...

d i e s e s KOS A 1

4ber d i e Funktion

∗ transformPointToOtherCOS (Vector3D ) in das KOS 2 A 1

4berfA 1

4hrt werden !

∗KOS 2: Hierin be f inden s i c h d ie grA 1

4nen Koordinatenvektoren samt Labe l sowie d i e ...

V i sua l i s i e rungen der 3∗ Winkel ( d i e roten Kreise b e i der Animation , we lche aus 2 b i s 157 ...

Punkten bes t ehen ) . Die Ausrichtung∗ Dieses KOS wird mit H i l f e der Transformationsmatrix coSy [ ] [ ] ...

g e spe i c he r t . A l l e Punkte kA¶nnen mit

∗ der Funktion transformCOS (Vector3D ) in das KOS 3 A 1

4berfA 1

4hrt werden .

∗ Weiterhin kann A 1

4ber d i e ro t a t e Funktionen jede andere Klasse d i e s e s ...

KOS ro t i e r en l a s s en

∗ ( Rotat ionsaxen kA¶nnen um kons tante werde verschoben werden durch das ...F ie ld ROT AXIS) .

∗KOS 3: Dieses KOS i s t das unveraenderbare Ine r t i a l s y s t em . Hierhin muessen a l l e ...Vektoren t ran s f o rmi e r t werden

∗ um auf das 2−dim KOS 4 p r o j e z i e r t zu werden ! Die Pro j e k l t i on ...uebernimmt transformPoint (Vector3D )

∗∗ @author Simon Kraeusel∗/

package ni ceGraph i cs ;

import java . awt . Bas i cStroke ;import java . awt . Color ;import java . awt . Dimension ;import java . awt . Graphics2D ;import java . awt . geom . GeneralPath ;import java . u t i l . Vector ;

public class TUShape {private double coSy [ ] [ ] = new double [ 3 ] [ 3 ] ; // t h i s i s t he t rans format ion matrix ...

between the two COSprivate stat ic Vector3D T POINTS [ ] [ ] = new Vector3D [ 2 ] [ 8 ] ; // t h i s c r e a t e s the Tprivate stat ic Vector3D U POINTS [ ] [ ] =new Vector3D [ 2 ] [ 8 ] ; // t h i s c r e a t e s the Uprivate stat ic Vector3D ROT AXIS=new Vector3D (100 ,100 , 100) ; // the poin t where ...

t he two ro t a t i on ax i s Meet ( around x and z )private Vector3D o r i g i n = new Vector3D (0 , 0 , 0 ) ; // t r an s l a t i on to coord inate ...

System in which TU i s ro t a t e dprivate double phi =0;//Euler ang le s

19

Page 20: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

4 QUELLCODE

private double theta =0;private double ps i =0;

public TUShape ( ) {coSy [ 0 ] [ 0 ] = 1 ; coSy [ 0 ] [ 1 ] = 0 ; coSy [ 0 ] [ 2 ] = 0 ; // t h i s i s t he t rans format ion ...

matrix between the two COScoSy [ 1 ] [ 0 ] = 0 ; coSy [ 1 ] [ 1 ] = 1 ; coSy [ 1 ] [ 2 ] = 0 ;coSy [ 2 ] [ 0 ] = 0 ; coSy [ 2 ] [ 1 ] = 0 ; coSy [ 2 ] [ 2 ] = 1 ;

T POINTS [ 0 ] [ 0 ]=new Vector3D (0 ,0 , 100) ;T POINTS [ 0 ] [ 1 ]=new Vector3D (0 ,0 , 60) ;T POINTS [ 0 ] [ 2 ]=new Vector3D (40 ,0 , 60) ;T POINTS [ 0 ] [ 3 ]=new Vector3D (40 ,0 , 0 ) ;T POINTS [ 0 ] [ 4 ]=new Vector3D (80 ,0 , 0 ) ;T POINTS [ 0 ] [ 5 ]=new Vector3D (80 ,0 , 60) ;T POINTS [ 0 ] [ 6 ]=new Vector3D (120 ,0 , 60) ;T POINTS [ 0 ] [ 7 ]=new Vector3D (120 ,0 , 100) ;for ( int i = 0 ; i < T POINTS [ 1 ] . l ength ; i++) {

T POINTS [ 1 ] [ i ]=new Vector3D (T POINTS [ 0 ] [ i ] . X, 40 ,T POINTS [ 0 ] [ i ...] . Z) ;

}U POINTS[ 0 ] [ 0 ]=new Vector3D (150 ,0 , 100) ;U POINTS[ 0 ] [ 1 ]=new Vector3D (150 ,0 , 0 ) ;U POINTS[ 0 ] [ 2 ]=new Vector3D (270 ,0 , 0 ) ;U POINTS[ 0 ] [ 3 ]=new Vector3D (270 ,0 , 100) ;U POINTS[ 0 ] [ 4 ]=new Vector3D (230 ,0 , 100) ;U POINTS[ 0 ] [ 5 ]=new Vector3D (230 ,0 , 40) ;U POINTS[ 0 ] [ 6 ]=new Vector3D (190 ,0 , 40) ;U POINTS[ 0 ] [ 7 ]=new Vector3D (190 ,0 , 100) ;for ( int i = 0 ; i < U POINTS [ 1 ] . l ength ; i++) {

U POINTS [ 1 ] [ i ]=new Vector3D (U POINTS [ 0 ] [ i ] . X, 40 ,U POINTS [ 0 ] [ i ...] . Z) ;

}this . r o tateZ(−Math . PI ∗2 .0

/3 . 0 ) ;this . rotateX ( 0 . 5 ) ;this . s e tOr i g i n (−50 , 300 , 0) ;

}

/∗∗∗ r o t a t e s around eu l e r ang le s ! in ZYZ notat ion .∗ @param poin t∗ @return∗/

private Vector3D transformPointToOtherCOS ( Vector3D point ) {Vector3D temp1=new Vector3D (0 , 0 , 0 ) ;Vector3D temp2=new Vector3D (0 , 0 , 0 ) ;temp1 . setX ( ( int ) ( point .X∗Math . cos ( phi )−point .Y∗Math . s i n ( phi ) ) ) ;temp1 . setY ( ( int ) ( point .X∗Math . s i n ( phi )+point .Y∗Math . cos ( phi ) ) ) ;temp1 . setZ ( point . Z) ;

temp2 . setX ( ( int ) ( temp1 .X∗Math . cos ( theta )+temp1 . Z∗Math . s i n ( theta ) ) ) ;temp2 . setY ( temp1 .Y) ;temp2 . setZ ( ( int )(−temp1 .X∗Math . s i n ( theta )+temp1 .Z∗Math . cos ( theta ) ) ) ;

temp1 . setX ( ( int ) ( temp2 .X∗Math . cos ( p s i )−temp2 .Y∗Math . s i n ( p s i ) ) ) ;temp1 . setY ( ( int ) ( temp2 .X∗Math . s i n ( p s i )+temp2 .Y∗Math . cos ( p s i ) ) ) ;temp1 . setZ ( temp2 . Z) ;

return temp1 ;}

public void drawDashedLine ( Graphics2D g , Color c ) {f loat dash1 [ ] = {10.0 f } ;

Bas i cStroke dashed = new Bas i cStroke (1 . 0 f ,Bas i cStroke .CAP BUTT,Bas i cStroke . JOIN MITER,10 . 0 f , dash1 , 0 . 0 f ) ;

g . s e tS t r oke ( dashed ) ;double temp = phi ;phi =0;

20

Page 21: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

4 QUELLCODE

Dimension zero=trans formPoint ( transformCOS( transformPointToOtherCOS (new ...Vector3D (0 , 0 , 0 ) ) ) ) ;

Dimension eY = trans formPoint ( transformCOS( transformPointToOtherCOS (new ...Vector3D (0 ,200 , 0) ) ) ) ;

g . s e tCo lor ( c ) ;g . drawLine ( zero . width , zero . height , eY . width , eY . he i gh t ) ;phi=temp ;

}public void s e tEu l erAng l es (double z1 , double x , double z2 ) {

this . phi=z1 ;this . theta=x ;this . p s i=z2 ;

}public void drawEulerMovedCoordinateSystem ( Graphics2D g , Color c ) {

g . s e tCo lor ( c ) ;Dimension zero=trans formPoint ( transformCOS( transformPointToOtherCOS ( ...

new Vector3D (0 , 0 , 0 ) ) ) ) ;Dimension eX = trans formPoint ( transformCOS( transformPointToOtherCOS ( ...

new Vector3D (200 ,0 , 0 ) ) ) ) ;Dimension eY = trans formPoint ( transformCOS( transformPointToOtherCOS ( ...

new Vector3D (0 ,200 , 0) ) ) ) ;Dimension eZ = trans formPoint ( transformCOS( transformPointToOtherCOS ( ...

new Vector3D (0 ,0 , 200) ) ) ) ;g . drawLine ( zero . width , zero . height , eX . width , eX . he i gh t ) ;g . drawLine ( zero . width , zero . height , eY . width , eY . he i gh t ) ;g . drawLine ( zero . width , zero . height , eZ . width , eZ . he i gh t ) ;g . drawString ( ”X” , eX . width , eX . he i ght ) ;g . drawString ( ”Y” , eY . width , eY . he i ght ) ;g . drawString ( ”Z” , eZ . width , eZ . he i ght ) ;

}public void drawCoordinateSystem ( Graphics2D g , Color c ) {

g . s e tCo lor ( c ) ;Dimension zero=trans formPoint ( transformCOS(new Vector3D (0 , 0 , 0 ) ) ) ;Dimension eX = trans formPoint ( transformCOS(new Vector3D (200 ,0 , 0 ) ) ) ;Dimension eY = trans formPoint ( transformCOS(new Vector3D (0 ,200 , 0) ) ) ;Dimension eZ = trans formPoint ( transformCOS(new Vector3D (0 ,0 , 200) ) ) ;g . drawLine ( zero . width , zero . height , eX . width , eX . he i gh t ) ;g . drawLine ( zero . width , zero . height , eY . width , eY . he i gh t ) ;g . drawLine ( zero . width , zero . height , eZ . width , eZ . he i gh t ) ;g . drawString ( ”X” , eX . width , eX . he i ght ) ;drawI ( g , eX . width+7, eX . he i ght+3) ;g . drawString ( ”Y” , eY . width , eY . he i ght ) ;drawI ( g , eY . width+7, eY . he i ght+3) ;g . drawString ( ”Z” , eZ . width , eZ . he i ght ) ;drawI ( g , eZ . width+7, eZ . he i ght+3) ;

}private void drawI ( Graphics2D g , int x , int y ){

g . drawLine (x , y , x+5, y ) ;g . drawLine (x , y−8, x+5, y−8) ;g . drawLine (x+3, y−1, x+3, y−7) ;

}public void s e tOr i g i n ( int x , int y , int z ) {

o r i g i n . setX (x ) ;o r i g i n . setY (y ) ;o r i g i n . setZ ( z ) ;

}public void t r a n s l a t eO r i g i n ( int x , int y , int z ) {

o r i g i n .X+=x ;o r i g i n .Y+=y ;o r i g i n . Z+=z ;

}

private Vector3D transformCOS( Vector3D a ) {int xn=( int ) ( coSy [ 0 ] [ 0 ] ∗ ( a .X−this .ROT AXIS .X)+coSy [ 1 ] [ 0 ] ∗ ( a .Y−this . ...

ROT AXIS .Y)+coSy [ 2 ] [ 0 ] ∗ ( a . Z−this .ROT AXIS .Z) ) ;int yn=( int ) ( coSy [ 0 ] [ 1 ] ∗ ( a .X−this .ROT AXIS .X)+coSy [ 1 ] [ 1 ] ∗ ( a .Y−this . ...

ROT AXIS .Y)+coSy [ 2 ] [ 1 ] ∗ ( a . Z−this .ROT AXIS .Z) ) ;int zn=( int ) ( coSy [ 0 ] [ 2 ] ∗ ( a .X−this .ROT AXIS .X)+coSy [ 1 ] [ 2 ] ∗ ( a .Y−this . ...

ROT AXIS .Y)+coSy [ 2 ] [ 2 ] ∗ ( a . Z−this .ROT AXIS .Z) ) ;return new Vector3D (xn+o r i g i n .X, yn+o r i g i n .Y, zn+o r i g i n . Z) ;

}

21

Page 22: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

4 QUELLCODE

public void drawTUShape ( Graphics2D g ) {Dimension temp = new Dimension ( ) ;int [ ] [ ] xT = new int [ 2 ] [ 9 ] ;int [ ] [ ] yT = new int [ 2 ] [ 9 ] ;int [ ] [ ] xU = new int [ 2 ] [ 9 ] ;int [ ] [ ] yU = new int [ 2 ] [ 9 ] ;for ( int k = 0 ; k < 2 ; k++) {

for ( int i = 0 ; i < T POINTS [ k ] . l ength ; i++) {

Vector3D hula = transformCOS( transformPointToOtherCOS ( ...T POINTS [ k ] [ i ] ) ) ;

temp= trans formPoint ( hula ) ;xT [ k ] [ i ]=temp . width ;yT [ k ] [ i ]=temp . he i ght ;

Vector3D hulahula = transformCOS( ...transformPointToOtherCOS (U POINTS[ k ] [ i ] ) ) ;

temp= trans formPoint ( hulahula ) ;xU [ k ] [ i ]=temp . width ;yU [ k ] [ i ]=temp . he i ght ;

}

xT [ k ] [ 8 ]=xT [ k ] [ 0 ] ;yT [ k ] [ 8 ]=yT [ k ] [ 0 ] ;g . drawPolygon (xT [ k ] , yT [ k ] , 8) ;xU [ k ] [ 8 ]=xU [ k ] [ 0 ] ;yU [ k ] [ 8 ]=yU [ k ] [ 0 ] ;g . drawPolygon (xU [ k ] , yU [ k ] , 8) ;

}for ( int i = 0 ; i < T POINTS [ 0 ] . l ength ; i++) {

g . s e tCo lor ( Color . white ) ;g . drawLine (xT [ 0 ] [ i ] , yT [ 0 ] [ i ] , xT [ 1 ] [ i ] , yT [ 1 ] [ i ] ) ;g . drawLine (xU [ 0 ] [ i ] , yU [ 0 ] [ i ] , xU [ 1 ] [ i ] , yU [ 1 ] [ i ] ) ;

}//drawT Surface ( g ) ;

}private void drawT Surface ( Graphics2D g ) {

Sur f ace su r f a c e [ ]=new Sur f ace [ 1 1 ] ;s u r f a c e [0 ]=new Sur f ace ( this . transformCOS(T POINTS [ 0 ] [ 0 ] ) , //upper T− ...

Frontthis . transformCOS(T POINTS [ 0 ] [ 7 ] ) ,this . transformCOS(T POINTS [ 0 ] [ 6 ] ) ,this . transformCOS(T POINTS [ 0 ] [ 1 ] ) ) ;

s u r f a c e [1 ]=new Sur f ace ( this . transformCOS(T POINTS [ 0 ] [ 2 ] ) , // lower T− ...Front

this . transformCOS(T POINTS [ 0 ] [ 5 ] ) ,this . transformCOS(T POINTS [ 0 ] [ 4 ] ) ,this . transformCOS(T POINTS [ 0 ] [ 3 ] ) ) ;

s u r f a c e [2 ]=new Sur f ace ( this . transformCOS(T POINTS [ 0 ] [ 0 ] ) , //T−roo fthis . transformCOS(T POINTS [ 1 ] [ 0 ] ) ,this . transformCOS(T POINTS [ 1 ] [ 7 ] ) ,this . transformCOS(T POINTS [ 0 ] [ 7 ] ) ) ;

s u r f a c e [3 ]=new Sur f ace ( this . transformCOS(T POINTS [ 0 ] [ 1 ] ) , //upper T− ...bottom

this . transformCOS(T POINTS [ 0 ] [ 6 ] ) ,this . transformCOS(T POINTS [ 1 ] [ 6 ] ) ,this . transformCOS(T POINTS [ 1 ] [ 1 ] ) ) ;

s u r f a c e [4 ]=new Sur f ace ( this . transformCOS(T POINTS [ 0 ] [ 3 ] ) , // lower T− ...bottom

this . transformCOS(T POINTS [ 1 ] [ 3 ] ) ,this . transformCOS(T POINTS [ 1 ] [ 4 ] ) ,this . transformCOS(T POINTS [ 0 ] [ 4 ] ) ) ;

s u r f a c e [5 ]=new Sur f ace ( this . transformCOS(T POINTS [ 1 ] [ 0 ] ) , //upper T− ...back

this . transformCOS(T POINTS [ 1 ] [ 7 ] ) ,this . transformCOS(T POINTS [ 1 ] [ 6 ] ) ,this . transformCOS(T POINTS [ 1 ] [ 1 ] ) ) ;

s u r f a c e [6 ]=new Sur f ace ( this . transformCOS(T POINTS [ 1 ] [ 2 ] ) , // lower T− ...Back

this . transformCOS(T POINTS [ 1 ] [ 5 ] ) ,

22

Page 23: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

4 QUELLCODE

this . transformCOS(T POINTS [ 1 ] [ 4 ] ) ,this . transformCOS(T POINTS [ 1 ] [ 3 ] ) ) ;

s u r f a c e [7 ]=new Sur f ace ( this . transformCOS(T POINTS [ 1 ] [ 0 ] ) , // l e f t upper ...T−Side

this . transformCOS(T POINTS [ 0 ] [ 0 ] ) ,this . transformCOS(T POINTS [ 0 ] [ 1 ] ) ,this . transformCOS(T POINTS [ 1 ] [ 1 ] ) ) ;

s u r f a c e [8 ]=new Sur f ace ( this . transformCOS(T POINTS [ 1 ] [ 2 ] ) , // l e f t lower ...T−Side

this . transformCOS(T POINTS [ 0 ] [ 2 ] ) ,this . transformCOS(T POINTS [ 0 ] [ 3 ] ) ,this . transformCOS(T POINTS [ 1 ] [ 3 ] ) ) ;

s u r f a c e [9 ]=new Sur f ace ( this . transformCOS(T POINTS [ 0 ] [ 7 ] ) , // r i g h t upper ...T−Side

this . transformCOS(T POINTS [ 1 ] [ 7 ] ) ,this . transformCOS(T POINTS [ 1 ] [ 6 ] ) ,this . transformCOS(T POINTS [ 0 ] [ 6 ] ) ) ;

s u r f a c e [10]=new Sur f ace ( this . transformCOS(T POINTS [ 0 ] [ 5 ] ) , // r i g h t ...lower T−Side

this . transformCOS(T POINTS [ 1 ] [ 5 ] ) ,this . transformCOS(T POINTS [ 1 ] [ 4 ] ) ,this . transformCOS(T POINTS [ 0 ] [ 4 ] ) ) ;

Color co l [ ]=new Color [ 1 1 ] ;for ( int i = 0 ; i < co l . l ength ; i++) {

co l [ i ]=new Color (100+ i ∗10 , i ∗10 , i ∗10) ;}for ( int i = 0 ; i < s u r f a c e . l ength ; i++) {

i f ( s u r f a c e [ i ] . isOnFront ( ) ) {g . s e tCo lor ( co l [ i ] ) ;g . f i l l P o l y g o n ( su r f a c e [ i ] . getXPanelCoordinates ( ) , ...

s u r f a c e [ i ] . getYPanelCoordinates ( ) , 4) ;}

}g . s e tCo lor ( Color . white ) ;

}

private Dimension trans formPoint ( Vector3D dummy) {int xEnd=0;int yEnd=0;

yEnd = 250−( int ) ( (double)dummy . Z/(dummy .Y+1300.0) ∗1300 .0) ;xEnd =250+(int ) ( ( double)dummy .X/(dummy .Y+1300.0) ∗1300 .0) ;return new Dimension (xEnd , yEnd) ;

}public void rotateX (double x i ){

double temp1 ;double temp2 ;for ( int i = 0 ; i < 3 ; i++) {

temp1=coSy [ i ] [ 1 ] ∗Math . cos ( x i )−coSy [ i ] [ 2 ] ∗Math . s i n ( x i ) ;temp2=coSy [ i ] [ 1 ] ∗Math . s i n ( x i )+coSy [ i ] [ 2 ] ∗Math . cos ( x i ) ;coSy [ i ] [ 1 ]= temp1 ;coSy [ i ] [ 2 ]= temp2 ;

}}public void r otateZ (double phi ) {

double temp1 ;double temp2 ;for ( int i = 0 ; i < 3 ; i++) {

temp1=coSy [ i ] [ 0 ] ∗Math . cos ( phi )−coSy [ i ] [ 1 ] ∗ Math . s i n ( phi ) ;temp2=coSy [ i ] [ 0 ] ∗Math . s i n ( phi )+coSy [ i ] [ 1 ] ∗ Math . cos ( phi ) ;coSy [ i ] [ 0 ]= temp1 ;coSy [ i ] [ 1 ]= temp2 ;

}}

Vector [ ] anglesRep=new Vector [ 3 ] ;

public void cr eateVi sua lAng l eRep resenta t i ons ( ) {for ( int i = 0 ; i < anglesRep . l ength ; i++) {

anglesRep [ i ]=new Vector ( ) ;}

}

23

Page 24: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

4 QUELLCODE

public void addPointToVisualAngle ( int i ) {switch ( i ) {case 0 :

anglesRep [ 0 ] . addElement ( ( transformPointToOtherCOS (new Vector3D ...(100 , 0 , 0 ) ) ) ) ;

break ;case 1 :

anglesRep [ 1 ] . addElement ( ( transformPointToOtherCOS (new Vector3D ...(0 , 0 , 100) ) ) ) ;

break ;case 2 :

anglesRep [ 2 ] . addElement ( ( transformPointToOtherCOS (new Vector3D ...(0 , 100 , 0) ) ) ) ;

break ;}

}

public Dimension [ ] getAngleRep ( int index ) {for ( int i = 0 ; i < 3 ; i++) {

i f ( ! anglesRep [ i ] . isEmpty ( ) ) {i f ( index==i ) {

Dimension [ ] x=new Dimension [ anglesRep [ i ] . s i z e ...( ) ] ;

for ( int i n = 0 ; in < anglesRep [ i ] . s i z e ( ) ; i n ...++) {

x [ in ]= this . trans formPoint ( transformCOS ...( ( Vector3D ) anglesRep [ i ] . elementAt ...( i n ) ) ) ;

}return x ;

}}

}return null ;

}

public void drawAngleLabel ( Graphics2D g2 ) {i f ( theta >1.0/6.0∗Math . PI ){

Dimension eZ = trans formPoint ( transformCOS(new Vector3D (new Vector3D ( ( int ) (Math . cos ( p s i ) ∗30 .0) , ( int ) ( ...

Math . s i n ( p s i ) ∗30 .0) , 50) .X,new Vector3D ( ( int ) (Math . cos ( p s i ) ∗30 .0) , ( int ) ( ...

Math . s i n ( p s i ) ∗30 .0) , 50) .Y,new Vector3D ( ( int ) (Math . cos ( p s i ) ∗30 .0) , ( int ) ( ...

Math . s i n ( p s i ) ∗30 .0) , 50) . Z) ) ) ;g2 . drawString ( ”\u03d1” , eZ . width , eZ . he i ght ) ;

}i f ( ps i >1.0/6.0∗Math . PI ) {

Dimension eX = trans formPoint ( transformCOS(new Vector3D ...(50 , 20 , 0) ) ) ;

g2 . drawString ( ”\u03c6 ” , eX . width , eX . he i ght ) ;}i f ( phi >1.0/6.0∗Math . PI ) {

Dimension eZ = trans formPoint ( transformCOS( ...transformPointToOtherCOS (new Vector3D (20 ,50 , 0) ) ) ) ;

g2 . drawString ( ”\u03c8 ” , eZ . width , eZ . he i ght ) ;}

}}class Vector3D{

public int X;public int Y;public int Z ;

public Vector3D ( int x , int y , int z ) {X=x ;Y=y ;Z=z ;

}public void setX ( int x ) {

X=x ;

24

Page 25: Technische Universität Berlin Institut für Theoretische Physik · Documentation on the javaTM packet Euler angles Simon Kraeusel 15-th october 2008 Technische Universität Berlin

4 QUELLCODE

}public void setY ( int y ) {

Y=y ;}public void setZ ( int z ) {

Z=z ;}public void s e tPo int ( int x , int y , int z ) {

X=x ;Y=y ;Z=z ;

}public void t r an s l a t ePo i n t ( int x , int y , int z ) {

X+=x ;Y+=y ;Z+=z ;

}}

Listing 5: Zum darstellen der Gleichungenimport javax . swing . ∗ ;import javax . swing . event . ∗ ;import javax . swing . text . NumberFormatter ;

public class customTextField extends JFormattedTextField{

/∗∗∗∗/

private stat ic f ina l long s e r i a lVer s i onUID = 1L ;

public customTextField ( int min , int max , int s i z e , int value ) {java . text . NumberFormat numberFormat =

java . text . NumberFormat . g e t In t eg e r In s tan ce ( ) ;NumberFormatter f o rmatter = new NumberFormatter ( numberFormat ) ;f o rmatter . setMinimum (new In t eg e r (min ) ) ;f o rmatter . setMaximum(new In t eg e r (max) ) ;

this . setFormatter ( f o rmatter ) ;this . setValue (new In t eg e r ( value ) ) ;

this . setColumns ( s i z e ) ; // ge t some space}

public int value ( ) {Number value = (Number) this . getValue ( ) ;return value . intValue ( ) ;

}

}

25