KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jscience > physics > quantities > Area


1 /*
2  * JScience - Java(TM) Tools and Libraries for the Advancement of Sciences.
3  * Copyright (C) 2005 - JScience (http://jscience.org/)
4  * All rights reserved.
5  *
6  * Permission to use, copy, modify, and distribute this software is
7  * freely granted, provided that this notice is preserved.
8  */

9 package org.jscience.physics.quantities;
10 import org.jscience.physics.units.SI;
11 import org.jscience.physics.units.Unit;
12
13 /**
14  * This class represents the extent of a planar region or of the surface of
15  * a solid measured in square units. The system unit for this quantity
16  * is "m²".
17  *
18  * @author <a HREF="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
19  * @version 1.0, October 24, 2004
20  */

21 public class Area extends Quantity {
22
23     /**
24      * Holds the associated unit.
25      */

26     private final static Unit<Area> UNIT = SI.SQUARE_METER;
27
28     /**
29      * Holds the factory for this class.
30      */

31     private final static Factory<Area> FACTORY = new Factory<Area>(
32             UNIT) {
33         protected Area create() {
34             return new Area();
35         }
36     };
37
38     /**
39      * Represents a {@link Area} amounting to nothing.
40      */

41     public final static Area ZERO = Quantity.valueOf(0, UNIT);
42
43     /**
44      * Default constructor (allows for derivation).
45      */

46     protected Area() {
47     }
48
49     /**
50      * Shows {@link Area} instances in the specified unit.
51      *
52      * @param unit the display unit for {@link Area} instances.
53      */

54     public static void showAs(Unit unit) {
55         QuantityFormat.show(Area.class, unit);
56     }
57
58     ///////////////////
59
// AREA SPECIFIC //
60
///////////////////
61

62     /**
63      * Returns the area of a circle sector (slice of a circle).
64      *
65      * @param radius the circle radius.
66      * @param theta the central angle.
67      * @return the area of the specified circle sector.
68      */

69     public static Area valueOf(Length radius, Angle theta) {
70         // Returns (theta / 2.0) * radius^2
71
return theta.times(radius.times(radius)).times(0.5).to(UNIT);
72     }
73
74     private static final long serialVersionUID = 1L;
75
76 }
77
Popular Tags