Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische...

34
Documentation for java TM Applet Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit¨ at Berlin Institut f¨ ur Theoretische Physik Abstract This documentation is a manual for a Java Applet 1 , which visualizes the Carnot cycle. The Carnot cycle is shown in different phase diagrams. A container with a process gas visualizes the different phases in the cycle process. The Java-Applet Information of different probability distributions has been created within the OWL Project e-Module for Visualisations of Theoretical Physics 2 . 1 Java and all Java-based trademarks of Sum Microsystems, Inc. in the United States, other countries, or both. 2 Translated to English by Philipp Loske 19.03.2014

Transcript of Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische...

Page 1: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

Documentation for javaTM Applet

Carnot cylce

Simon Kraeusel

14th February 2008

Technische Universitat Berlin

Institut fur Theoretische Physik

Abstract

This documentation is a manual for a Java Applet1, which visualizes the Carnot cycle.The Carnot cycle is shown in different phase diagrams. A container with a process gasvisualizes the different phases in the cycle process.The Java-Applet Information of different probability distributions has been createdwithin the OWL Project e-Module for Visualisations of Theoretical Physics2.

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

2Translated to English by Philipp Loske 19.03.2014

Page 2: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

Contents

1 Introduction 3

2 Manual 42.1 Control Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.2 (P,V) - diagram (upper left corner in the main interface) . . . . . . . . . . 42.3 (T,S) - diagram (upper right corner in the main interface) . . . . . . . . . 52.4 Chart of the Carnot cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.5 (U,S,V) - diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

3 Theory 63.1 Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63.2 Efficiency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

About us

Institute for Theoretical PhysicsHardenbergstr. 36, Sekr. EW7-1

10623 Berlin

Project: Offensive Wissen durch Lernen(Knowledge through Learning)

e-Module for Visualisations of Theoretical PhysicsHead of project: Prof. Dr. Eckehard Scholl, PhD

Contact: [email protected]

Page 3: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

Figure 1: Screenshot of the main interface.

1 Introduction

This Java-Applet serves as a visualization of the Carnot cycle. To demonstrate theprocess of the Carnot cycle this applet simulates a process gas with a change in volumewhich is surrounded by two heating bathes.In addition there are several plot panels which simulate phase diagrams with differentparameters.

What this Applet is able to visualize:

• qualitative simulation of an ideal gas

• time-depending animation of the Carnot cycle

• three-dimensional plot of the Energy (U), Entropy (S) and Volume (V ) graph.

• variation of the temperature difference and manipulative view on all diagrams.

What this Applet is not able to visualize:

• quantitative parameters of the process gas (process gas with fictional speed notconsidering real speed variations)

• view on the system status in (U,S,V)-diagram, which is placed in the lower rightcorner of the main interface

• interaction between the gas particles

• realistic change in volume

Page 4: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

Figure 2: Main interface of the Carnot - Applet.

2 Manual

After starting the applet, a new window opens on the desktop. In figure 2 four panelsillustrate the Carnot cycle with different phase diagrams and a control panel betweenthe upper two plots.

2.1 Control Panel

The control panel contains an overview for the parameters (S: entropy, T: currentabsolute temperature, V: current volume, P: current pressure, Tlow, Thigh), whichdescribe the current system status. It is important to know that all parameters areused as they appear in the control panel and not transformed to physically correctunits (pseudo units).The control panel contains two buttons (“hide plot”, ”stop animation”) and a slider,too. With changing the position of the slider it is possible to change the maximumdifference in temperature (Thigh − Tlow).

2.2 (P,V) - diagram (upper left corner in the main interface)

The (P,V)-diagram simulates the systems progress in time (see Figure 3 ). Thesystem’s current position is marked with a blue point. The red curve represents the

Page 5: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

Figure 3: The (P,V) - diagram on the left and the (T,S) - diagram on the right side.

four paths in the Carnot cycle. When the difference in temperature is changed, theplot is calculated and plotted again.The scales have the same pseudo units as the control panel.

2.3 (T,S) - diagram (upper right corner in the main interface)

The (T,S) - diagram works in the same way as the (P,V) - diagram with different axes.

2.4 Chart of the Carnot cycle

This panel simulates the process gas and the two heating baths mentioned above. Theyellow box symbolizes the gas container that moves back and forth in between the cold(blue) and hot (red) heating bath (A coloured arrow shows the direction.). The size ofthe yellow box simulates a change in volume depending on the gas particles movement.The gas particle (simulated through 1500 coloured pixel) change in colour and speeddepending on the temperature. All particles have the same speed which is proportionalto the temperature. When the applet starts all particles start in a random directionand move with the same speed until they collide with one of the walls (the simulationdoes not consider the collision with other gas particles). The collision with one of thewalls is ideal (angle of incidence = angle of reflection) except for the left wall. Theparticles get ± 30◦ to their change of direction. This option has been chosen foraesthetic reasons.

2.5 (U,S,V) - diagram

The (U,S,V) - diagram, like the other diagrams, simulates the current system status.But instead of visualizing the path in the diagram, it is plotted in three-dimensions.

Page 6: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

Figure 4: Simulation of the Carnot cycle.

Figure 5: Plot of the (U,S,V) - diagram.

With clicking on the diagram and pressing the left mouse button it is possible tochange the camera position. To zoom in and out it is necessary to press both mousebuttons. On older computers it might lead to performance problems if these featuresare used while running a simulation.

3 Theory

3.1 Basics

A Carnot engine transforms heat into work in a reversible process (see Figure 6). Theaddition of heat is defined as δQ = TdS. The work W done by the machine and thequantity of heat Q1 are smaller than zero because they take energy from the system.The intrinsic energy as a state function does not change within a cycle (reversible) sothat

W +Q1 +Q2 = 0, (1)

as well as:

∆S =Q1

T1+Q2

T2= 0. (2)

Such a reversible process can be created with a four steps cycle.

Page 7: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

T1

T2Q2

-Q1

-W

Figure 6: Outlines of a Thermal Engine (T1, T2: Temperatures of the heating baths 1, b. W :work done by the machine, Q1, Q2: absorption of heat energy from the high temperaturereservoir).

Figure 7: Visualization of the (P,V)-diagram. The four steps of the thermodynamic cycle are markedwith the numbers 1-4.

1. Isothermal expansion (1 → 2 in Figure 7, Contact with high temperaturereservoir, Q2 > 0)

2. Adiabatic expansion (2 → 3, Cooling the gas, W1 < 0)

3. Isothermal compression (3 → 4, Contact with low temperature reservoir, Q1 < 0)

4. Adiabatic compression (4 → 1, Heating the gas, W2 > 0)

With W = W1 +W2 < 0, which means work done from the outside W2 is smaller thanthe work done from the system W1(|W1| > |W2|).

Page 8: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

3.2 Efficiency

The energy conversion efficiency η is defined as the fraction of absorbed heat andproduced work:

η =−WQ2

⇒ η = 1 +Q1

Q2. (3)

Equation 2 transforms for reversible processes to:

η = 1− T1T2. (4)

Page 9: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

4 Quellcode

Listing 1: Hauptklasse des Appletspackage u s e r i n t e r f a c e ;

import java . awt . Dimension ;import java . awt . event . ActionEvent ;import java . awt . event . Act i onL i s tener ;import java . text . NumberFormat ;import java . u t i l . concur r ent . TimeUnit ;import java . u t i l . concur r ent . atomic . AtomicBoolean ;

import javax . swing . BorderFactory ;import javax . swing . Box ;import javax . swing . BoxLayout ;import javax . swing . JApplet ;import javax . swing . JButton ;import javax . swing . JFrame ;import javax . swing . JLabel ;import javax . swing . JPanel ;import javax . swing . JS l i d e r ;import javax . swing . SwingConstants ;import javax . swing . Sw i n gU t i l i t i e s ;import javax . swing . event . ChangeEvent ;import javax . swing . event . ChangeListener ;

import ni ceGraph i cs . Part ic l eAnimationPane l ;

public class CarnotProcessMain extends JApplet {

private stat ic f ina l long s e r i a lVer s i onUID = 1L ;JButton drawButton , animationButton ;JLabel volume , entropy , temperatureLabel , tlowLabel , thi ghLabel , entropyLabel , ...

volumeLabel , pr es sur eLabe l ;JS l i d e r lowtemp , hightemp ;PVPlot pvplot ;TSPlot t s p l o t ;Part ic l eAnimationPane l par t i c l eBox ;Carnot3DPlot plot3D ;private boolean plotmark = true ;private vo lat i le AtomicBoolean animated = new AtomicBoolean ( true ) ;// pr i v a t e s t a t i c f i n a l doub le GAS CONSTANT = 8.314472; // in J/mol∗Kprivate stat ic f ina l double PLANCK = Math . pow(6.6260693 ,−34) ; // in J∗ s// pr i v a t e s t a t i c f i n a l doub le BOLTZMANN = Math . pow(1.3806504 ,−23) ; // in J/Kprivate stat ic f ina l double ATOMMASSUNIT = Math . pow(1 .660538782 , −27) ; // in ...

kgprotected stat ic f ina l double SOMEOTHERCONSTANT = 2.5+(2∗Math . PI∗ ...

ATOMMASSUNIT)/Math . pow(PLANCK,2 ) ;protected stat ic f ina l double kappa = 5 . 0 / 3 ; // ad i aba t i c exponent f o r i d e a l ...

gasstat ic NumberFormat nf = NumberFormat . g e t In t eg e r In s tanc e ( ) ;private f ina l stat ic double HIGH INIT TEMP = 255 ;private f ina l stat ic double LOW INIT TEMP = 0.8∗HIGH INIT TEMP ;private double T1 = LOW INIT TEMP;private double T2 = HIGH INIT TEMP ;private double v1 = 5 0 . ;private double v2 = 70 ;stat ic f ina l int PRECISION = 240 ; //IMPORTANT 4 must d i v i d e PRECISION ! ! ! !private vo lat i le AnimationManager animationManager ;

/∗∗

9

Page 10: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

∗ I n i t s t he Applet−GUI: c r ea t e s 4 empty p l o t p an e l s and var ious l a b e l to ...d i s p l ay the

∗ thermodynamic v a r i a b l e s .∗∗/

public CarnotProcessMain ( ) {

volume = new JLabel ( ”Vol= XX” ) ;entropy = new JLabel ( ”Vol= ZZ” ) ;

JPanel mainpanel = new JPanel ( ) ,upperpanel = new JPanel ( ) ,l owerpane l = new JPanel ( ) ,ad jus tpane l = new JPanel ( ) ,v a r i a b l e s = new JPanel ( ) ;

v a r i a b l e s . setLayout (new BoxLayout ( va r i ab l e s , BoxLayout .PAGE AXIS) ) ;ad jus tpane l . setLayout (new BoxLayout ( ad jus tpane l , BoxLayout . LINE AXIS) ) ...

;l owerpane l . setLayout (new BoxLayout ( lowerpanel , BoxLayout . LINE AXIS) ) ;upperpanel . setLayout (new BoxLayout ( upperpanel , BoxLayout . LINE AXIS) ) ;mainpanel . setLayout (new BoxLayout ( mainpanel , BoxLayout .PAGE AXIS) ) ;// s e tR e s i z a b l e ( t rue ) ;

drawButton = new JButton ( ” hide p l o t s ” ) ;animationButton = new JButton ( ” stop animation ” ) ;pvplot = new PVPlot (T1 ,T2 , v1 , v2 ) ;t s p l o t = new TSPlot (T1 ,T2 , v1 , v2 ) ;par t i c l eBox = new Partic l eAnimationPane l (350 , 300) ;plot3D = new Carnot3DPlot (T1 ,T2 , v1 , v2 ) ;

// plot3D . addDataset ( data3D ) ;// plot3D . s e tLab e l (”V” , ”S” , ”U”) ;

lowtemp = new JS l i d e r ( SwingConstants .VERTICAL, ( int ) ( 0 . 9∗LOW INIT TEMP) ..., ( int ) ( 1 . 1∗LOW INIT TEMP) , ( int )LOW INIT TEMP) ;

par t i c l eBox . setBorder ( BorderFactory . c r eateTi t l edBor de r ( ” p a r t i c l e box ...animation ” ) ) ;

plot3D . setBorder ( BorderFactory . c r eateTi t l edBorde r ( ”U ver sus T and V” ) ) ...;

// v a r i a b l e s . se tBorder ( BorderFactory . c reat eTi t l edBorder (” v a r i a b l e s ”) ) ;

drawButton . addActionLis tener ( drawListener ) ;animationButton . addActionListener ( an imat i onL i s tener ) ;t lowLabel = new JLabel ( ”<html> T<sub>low</sub> =” + nf . format (T1) ) ;thighLabel = new JLabel ( ”<html> T<sub>high</sub> =” + nf . format (T2) ) ;temperatureLabel = new JLabel ( ) ;entropyLabel = new JLabel ( ) ;volumeLabel = new JLabel ( ) ;pr es sur eLabe l = new JLabel ( ) ;

v a r i a b l e s . add ( drawButton ) ;v a r i a b l e s . add ( animationButton ) ;// v a r i a b l e s . add ( volume ) ;// v a r i a b l e s . add ( pre ssure ) ;// v a r i a b l e s . add ( entropy ) ;va r i a b l e s . add (Box . cr eateR ig idArea (new Dimension (0 , 10) ) ) ;v a r i a b l e s . add ( t lowLabel ) ;v a r i a b l e s . add ( thighLabel ) ;v a r i a b l e s . add (Box . cr eateR ig idArea (new Dimension (0 , 10) ) ) ;

10

Page 11: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

va r i a b l e s . add ( entropyLabel ) ;v a r i a b l e s . add ( volumeLabel ) ;v a r i a b l e s . add ( temperatureLabel ) ;v a r i a b l e s . add ( pr es sur eLabe l ) ;

ad jus tpane l . add ( v a r i a b l e s ) ;ad jus tpane l . add ( lowtemp ) ;

upperpanel . add ( pvplot ) ;upperpanel . add ( ad jus tpane l ) ;upperpanel . add ( t s p l o t ) ;l owerpane l . add ( par t i c l eBox ) ;l owerpane l . add ( plot3D ) ;mainpanel . add ( upperpanel ) ;mainpanel . add ( l owerpane l ) ;JFrame frame = new JFrame ( ) ;frame . s e tT i t l e ( ”Carnot cyc l e ” ) ;frame . add (mainpanel ) ;frame . pack ( ) ;frame . s e tRe s i z ab l e ( fa l se ) ;// frame . se tDe fau l tC loseOperat ion (JFrame .EXIT ON CLOSE) ;frame . s e tV i s i b l e ( true ) ;

lowtemp . addChangeListener ( new ChangeListener ( ) {public void stateChanged ( ChangeEvent e ) {

T1 = (( JS l i d e r ) e . getSource ( ) ) . getValue ( ) ;i f ( plotmark )

pvplot . c l earCurve ( ) ;pvplot . drawCurve (T1 ,T2 , v1 , v2 ) ;pvplot . drawCurrentState ( animationManager . ...

ge tState ( ) . getParameter ( ) ) ;t s p l o t . c l earCurve ( ) ;t s p l o t . drawCurve (T1 , T2 , v1 , v2 ) ;t s p l o t . drawCurrentState ( animationManager . ...

ge tState ( ) . getParameter ( ) ) ;t lowLabel . setText ( ”<html> T<sub>low</sub> =” + ...

nf . format (T1) ) ;thighLabel . setText ( ”<html> T<sub>high</sub> =” ...

+ nf . format (T2) ) ;}

}) ;

/∗ hightemp = new JS l i d e r ( SwingConstants .VERTICAL, ( i n t ) (0.9∗ ...HIGH INIT TEMP) ,

( i n t ) (1 .1∗HIGH INIT TEMP) ,( i n t )HIGH INIT TEMP) ;

hightemp . addChangeListener (new ChangeListener () {pu b l i c void stateChanged (ChangeEvent e ) {

T2 = (( JS l i d e r ) e . ge tSource () ) . ge tValue () ;//temp1 . se tTex t (”T1 =” + nf . format (T1) ) ;//temp2 . se tTex t (”T2 =” + nf . format (T2) ) ;i f ( plotmark )

pvp l o t . c learCurve () ;p vp l o t . drawCurve(T1 ,T2 , v1 , v2 ) ;pvp l o t . drawCurrentState ( animationManager . ...

g e t S t a t e ( ) . getParameter () ) ;t s p l o t . drawCurrentState ( animationManager . ...

g e t S t a t e ( ) . getParameter () ) ;t s p l o t . c learCurve () ;t s p l o t . drawCurve(T1 , T2, v1 , v2 ) ;

}}) ; ∗/

}

private Act i onL i s tener an imat i onL i s tener = new Act i onL i s tener ( ) {

11

Page 12: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

public void act ionPer formed ( ActionEvent e ) {i f ( ! animated . get ( ) ) {

animated . s e t ( true ) ;animationManager . s tartAnimation ( ) ;animationButton . setText ( ” stop \n animation ” ) ;

} else {// i f ( animated )animated . s e t ( fa l se ) ;animationManager . stopAnimation ( ) ;animationButton . setText ( ” s t a r t \n animation ” ) ;

}}

} ;

private Act i onL i s tener drawListener = new Act i onL i s tener ( ) {public void act ionPer formed ( ActionEvent e ) {

i f ( ! plotmark ) {pvplot . drawCurve (T1 ,T2 , v1 , v2 ) ;t s p l o t . drawCurve (T1 ,T2 , v1 , v2 ) ;plotmark=true ;drawButton . setText ( ”hide p l o t s ” ) ;

}else i f ( plotmark ) {

pvplot . c l earCurve ( ) ;t s p l o t . c l earCurve ( ) ;plotmark=fa l se ;drawButton . setText ( ”show p l o t s ” ) ;

}}

} ;

public void i n i t ( ) {

// f i n a l CarnotProcessMain mainWindow = new CarnotProcessMain () ;//mainWindow . s e t S i z e (950 ,900) ;/∗ f i n a l JFrame f = new JFrame () ;Sw i n gU t i l i t i e s . invokeLater (new Runnable ( ) {

pu b l i c void run () {f . s e t T i t l e ( f . g e tC lass ( ) . getSimpleName () ) ;f . add ( t h i s . mainpanel ) ;f . s e tDe fau l tC loseOperat ion (JFrame .EXIT ON CLOSE) ;f . s e t S i z e (950 ,900) ;f . s e tR e s i z a b l e ( t rue ) ;f . s e t V i s i b l e ( t rue ) ;}

}) ; ∗/

this . animationManager = new AnimationManager ( ) ;this . animationManager . s tartAnimation ( ) ;

}

/∗∗∗ Implements a cont inuat ion t ha t a l l ows to s t a r t , s t op and resume the ...

animation .∗ @author chr i s∗/

private class AnimationManager{

private vo lat i le boolean doRun ;private vo lat i le CurrentState s ta t e ;

public AnimationManager ( ) {s t a t e = new CurrentState ( ) ;

12

Page 13: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

}

/∗∗∗ I f running , t h i s c l a s s execut e s the d i s p l ay update every 40 ...

m i l l i s e c onds .∗ @author chr i s∗/

private class Animation extends Thread {public void run ( ) {

AnimationManager . this . doRun = true ;while (doRun) {

Sw i n gU t i l i t i e s . invokeLater ( s t a t e ) ;try {

TimeUnit .MILLISECONDS . s l e ep (50) ;

} catch ( Inter ruptedExcept i on e ) {System . out . p r i n t l n ( ”Waiting ...

Inter rupted ! \n f u r the r ...i n f ormat i on : ” ) ;

System . out . p r i n t l n ( e . t oS t r i ng ...( ) ) ;

e . pr intStackTrace ( ) ;}

}AnimationManager . this . doRun = fa l se ;

}}

/∗∗∗ Use to s t a r t t he animation i f not a c t i v e .∗/

public void startAnimation ( ) {i f ( ! this . doRun) {

new Thread (new Animation ( ) ) . s t a r t ( ) ;}

}

/∗∗∗ Use to s top the animation∗∗/

public void stopAnimation ( ) {this . doRun = fa l se ;

}

/∗∗∗ @return The current s t a t e . Can be a l t e r e d .∗/

public CurrentState getState ( ) {return this . s t a t e ;

}

/∗∗∗ Updates the d i s p l ay with the new s t a t e . Executed in the d i s pat c he r ...

Thread .∗ @author chr i s∗/

class CurrentState implements Runnable {private int parameter ;

public CurrentState ( ) {parameter=0;

}

public void run ( ) {t s p l o t . drawCurrentState ( parameter ) ;

13

Page 14: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

pvplot . drawCurrentState ( parameter ) ;plot3D . drawCurrentState ( parameter ) ;par t i c l eBox . setVolume ( pvplot . volumePercent ( parameter ) ) ...

;par t i c l eBox . setTemp ( ( int ) t s p l o t . tempPartic l eMotion( ...

parameter ) ) ;

i f ( parameter==0){// par t i c l eBox . startArrowAnimation (2 , 38∗ ...

PRECISION, ””) ;par t i c l eBox . startArrowAnimation (0 , 38∗PRECISION/4 , ” ...

contact with hot bath” ) ;}else i f ( parameter==PRECISION/2)

par t i c l eBox . startArrowAnimation (1 , 38∗ ...PRECISION/4 , ” contact with co ld bath” ) ;

temperatureLabel . setText ( ”T=” + nf . format ( t s p l o t . temp ( ...parameter ) ) ) ;

entropyLabel . setText ( ”S=” + nf . format ( t s p l o t . entropy ( ...parameter ) ) ) ;

volumeLabel . setText ( ”V=” + nf . format ( pvplot . volume ( ...parameter ) ) ) ;

pr es sur eLabe l . setText ( ”P=” + nf . format ( pvplot . p r e s su r e ...( parameter ) ) ) ;

parameter= (++parameter )%PRECISION ;}

public int getParameter ( ) {return this . parameter ;

}

}

}

}

Listing 2: Interface zum Particle-Fensterpackage u s e r i n t e r f a c e ;

public interface AnimatedPart ic l es {public void setVolume ( int volume ) ;public void setTemp( int temp) ;public void startArrowAnimation ( int arrow , int duration , Str ing capt i on ) ;

}

Listing 3: Interface zum 3D-Plotpackage u s e r i n t e r f a c e ;

public interface PlotSurfaceAndPoint {public void addDataset (double [ ] [ ] data ) ;public void addPoint (double x , double y ) ;public void s e tLabe l ( Str ing xLabel , Str ing yLabel , Str ing zLabel ) ;

}

14

Page 15: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

Listing 4: Panel zum Implementieren der 2D-Plotspackage u s e r i n t e r f a c e ;

import javax . swing . ∗ ;import javax . swing . border . Tit l edBorder ;

import p l o t . Plot ;import java . awt . Dimension ;import java . awt . Font ;

import ni ceGraph i cs . ∗ ;

abstract class Carnot2DPlot extends JPanel {

protected stat ic f ina l double GASCONSTANT = 8.314472 ; // in J/mol∗Kprotected stat ic f ina l double PLANCK = Math . pow(6.6260693 ,−34) ; // in J∗ sprivate stat ic f ina l double BOLTZMANN = Math . pow(1.3806504 , −23) ; // in J/Kprotected stat ic f ina l double ATOMMASSUNIT = Math . pow (1 .660538782 , −27) ; // in ...

kgprotected stat ic f ina l double SOMECONSTANT = (2∗Math . PI∗ATOMMASSUNIT∗ ...

BOLTZMANN)/Math . pow(PLANCK,2 ) ;protected double kappa =5.0/3; // ad i aba t i c constantprotected double [ ] T; // temperatures o f t he 2 i so thermals , T[0]<T[ 1 ]protected double [ ] v ; // the 4 c h a r a c t e r i s t i c volumes at v e r t i c e s o f curve in ...

s t a t e diagramprotected double [ ] C; // cons tant s o f t he ad i aba t i c curvesprotected stat ic f ina l int PRECISION = 240 ; //IMPORTANT 4 must d i v i d e ...

PRECISION ! ! ! !Plot p l o t ;// pro t e c t e d DataPoint [ ] dataSet ;protected DataSet dataSet ;

public Carnot2DPlot ( ) {

T=new double [ 2 ] ;v=new double [ 4 ] ;C=new double [ 2 ] ;p l o t = new Plot ( ) ;

dataSet = new DataSet ( ) ;

p l o t . s e t S i z e (new Dimension (400 , 400) ) ;p l o t . setMarksStyle ( ” p i x e l s ” , 0 ) ;p l o t . setMarksStyle ( ” dots ” , 1) ;p l o t . setLabelFont ( ”ARIAL−PLAIN−16” ) ;add ( p l o t ) ;

}/∗∗∗ s e t t he c h a r a c t e r i s t i c parameters o f t he carnot c y c l e so you can p l o t t he ...

curve∗ f o r the a d i a b a t i c s : C={ l e f t ad iabat i c , r i g h t ad i aba t i c }∗ @param v1 s t a r t volume on upper isotherm∗ @param v2 end volume to q u i t t he upper isotherm∗ @param T1 temperature o f lower isotherm∗ @param T2 temperature o f upper isotherm∗/

protected void setParameters (double T1 , double T2 , double v1 , double v2 ) {T[0]=T1 ;T[1]=T2 ;

C[ 0 ] = GASCONSTANT∗T2∗Math . pow(v1 , kappa−1) ;C [ 1 ] = GASCONSTANT∗T2∗Math . pow(v2 , kappa−1) ;

v [0 ]= v1 ;

15

Page 16: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

v [1]= v2 ;v [ 2 ] = Math . pow(GAS CONSTANT∗T[ 0 ] /C[ 1 ] , 1/(1−kappa ) ) ;v [ 3 ] = Math . pow(GAS CONSTANT∗T[ 0 ] /C[ 0 ] , 1/(1−kappa ) ) ;

}

abstract void makeDataSet (double T1 , double T2 , double v1 , double v2 ) ;abstract void drawCurve (double T1 , double T2 , double v1 , double v2 ) ;abstract void drawCurrentState ( int parameter ) ;

/∗∗∗∗ @param parameter which paramet r i ze s the carnot c y c l e∗ @return volume∗/

double volume ( int parameter ) {// parameter = parameter%PRECISION;double x ;

i f (0<=parameter && parameter <(PRECISION/4) ){x=v [0 ]+( v [1]−v [ 0 ] ) ∗parameter /(PRECISION/4) ;return x ;

}else i f ( (PRECISION/4)<=parameter && parameter <2∗(PRECISION/4) ...

) {x=v [1 ]+( v [2]−v [ 1 ] ) ∗( parameter−(PRECISION/4) ) /( ...

PRECISION/4) ;return x ;

}else i f (2∗ (PRECISION/4)<=parameter && parameter <3∗(PRECISION ...

/4) ) {x=v [2 ]+( v [3]−v [ 2 ] ) ∗( parameter −2∗(PRECISION/4) ) /( ...

PRECISION/4) ;return x ;

}else i f (3∗ (PRECISION/4)<=parameter && parameter<=PRECISION){

x=v [3 ]+( v [0]−v [ 3 ] ) ∗( parameter −3∗(PRECISION/4) ) /( ...PRECISION/4) ;

return x ;}else

return 0 ;}/∗∗∗ re turns the volume in normalized to a va lue o f 100 at the po in t wi th ...

b i g g e s t volume v [ 2 ]∗ @param parameter∗ @return volume in a range o f [0 ,100 ]∗/

int volumePercent ( int parameter ) {return ( int ) (100∗( volume ( parameter )−volume (0) ) /( volume(PRECISION/2)− ...

volume (0) ) ) ;}

/∗∗∗ g i v e s 4 thermal s t a t e func t ion f o r the 4 s t ag e s o f t he carnot cy c l e∗ @param index <br> 1: upper isotherm <br> 2: r i g h t ad i aba t i c <br> 3: lower ...

i sotherm∗ <br> 4: l e f t ad i aba t i c∗ @param v∗ @return∗/

public void clearCurve ( ) {p l o t . c l e a r (0) ;

}/∗∗∗ re turns the va lue o f t he entropy s t a t e f o r g i ven T and v

16

Page 17: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

∗ @param T temperature∗ @param v volume∗ @return∗/

public double entropy (double T, double v ) {return (GAS CONSTANT∗(Math . l og ( /∗SOMECONSTANT∗∗/T) ∗1 .5 + Math . l og ( v ) ...

+ 2 . 5 ) ) ;}

protected class DataSet {private double [ ] [ ] data ;DataSet ( ) {

data = new double [PRECISION+1 ] [ 2 ] ;}void setDataPoint ( int place , double x , double y ){

data [ p l ace ] [ 0 ]= x ;data [ p l ace ] [ 1 ]= y ;

}double getX ( int place ) {

return data [ p l ace ] [ 0 ] ;}double getY ( int place ) {

return data [ p l ace ] [ 1 ] ;}

}}

class PVPlot extends Carnot2DPlot {/∗∗∗∗/

private stat ic f ina l long s e r i a lVer s i onUID = 1L ;//Carnot2DPlot carnotPlo t = new Carnot2DPlot ( ) ;

public PVPlot (double T1 , double T2 , double v1 , double v2 ) {p l o t . setXLabel ( ”v” ) ;p l o t . setYLabel ( ”p” ) ;drawCurve (T1 ,T2 , v1 , v2 ) ;p l o t . setBorder ( BorderFactory . c r eateTi t l edBorder ( null , ”P ver sus V” , ...

Ti t l edBorder .CENTER, 0 , new Font ( ”Ar ia l ” , 1 , 16) ) ) ;

}public void makeDataSet (double T1 , double T2 , double v1 , double v2 ) {

setParameters (T1 ,T2 , v1 , v2 ) ;for ( int i =0; i<=PRECISION ; i++){

dataSet . setDataPoint ( i , volume ( i ) , p r e s su r e ( i ) ) ;}

}

public void drawCurve (double T1 , double T2 , double v1 , double v2 ) {makeDataSet (T1 ,T2 , v1 , v2 ) ;// p l o t . setXRange ( v [0]−0.2 , v [2 ]+0.2) ;// p l o t . setYRange ( pre ssure (PRECISION/2)−1, pre ssure (0)+1) ;p l o t . s e tPo i n t sPe r s i s t e n c e (0) ;for ( int i =0; i<=PRECISION ; i++)

p l o t . addPoint (0 , dataSet . getX ( i ) , dataSet . getY ( i ) , true ) ;// p l o t . addPoint (0 , volume ( i ) , pre ssure ( i ) , t rue ) ;

// p l o t . s e tPo in t sPe r s i s t enc e (1) ;p l o t . f i l l P l o t ( ) ;

}

public void drawCurrentState ( int parameter ) {p l o t . s e tPo i n t sPe r s i s t e n c e (1) ;

17

Page 18: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

// p l o t . c l e a r (1) ;p l o t . addPoint (1 , dataSet . getX ( parameter ) , dataSet . getY ( parameter ) , fa l se ) ...

;// p l o t . addPoint (1 , volume ( parameter ) , pre ssure ( parameter ) , f a l s e ) ;

}

/∗∗∗∗ @param parameter which paramet r i ze s the carnot c y c l e∗ @return∗/

public double pr e s su r e ( int parameter ) {//parameter = parameter%PRECISION;

i f (0<=parameter && parameter <(PRECISION/4) )return (GASCONSTANT∗T[ 1 ] / volume ( parameter ) ) ;

else i f ( (PRECISION/4)<=parameter && parameter <2∗(PRECISION/4) ...)

return (C[ 1 ] ∗Math . pow( volume ( parameter ) ,−kappa ) ) ;

else i f (2∗ (PRECISION/4)<=parameter && parameter <3∗(PRECISION .../4) )

return (GASCONSTANT∗T[ 0 ] / volume ( parameter ) ) ;

else i f (3∗ (PRECISION/4)<=parameter && parameter<=PRECISION)return (C[ 0 ] ∗Math . pow( volume ( parameter ) ,−kappa ) ) ;

elsereturn 0 ;

}}

class TSPlot extends Carnot2DPlot {

/∗∗∗∗/

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

public TSPlot (double T1 , double T2 , double v1 , double v2 ) {p l o t . setXLabel ( ”S” ) ;p l o t . setYLabel ( ”T[K] ” ) ;drawCurve (T1 ,T2 , v1 , v2 ) ;p l o t . setBorder ( BorderFactory . c r eateTi t l edBorder ( null , ”T ver sus S” , ...

Ti t l edBorder .CENTER, 0 , new Font ( ”Ar ia l ” , 1 , 16) ) ) ;}Font f = new Font ( ”Ar ia l ” , 0 , 0 ) ;

public void drawCurve (double T1 , double T2 , double v1 , double v2 ) {makeDataSet (T1 ,T2 , v1 , v2 ) ;

// p l o t . setXRange ( entropy (T[ 1 ] , v [ 0 ] ) −0.5 , entropy (T[ 0 ] , v [ 2 ] ) +0.5) ;// p l o t . setYRange (T[0]−1 ,T[1]+1) ;

p l o t . s e tPo i n t sPe r s i s t e n c e (0) ;for ( int i =0; i<=PRECISION ; i++){

p l o t . addPoint (0 , dataSet . getX ( i ) , dataSet . getY ( i ) , true ...) ;

}p l o t . f i l l P l o t ( ) ;

}public void makeDataSet (double T1 , double T2 , double v1 , double v2 ) {

setParameters (T1 ,T2 , v1 , v2 ) ;for ( int i =0; i<=PRECISION ; i++){

18

Page 19: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

dataSet . setDataPoint ( i , entropy ( i ) , temp( i ) ) ;}

}

public double entropy ( int parameter ) {return (GAS CONSTANT∗(Math . l og ( /∗SOMECONSTANT∗∗/temp( parameter ) ) ∗1 .5 ...

+ Math . l og ( volume( parameter ) ) + 2 . 5 ) ) ;}

public double temp( int parameter ) {//parameter = parameter %100;i f (0<=parameter && parameter <(PRECISION/4) )

return T [ 1 ] ;

else i f ( (PRECISION/4)<=parameter && parameter <2∗(PRECISION/4) )return (C[ 1 ] ∗Math . pow( volume ( parameter ) , 1−kappa ) /GASCONSTANT) ...

;

else i f (2∗ (PRECISION/4)<=parameter && parameter <3∗(PRECISION/4) )return T [ 0 ] ;

else i f (3∗ (PRECISION/4)<=parameter && parameter<=PRECISION) {return (C[ 0 ] ∗Math . pow( volume ( parameter ) , 1−kappa ) /GASCONSTANT) ...

;}

else return 0 ;}public int tempPartic l eMotion( int parameter ) {

return ( int ) ( (200∗ ( temp( parameter )−T[ 0 ] ) ) /(T[1]−T[ 0 ] ) +100) ;}

public void drawCurrentState ( int parameter ) {p l o t . s e tPo i n t sPe r s i s t e n c e (1) ;// p l o t . c l e a r (1) ;p l o t . addPoint (1 , dataSet . getX ( parameter ) , dataSet . getY ( parameter ) , fa l se ) ...

;// p l o t . addPoint (1 , entropy ( temp( parameter ) , volume ( parameter ) ) , temp( ...

parameter ) , t rue ) ;}

}

class Carnot3DPlot extends Carnot2DPlot{

PlotPanel3D plot3D ;private int s i z e = 40 ;double [ ] [ ] dataSet = new double [ s i z e +10] [ s i z e +10] ;private stat ic f ina l double constant = 2.5 + (1 . 5 ∗Math . l og (4∗Math . PI∗ ...

ATOMMASSUNIT) /(3∗Math . pow(PLANCK, 2 ) ) ) ;

public Carnot3DPlot (double T1 , double T2 , double v1 , double v2 ) {this . remove (0) ;plot3D = new PlotPanel3D (350 ,300) ;

plot3D . s etLabe l ( ”volume” , ” entropy ” , ” energy ” ) ;drawCurve (T1 ,T2 , v1 , v2 ) ;this . add ( plot3D ) ;

}

/∗∗∗ g i v e s the va lue o f t he energy s t a t e func t ion∗ @param v volume∗ @param s entropy∗ @return

19

Page 20: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

∗/double energy (double v , double s ) {

return /∗Math . pow(10 ,−41) ∗∗/Math . exp ( ( 2 . 0 / 3 ) ∗( s /GAS CONSTANT)−1)∗Math .... pow(v ,−1.5) ;

}

void drawCurrentState ( int parameter ) {// doub le v1 = 0;double v2 =(v [1]−v [ 0 ] ) /( v [2]−v [ 0 ] ) ∗( dataSet . l ength −1) ;double v4 = (v [3]−v [ 0 ] ) /( v [2]−v [ 0 ] ) ∗( dataSet . l ength −1) ;double v3 = dataSet . l ength −1;// doub le s1 = 0;double s2 = dataSet . l ength −1;double temp= (double) parameter/PRECISION ∗4 ;

i f (0<=parameter && parameter<PRECISION/4) {plot3D . addPoint ( temp∗v2 , temp∗ s2 ) ;

} else i f (PRECISION/4<=parameter && parameter<PRECISION/2) {temp−−;plot3D . addPoint ( v2+(v3−v2 )∗temp , s2 ) ;

} else i f (PRECISION/2<=parameter && parameter<PRECISION∗3/4) {temp−=2;plot3D . addPoint ( v3+(v4−v3 )∗temp , s2∗(1−temp) ) ;

} else i f (PRECISION∗3/4<=parameter && parameter<PRECISION) {temp−=3;plot3D . addPoint ( v4∗(1−temp) , 0) ;

}

}

public void makeDataSet (double T1 , double T2 , double v1 , double v2 ){

dataSet = new double [ 2 4 ] [ 2 4 ] ;/∗ f o r ( i n t i =20; i<=24; i++){

f o r ( i n t j =20; j<=24; j++) // creat e dummy 3D p l o tdataSet [ i ] [ j ] = 50;

}∗/

setParameters (T1 ,T2 , v1 , v2 ) ;double s1 = entropy (T[ 1 ] , v [ 0 ] ) ;double s2 = entropy (T[ 1 ] , v [ 1 ] ) ;

double vol , s ;

for ( int i = 0 ; i < dataSet . l ength ; i++) {vo l = v [0 ]+( v [2]−v [ 0 ] ) ∗ ( (double) i ) /( dataSet . l ength −1) ;for ( int j = 0 ; j < dataSet [ 0 ] . l ength ; j++) {

s = s1+(s2−s1 ) ∗ ( (double) j ) /( dataSet [ 0 ] . l ength −1) ;dataSet [ i ] [ j ]= energy ( vol , s ) ;}

}

}

public void drawCurve (double T1 , double T2 , double v1 , double v2 ) {makeDataSet (T1 ,T2 , v1 , v2 ) ;plot3D . addDataset ( dataSet ) ;

}

}

Listing 5: Gas-Simulations-Panelpackage ni ceGraph i cs ;import java . awt . ∗ ;

20

Page 21: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

import java . awt . event . ∗ ;import java . awt . geom . GeneralPath ;import java . awt . image . ∗ ;import java . u t i l .Random ;import java . u t i l . concur r ent . TimeUnit ;

import javax . swing . ∗ ;import u s e r i n t e r f a c e . ∗ ;

public class Partic l eAnimationPane l extends JPanel implements Act i onL i s tener , ...AnimatedPart ic l es , Runnable{

/∗∗∗∗/

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 ;public stat ic f ina l int DELAY = 40;private stat ic f ina l int NUMBER OF PARTICLES=1500;public int alpha=0;public boolean arrowDrawing=fa l se ;private int volume=0;

public f ina l int NORTH=0,SOUTH=2,WEST=1,EAST=3;private int Temperature =150;private Pa r t i c l e [ ] p a r t i c l e= new Pa r t i c l e [NUMBER OF PARTICLES ] ;

public Dimension boxSize , boxBegin ;public Dimension ar rowPos i t i on ;public Str ing i n f o=”−” ;private Timer t imer ;

public Partic l eAnimationPanel ( 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 . 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 ) ;// t h i s . p i c t u r e . setBackground ( Color .BLACK) ;this . p i c tu r e . setBackground ( Color . b lack ) ;this . add ( p i c tu r e ) ;this . g2 = (Graphics2D ) image . getGraphics ( ) ;// t h i s . g2 . se tCo lor ( Color .BLACK) ;t imer = new Timer (DELAY, this ) ; // f i r e s the ac t i onL i s t ene r every quar t e r second

boxBegin=new Dimension ( this . g e tP r e f e r r edS i z e ( ) . width /10 , this . ...g e tP r e f e r r edS i z e ( ) . he i ght ∗2/10) ;

boxSize=new Dimension ( this . g e tP r e f e r r edS i z e ( ) . width∗5/10+volume , this . ...g e tP r e f e r r edS i z e ( ) . he i ght ∗6/10) ;

i n i t P a r t i c l e s ( ) ;r edtob lue = newGradientPaint (0 , 0 , Color . red , 0 , this . g e tP r e f e r r edS i z e ( ) . height , Color . ...

b lue ) ;act ionPer formed ( null ) ;new Thread ( this ) . s t a r t ( ) ;

}public Graphics2D getTheGraphics ( ) {

return this . g2 ;}

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 ) ;

21

Page 22: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

}

public void setImage ( BufferedImage g lo ) {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 ( ) ; // r epa in t s

}public void paintComponent ( Graphics g ) {

drawScene ( ) ;super . paintComponent ( g ) ;

}

/∗∗∗ volume i s to be s e t from 0 to 100 ! !∗/

public void setVolume ( int vo l ) {volume = (−boxSize . width−boxBegin . width+this . g e tP r e f e r r edS i z e ( ) . width−2)∗ vo l ...

/100;for ( int i = 0 ; i < p a r t i c l e . l ength ; i++) {

p a r t i c l e [ i ] . setVolume ( volume ) ; // in p i x e l}

}GradientPaint r edtob lue ;

public void drawScene ( ) {

g2 . s e tPa int ( r edtob lue ) ; // very ...s low ! ! !

g2 . f i l l R e c t (0 , 0 , this . g e tP r e f e r r edS i z e ( ) . width , this . g e tP r e f e r r edS i z e ...( ) . he i ght ) ;

/∗ g2 . se tCo lor ( t h i s . getBackground () ) ; // very f a s tg2 . f i l l R e c t (0 , 0 , t h i s . g e tPr e f e r r e dS i z e () . width , t h i s . g e tPr e f e r r e dS i z e ...

( ) . h e i g h t ) ; ∗/g2 . s e tCo lor ( Color . ye l l ow ) ; // s i z e o f Boxg2 . f i l l R e c t ( boxBegin . width , boxBegin . height ,

boxSize . width+volume , boxSize . he i ght ) ;g2 . s e tCo lor ( this . p i c tu r e . getBackground ( ) ) ;g2 . f i l l R e c t ( boxBegin . width+5, boxBegin . he i ght+5,

boxSize . width+volume−10, boxSize . height −10) ;i f ( arrowDrawing ) {

drawArrow (2 , ar rowPos i t i on . width , ar rowPos i t i on . heigh t , alpha ) ;g2 . s e tCo lor ( Color . white ) ;Font f ont = new Font ( ”Dialog ” , Font .BOLD, 18) ;g2 . setFont ( f ont ) ;g2 . drawString ( in f o , 5 , 25) ;

}g2 . s e tCo lor ( Color .YELLOW) ;drawPar t i c l e s ( ) ;

}

public void i n i t P a r t i c l e s ( ) {for ( int i = 0 ; i < p a r t i c l e . l ength ; i++) {

p a r t i c l e [ i ]=new Pa r t i c l e ( boxSize . width−10, boxSize . height −10) ;}

}

public void drawPar t i c l e s ( ) {i f ( Temperature<255)

g2 . s e tCo lor (new Color (Temperature , 150 , 150) ) ;else

22

Page 23: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

g2 . s e tCo lor (new Color (255 ,140+Temperature −255,140+Temperature ...−255) ) ;

for ( int i = 0 ; i < p a r t i c l e . l ength ; i++) {drawAParticle ( p a r t i c l e [ i ] . getX ( )+boxBegin . width+5, p a r t i c l e [ i ...

] . getY ( )+boxBegin . he i ght+5, 2 , 2) ;//g2 . f i l l R e c t ( p a r t i c l e [ i ] . getX ()+boxBegin . width+5, pa r t i c l e [ i ...

] . getY ()+boxBegin . he i g h t +5, 2 , 2) ;}

}private void drawAParticle ( int x , int y , int xSize , int yS i ze ) {

for ( int i = 0 ; i < xS i ze ; i++) {for ( int j = 0 ; j < yS i ze ; j++) {

image . setRGB (x+i , y+j , g2 . getColor ( ) . getRGB () ) ;}

}}

public void drawArrow ( int d i r e c t i on , int x , int y , int alpha ) {int [ ] xPoints={−5 ,−5 ,−10 ,0 ,10 ,5 ,5};int [ ] yPoints ={0 ,25 ,25 ,45 ,25 ,25 ,0} ;g2 . s e tS t r oke (new Bas i cStroke (2) ) ;i f ( Temperature<255)

g2 . s e tCo lor (new Color (Temperature , 100 , 100 , alpha ) ) ;else

g2 . s e tCo lor (new Color (255 ,100+Temperature −255,100+Temperature ...−255 , alpha ) ) ;

GeneralPath polygon =new GeneralPath ( GeneralPath .WIND EVEN ODD, xPoints . l ength ) ;

switch ( d i r e c t i o n ) {case NORTH:

polygon .moveTo(x+xPoints [ 0 ] , y−yPoints [ 0 ] ) ;for ( int index = 1 ; index < xPoints . l ength ; index++) {

polygon . l ineTo (x+xPoints [ index ] , y−yPoints [ index ] ) ;} ;break ;

case SOUTH:polygon .moveTo(x+xPoints [ 0 ] , y−yPoints [ 0 ] ) ;for ( int index = 1 ; index < xPoints . l ength ; index++) {

polygon . l ineTo (x+xPoints [ index ] , y+yPoints [ index ] ) ;} ;break ;

case EAST:polygon .moveTo(x−yPoints [ 0 ] , y+xPoints [ 0 ] ) ;for ( int index = 1 ; index < xPoints . l ength ; index++) {

polygon . l ineTo (x−yPoints [ index ] , y+xPoints [ index ] ) ;} ;break ;

case WEST:polygon .moveTo(x+yPoints [ 0 ] , y+xPoints [ 0 ] ) ;for ( int index = 1 ; index < xPoints . l ength ; index++) {

polygon . l ineTo (x+yPoints [ index ] , y+xPoints [ index ] ) ;} ;break ;

}polygon . c l os ePath ( ) ;g2 . draw ( polygon ) ;double a=alpha /255 . 0 ;i f ( Temperature<255)

g2 . s e tCo lor (new Color (Temperature , 100 , 100 , ( int ) (150 . 0∗ a ) ) ) ;else

g2 . s e tCo lor (new Color (255 ,100+Temperature −255,100+Temperature ...−255 ,( int ) (150 . 0∗ a ) ) ) ;

g2 . f i l l ( polygon ) ;}public void setTemp( int temp) {

Temperature=temp ;

23

Page 24: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

for ( int i = 0 ; i < p a r t i c l e . l ength ; i++) {p a r t i c l e [ i ] . setTemp( temp) ;

}}Animation animation=new Animation (0 , this , 1 0 ) ;public void startArrowAnimation ( int arrow , int duration , Str ing capt i on ) {

animation . stop ( ) ;switch ( arrow ) {case 0 :

i n f o=capt i on ;ar rowPos i t i on=new Dimension ( this . g e tP r e f e r r edS i z e ( ) . width /2 , ...

boxBegin . he i ght ) ;new Thread ( animation=new Animation ( arrow , this , durat ion ) ) . s t a r t ...

( ) ;break ;

case 1 :i n f o=capt i on ;ar rowPos i t i on=new Dimension ( this . g e tP r e f e r r edS i z e ( ) . width /2 , ...

boxBegin . he i ght+boxSize . he i ght ) ;new Thread ( animation=new Animation ( arrow , this , durat ion ) ) . s t a r t ...

( ) ;break ;

default :i n f o=capt i on ;new Thread ( animation=new Animation (5 , this , durat ion ) ) . s t a r t ( ) ;

}

}public void run ( ) {

t imer . s t a r t ( ) ;/∗ whi l e ( t rue ){

t h i s . repa in t ( ) ;t r y {

TimeUnit .MILLISECONDS. s l e e p (40) ;

} catch ( In t e rrupt edExcept ion e ) {System . out . p r i n t l n (” p a r t i c l e thread in t e r rup t ”) ;

}}∗/

}

}class Pa r t i c l e {

private double X=0,Y=0;private int volume=0;private double speed =1.5;private double speedX=0;private double speedY=0;private double alpha=0;private int xBoxSize , yBoxSize ;

Random R= new Random() ;/∗∗∗ p l e a s e s p e c i f y the dimensions o f Box i n t e r i o r .∗ @param boxDimension∗/

public Pa r t i c l e ( int xSize , int yS i ze ) {xBoxSize=xSi ze ;yBoxSize=ySi ze ;Y=R. nextInt ( yS i ze ) ;X=R. nextInt ( xS i ze ) ;alpha=R. nextInt (360) ∗Math . PI /180 . 0 ;speedY=Math . s i n ( alpha ) ;speedX= Math . cos ( alpha ) ;

}

24

Page 25: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

/∗∗∗∗ @return x Value o f p a r t i c l e po s i t i on r e l a t i v e to box i n t e r i o r∗/

public int getX ( ) {i f (X>=xBoxSize−2+volume ) {

X=xBoxSize−2+volume ;speedX=−Math . abs ( speedX ) ;

} else i f (X<=0){i f ( speedY>0)

alpha=Math . acos ( speedX ) ;else

alpha=2∗Math . PI−Math . acos ( speedX ) ;alpha += 2∗R. nextDouble ( ) −1.0;speedX=Math . cos ( alpha ) ;speedY=Math . s i n ( alpha ) ;speedX=Math . abs ( speedX ) ;

}X+=speedX∗ speed ;return ( int )X;

}/∗∗∗∗ @return y Value o f p a r t i c l e po s i t i on r e l a t i v e to box i n t e r i o r∗/

public int getY ( ) {i f (Y>=yBoxSize−2){

speedY=−Math . abs ( speedY ) ;} else i f (Y<=0){

speedY=Math . abs ( speedY ) ;}Y+=speedY∗ speed ;

return ( int )Y;}

public void setVolume ( int vo l ) {volume=vol ;

}public void setTemp( int temp) {

speed=temp /100 . 0 ;}

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

private Timer t imer ;private Partic l eAnimationPane l dP ;private int o r i e n t=0;private int counter =0;private int animTime ;private f ina l int DELAY=40;

public Animation ( int d i r e c t i on , Part ic l eAnimationPane l d , int time ) {o r i e n t=d i r e c t i o n ;dP=d ;animTime=time ;t imer=new Timer (DELAY, this ) ;

}

public void stop ( ) {t imer . s top ( ) ;

}public void run ( ) {

25

Page 26: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

i f ( or i ent <5)dP . arrowDrawing=true ;

t imer . s t a r t ( ) ;}public void act ionPer formed ( ActionEvent arg0 ) {

counter++;i f ( o r i e n t==5){

dP . setVolume ( animationAlpha ( counter ∗(double)DELAY/(double) ...animTime) ∗100/255) ;

} else {dP . alpha=animationAlpha ( counter ∗(double)DELAY/(double) animTime ...

) ;}i f ( counter ∗DELAY>=animTime) {

t imer . s top ( ) ;i f ( or i ent <5)

dP . arrowDrawing=fa l se ;}

}/∗∗∗ @param param : animation Parameter must be between 0 and 1!∗ @return∗/

private int animationAlpha (double param) {i f (param<0 | |param>1){

t imer . s top ( ) ;System . out . p r i n t l n ( ”Animation Parameter i n v a l i d ” ) ;return 0 ;

}return ( int ) (255 . 0∗4 .0∗ (0 . 25 − ( param−0.5) ∗( param−0.5) ) ) ;

}}

Listing 6: Graphikebene zum zeichnen des Plots sowie des Punktespackage ni ceGraph i cs ;

import java . awt . ∗ ;import java . awt . event . ∗ ;import java . awt . image . ∗ ;import javax . swing . ∗ ;import u s e r i n t e r f a c e . ∗ ;// import javax . swing . event .∗ ;

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

PlotSurfaceAndPoint {

/∗∗∗∗/

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

private Graphics2D g2 ;private JLabel p i c tu r e ;private Plot3D p l o t ;public stat ic f ina l int DELAY = 10000;

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

26

Page 27: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

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 . b lack ) ;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 ) ;// t h i s . p i c t u r e . setBackground ( Color .BLACK) ;this . add ( p i c tu r e ) ;this . g2 = (Graphics2D ) image . getGraphics ( ) ;// t h i s . g2 . se 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 quar t e r secondthis . addMouseMotionListener( this ) ;this . addMouseListener ( this ) ;p l o t=new Plot3D (200 ,200 , 200) ;temp = new BufferedImage ( this . g e tP r e f e r r edS i z e ( ) . width , this . g e tP r e f e r r edS i z e ( ) ...

. he ight ,BufferedImage .TYPE INT ARGB) ;

g1= (Graphics2D ) temp . getGraphics ( ) ;g1 . drawImage ( image , 0 , 0 , this ) ;

s tartAnimation ( ) ;p l o t . r otateZ(−Math . PI ∗2/3) ; // i n i t i a l po s i t i on o f coord inat e systemp l o t . rotateX ( 0 . 8 ) ;p l o t . s e tOr i g i n (0 , 500 , 25) ;}

private void startAnimation ( ) {//g1 . se tCo lor ( Color . whi te ) ;p l o t . drawPlot ( g1 ) ;this . updatePlot ( ) ;

}

public Graphics2D getTheGraphics ( ) {return this . g2 ;

}

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 lo ) {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 ( ) ;

}

private void no t i f y ( Str ing x ) {/∗g2 . se tCo lor ( Color . l i gh tGray ) ;g2 . f i l l R e c t (10 , 10 , 200 , 20) ;g2 . se tCo lor ( Color . b l a c k ) ;g2 . drawStr ing ( x ,25 ,25) ;t h i s . repa in t ( ) ; ∗/

}

27

Page 28: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

private void updatePlot ( ) {g1 . s e tCo lor ( this . getBackground ( ) ) ;g1 . f i l l R e c t (0 , 0 , this . g e tP r e f e r r edS i z e ( ) . width , this . g e tP r e f e r r edS i z e ( ) . ...

he i ght ) ;p l o t . drawPlot ( g1 ) ;g2 . drawImage ( temp , 0 , 0 , this ) ;

}public Dimension trans formPoint ( int x , int y , int z ) {

int xEnd=0;int yEnd=0;yEnd = 250−( int ) ( (double) z /( y+1300.0) ∗1300 .0) ;xEnd =250+( int ) ( ( double)x/( y+1300.0) ∗1300 .0) ;return new Dimension (xEnd , yEnd) ;

}public void mouseClicked (MouseEvent arg0 ) { no t i f y ( ”CLicked ” ) ; }public void mouseEntered(MouseEvent arg0 ) { no t i f y ( ”Enterd” ) ; }public void mouseExited (MouseEvent arg0 ) { no t i f y ( ”Exited ” ) ; }public void mousePressed (MouseEvent arg0 ) {

i f ( arg0 . getButton ( )==MouseEvent .BUTTON1) {previousMousePosit ionX=arg0 . getX ( ) ;previousMousePosit ionY=arg0 . getY ( ) ;this . button1Pressed=true ;

} else i f ( arg0 . getButton ( )==MouseEvent .BUTTON3) {previousMousePosit ionX=arg0 . getX ( ) ;previousMousePosit ionY=arg0 . getY ( ) ;this . button3Pressed=true ;

} else i f ( arg0 . getButton ( )==MouseEvent .BUTTON2) {previousMousePosit ionX=arg0 . getX ( ) ;previousMousePosit ionY=arg0 . getY ( ) ;this . button2Pressed=true ;

} else {this . button1Pressed=fa l se ;this . button3Pressed=fa l se ;

}

}public void mouseReleased (MouseEvent arg0 ) {

i f ( arg0 . getButton ( )==MouseEvent .BUTTON1) {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 {}

}private int previousMousePosit ionX =0, previousMousePosit ionY =0;private boolean button1Pressed=true , button3Pressed=fa lse , button2Pressed=fa l se ;public void mouseDragged (MouseEvent arg0 ) {

i f ( ( button1Pressed&&button3Pressed ) | | this . button2Pressed ) {int mouseMovementY=arg0 . getY ( )−this . previousMousePosit ionY ;previousMousePosit ionX=arg0 . getX ( ) ;previousMousePosit ionY=arg0 . getY ( ) ;p l o t . t r a n s l a t eO r i g i n (0 , mouseMovementY ∗2 , 0) ;updatePlot ( ) ;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 ( ) ;p l o t . rotateX (0 .005∗mouseMovementY ) ;p l o t . r otateZ (0 . 005∗mouseMovementX ) ;updatePlot ( ) ;this . r epa i n t ( ) ;

28

Page 29: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

} else {}

}public void mouseMoved (MouseEvent arg0 ) {

no t i f y ( ”moved” ) ;}

public void addDataset (double [ ] [ ] data ) {double min=data [ 0 ] [ 0 ] , max=data [ 0 ] [ 0 ] ;for ( int i = 0 ; i < data . l ength ; i++) {

for ( int j = 0 ; j < data [ 0 ] . l ength ; j++) {i f ( data [ i ] [ j ]<min)

min=data [ i ] [ j ] ;i f ( data [ i ] [ j ]>max)

max=data [ i ] [ j ] ;}

}int [ ] [ ] var=new int [ data [ 0 ] . l ength ] [ data . l ength ] ;for ( int i = 0 ; i < data . l ength ; i++) {

for ( int j = 0 ; j < data [ 0 ] . l ength ; j++) {var [ i ] [ j ]=( int ) (200∗( data [ i ] [ j ]−min) /(max−min) ) ;

}}p l o t . s e tZPoints ( var ) ;updatePlot ( ) ;this . r epa i n t ( ) ;

}

public void addPoint (double x , double y ) {g2 . drawImage ( temp , 0 , 0 , null ) ;p l o t . s e tPo int (x , y , g2 ) ;this . r epa i n t ( ) ;

}

public void s e tLabe l ( Str ing xLabel , Str ing yLabel , Str ing zLabel ) {p l o t . setCOSLabel ( xLabel , yLabel , zLabel ) ;

}}

Listing 7: Berechnet die Position der Dreiecke sowie alle Koordinatentransformationenpackage ni ceGraph i cs ;

import java . awt . Color ;import java . awt . Dimension ;import java . awt . Font ;import java . awt . GradientPaint ;import java . awt . Graphics2D ;

public class Plot3D {

private double coSy [ ] [ ] = new double [ 3 ] [ 3 ] ; // t h i s i s t he t rans format ion matrix ...between the two COS

private Vector3D [ ] [ ] qubePoints=new Vector3D [ 2 ] [ 4 ] ;private int width , height , depth=0;private Sur f ace [ ] qS=new Sur f ace [ 6 ] ;private Vector3D [ ] [ ] data ;private Polygon [ ] [ ] [ ] hope ;private Vector3D o r i g i n=new Vector3D (0 ,200 , 0) ;private f ina l Vector3D ROT AXIS=new Vector3D (100 ,100 , 100) ; // the po in t where ...

t he two ro t a t i on ax i s Meet ( around x and z )private Str ing xLabel=”X” , yLabel=”Y” , zLabel=”Z” ;

public Plot3D ( int w, int h , int d) {

29

Page 30: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

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 COS

coSy [ 1 ] [ 0 ] = 0 ; coSy [ 1 ] [ 1 ] = 1 ; coSy [ 1 ] [ 2 ] = 0 ;coSy [ 2 ] [ 0 ] = 0 ; coSy [ 2 ] [ 1 ] = 0 ; coSy [ 2 ] [ 2 ] = 1 ;width=w;he i ght=h ;depth=d ;qubePoints [ 0 ] [ 0 ]=new Vector3D(−w/2,−d/2 ,h/2) ;qubePoints [ 0 ] [ 1 ]=new Vector3D (w/2,−d/2 ,h/2) ;qubePoints [ 0 ] [ 2 ]=new Vector3D (w/2,−d/2,−h/2) ;qubePoints [ 0 ] [ 3 ]=new Vector3D(−w/2,−d/2,−h/2) ;for ( int i = 0 ; i < qubePoints [ 1 ] . l ength ; i++) {

this . qubePoints [ 1 ] [ i ]=new Vector3D ( this . qubePoints [ 0 ] [ i ] . X,this . qubePoints [ 0 ] [ i ] .Y+d , this . qubePoints [ 0 ] [ i ...

] . Z) ;}for ( int i = 0 ; i < qS . l ength ; i++) {

qS [ i ]= new Sur f ace ( qubePoints [ 0 ] [ 0 ] , qubePoints [ 0 ] [ 1 ] , ...qubePoints [ 0 ] [ 2 ] , qubePoints [ 0 ] [ 3 ] ) ;

}}

public void s e tZPoints ( int [ ] [ ] x ) {int xSca l e=width/x [ 0 ] . l ength ;int ySca l e=depth/x . l ength ;data=new Vector3D [ x . l ength ] [ x [ 0 ] . l ength ] ;for ( int i = 0 ; i < x . l ength ; i++) {

for ( int j = 0 ; j < x [ 0 ] . l ength ; j++) {data [ i ] [ j ]=new Vector3D ( xSca l e ∗ i , ySca l e ∗ j , x [ i ] [ j ] ) ;

}}hope=new Polygon [ ( data . l ength −1) ] [ ( data [ 0 ] . l ength −1) ] [ 2 ] ; //number o f ...

t r i a n g l e s ( twice o f squares )for ( int i = 0 ; i < hope . l ength ; i++) {

for ( int j = 0 ; j < hope [ 0 ] . l ength ; j++) {hope [ i ] [ j ] [ 0 ]=new Polygon (

data [ i ] [ j ] ,data [ i +1] [ j +1] ,data [ i ] [ j +1]) ;

hope [ i ] [ j ] [ 1 ]=new Polygon (data [ i ] [ j ] ,data [ i +1] [ j ] ,data [ i +1] [ j +1]) ;

}}

}

private void updateSur f aces ( ) {i f ( hope !=null ){

for ( int i = 0 ; i < hope . l ength ; i++) {for ( int j = 0 ; j < hope [ 0 ] . l ength ; j++) {

hope [ i ] [ j ] [ 0 ]=new Polygon (transformCOS( data [ i ] [ j ] ) ,transformCOS( data [ i +1] [ j +1]) ,transformCOS( data [ i ] [ j +1]) ) ;

hope [ i ] [ j ] [ 1 ]=new Polygon (transformCOS( data [ i ] [ j ] ) ,transformCOS( data [ i +1] [ j ] ) ,transformCOS( data [ i +1] [ j +1]) ) ;

}}

}}public void setCOSLabel ( Str ing xL , Str ing yL , Str ing zL ) {

xLabel=xL ;

30

Page 31: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

yLabel=yL ;zLabel=zL ;

}private 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 ) ;

}private void drawCOSLabel ( Graphics2D g , Color c ) {

g . s e tCo lor ( c ) ;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 . s e tCo lor ( c ) ;Font f ont = new Font ( ”Dialog” , Font .BOLD, 15) ;g . setFont ( f ont ) ;g . drawString ( xLabel , eX . width , eX . he i ght ) ;g . drawString ( yLabel , eY . width , eY . he i ght ) ;g . drawString ( zLabel , eZ . width , eZ . he i ght ) ;

}private Vector3D po s i t i o n=new Vector3D (0 , 0 , 0 ) ;public void s e tPo int (double x , double y , Graphics2D g ) {

i f ( hope !=null ){i f (x>this . data . l ength −2){

x=this . data . l ength −2;}i f (y>this . data [ 0 ] . l ength −2){

y=this . data [ 0 ] . l ength −2;}i f (x<0){

x=0;}i f (y<0){

y=0;}int xDist=200/data . l ength ;int yDist=200/data [ 0 ] . l ength ;p o s i t i o n .X=( int ) ( xDist∗x ) ;p o s i t i o n .Y=( int ) ( yDist∗y ) ;p o s i t i o n . Z=(data [ ( int )x ] [ ( int ) y ] . Z+data [ ( int ) x+1] [ ( int )y ] . Z

+data [ ( int ) x ] [ ( int )y+1] .Z+data [ ( int )x+1] [ ( int ) ...y+1] .Z) /4 ;

}drawPoint (g ,new Color (255 , 10 , 50 , 70) ) ;

}private void drawPoint ( Graphics2D g , Color c ) {

g . s e tCo lor ( c ) ;Vector3D temp=this . transformCOS( po s i t i o n ) ;Dimension p= this . trans formPoint ( temp) ;double distanceFromViewer =

Math . s q r t ( ( temp .X) ∗( temp .X)+(temp .Y+1300) ∗( temp .Y+1300)+(temp . ...Z) ∗( temp . Z) ) ;

double s i z e=1/distanceFromViewer ∗1300;for ( int i = 0 ; i < 10 ; i++) {

g . f i l l O v a l ( ( int ) (p . width−i ∗ s i z e ) , ( int ) (p . height−i ∗ s i z e ) ,( int ) ( i ∗ s i z e ∗2) , ( int ) ( i ∗ s i z e ∗2) ) ;

}

}

31

Page 32: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

public void drawPlot (Graphics2D g ) {Color c= Color . white ;boolean isBackward=fa l se ;this . drawCoordinateSystem (g , c ) ;this . updateSur f aces ( ) ;i f ( hope !=null ){

for ( int i = 0 ; i < hope . l ength ; i++) {for ( int j = 0 ; j < hope [ 0 ] . l ength ; j++) {

g . s e tCo lor ( hope [ i ] [ j ] [ 0 ] . g e tP r e f e r r edCo l o r ( ) ) ;i f ( ! hope [ i ] [ j ] [ 0 ] . isOnFront ( ) )

g . f i l l P o l y g o n ( hope [ i ] [ j ] [ 0 ] . ...getXPanelCoordinates ( ) , hope [ i ] [ j ...] [ 0 ] . getYPanelCoordinates ( ) , 3 ) ;

else {g . s e tCo lor (new Color (50 , //hope [ i ] [ j ...

] [ 0 ] . g e tPre f e rredColor () . getRed () ,255−hope [ i ] [ j ] [ 0 ] . ...

g e tP r e f e r r edCo l or ...( ) . getGreen ( ) ,

hope [ i ] [ j ] [ 0 ] . ...g e tP r e f e r r edCo l or ...( ) . getGreen ( ) ) ) ;

g . f i l l P o l y g o n ( hope [ i ] [ j ] [ 0 ] . ...getXPanelCoordinates ( ) , hope [ i ] [ j ...] [ 0 ] . getYPanelCoordinates ( ) , 3 ) ;

}g . s e tCo lor ( hope [ i ] [ j ] [ 1 ] . g e tP r e f e r r edCo l o r ( ) ) ;i f ( ! hope [ i ] [ j ] [ 1 ] . isOnFront ( ) )

g . f i l l P o l y g o n ( hope [ i ] [ j ] [ 1 ] . ...getXPanelCoordinates ( ) , hope [ i ] [ j ...] [ 1 ] . getYPanelCoordinates ( ) , 3 ) ;

else {g . s e tCo lor (new Color (50 ,

255−hope [ i ] [ j ] [ 0 ] . ...g e tP r e f e r r edCo l or ...( ) . getGreen ( ) ,

hope [ i ] [ j ] [ 0 ] . ...g e tP r e f e r r edCo l or ...( ) . getGreen ( ) ) ) ;

g . f i l l P o l y g o n ( hope [ i ] [ j ] [ 1 ] . ...getXPanelCoordinates ( ) , hope [ i ] [ j ...] [ 1 ] . getYPanelCoordinates ( ) , 3 ) ;

isBackward=true ;}

}}

}i f ( isBackward ) {

this . drawCoordinateSystem (g , c ) ;}this . drawCOSLabel ( g , c ) ;

}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 ;

32

Page 33: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

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 ;

}}public void s e tOr 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 ;

}public void t r a n s l a t eO r i g i n ( int dx , int dy , int dz ) {

o r i g i n .X+=dx ;o r i g i n .Y+=dy ;o r i g i n . Z+=dz ;

}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) ;}private Dimension trans formPoint ( Vector3D dummy) {

int xEnd=0;int yEnd=0;

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

}

}

Listing 8: Reprasentiert Dreiecke und Berechnet deren Farbungpackage ni ceGraph i cs ;

import java . awt . Color ;import java . awt . Dimension ;

public class Polygon {private Vector3D ult imateViewVector ;public Vector3D normal=new Vector3D (0 , 0 , 0 ) ;public Vector3D [ ] edges=new Vector3D [ 3 ] ;private Vector3D sun = new Vector3D (0 ,0 ,−1) ;

public Polygon (Vector3D edge1 , Vector3D edge2 , Vector3D edge3 ) {Vector3D a = new Vector3D ( edge3 .X−edge1 .X, edge3 .Y−edge1 .Y, edge3 . Z− ...

edge1 . Z) ;Vector3D b = new Vector3D ( edge2 .X−edge1 .X, edge2 .Y−edge1 .Y, edge2 . Z− ...

edge1 . Z) ;normal=this . crossProduct (a , b ) ;// in t l e ng t h = ( in t ) (Math . s q r t ( normal .X∗normal .X+normal .Y∗normal .Y+ ...

normal .Z∗normal .Z) /10) ;//normal=new Vector3D ( normal .X/ leng th , normal .Y/ leng th , normal .Z/ l eng t h ) ...

;edges [0 ]= edge1 ;edges [1 ]= edge2 ;edges [2 ]= edge3 ;ul t imateViewVector = new Vector3D (0 , 0 , 0 ) ;/∗ f o r ( i n t i = 0; i < edges . l e ng t h ; i++) {

t h i s . u l t imateViewVector .X+=edges [ i ] .X;

33

Page 34: Simon Kraeusel - itp.tu-berlin.de · Carnot cylce Simon Kraeusel 14th February 2008 Technische Universit at Berlin Institut fur Theoretische Physik Abstract This documentation is

4 QUELLCODE

t h i s . u l t imateViewVector .Y+=edges [ i ] .Y;t h i s . u l t imateViewVector .Z+=edges [ i ] . Z ;

}t h i s . u l t imateViewVector .X/=3;t h i s . u l t imateViewVector .Y/=3;t h i s . u l t imateViewVector .Z/=3;t h i s . u l t imateViewVector .Y−=1300;∗/this . u l t imateViewVector .X=edges [ 1 ] .X;this . u l t imateViewVector .Y=edges [ 1 ] .Y+1300;this . u l t imateViewVector . Z=edges [ 1 ] . Z ;

}public boolean isOnFront ( ) {

i f ( this . u l t imateViewVector .X∗ this . normal .X+this . u l t imateViewVector .Y∗ this . normal .Y+this . u l t imateViewVector . Z∗ this . normal . Z<0) {

return true ;} elsereturn fa l se ;

}private Vector3D crossProduct ( Vector3D a , Vector3D b) {

return new Vector3D ( a .Y∗b . Z−a . Z∗b .Y, a . Z∗b .X−a .X∗b . Z , a .X∗b .Y−a .Y∗b .X) ;}private Dimension trans formPoint ( Vector3D dummy) {

int xEnd=0;int yEnd=0;

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

}public int [ ] getXPanelCoordinates ( ) {

int x [ ]=new int [ 4 ] ;for ( int i = 0 ; i < edges . l ength ; i++) {

x [ i ]= trans formPoint ( edges [ i ] ) . width ;}x [3]=x [ 0 ] ;return x ;

}public int [ ] getYPanelCoordinates ( ) {

int y [ ]=new int [ 4 ] ;for ( int i = 0 ; i < edges . l ength ; i++) {

y [ i ]= trans formPoint ( edges [ i ] ) . he i ght ;}y [3]=y [ 0 ] ;return y ;

}public Color g e tP r e f e r r edCo l o r ( ) {

double angle = normal .X∗ sun .X+normal .Y∗ sun .Y+normal . Z∗ sun . Z ;angle/=Math . s q r t ( (double) ( normal .X∗normal .X+normal .Y∗normal .Y+normal . Z ...

∗normal . Z) ) ;angle=Math . abs ( angle ) ;return new Color ( ( int ) (250∗ angle ) , ( int ) (250∗ angle ) ,250) ;

}

}

34