|
NAMEPhysics::Unit::ScalarSYNOPSIS# Distances $d = new Physics::Unit::Distance('98 mi'); print $d->ToString, "\n"; # prints 157715.712 meter $d->add('10 km'); print $d->ToString, "\n"; # prints 167715.712 meter print $d->value, ' ', $d->default_unit->name, "\n"; # same thing # Convert print $d->ToString('mile'), "\n"; # prints 104.213... mile print $d->convert('mile'), " miles\n"; # same thing (except 'miles') $d2 = new Physics::Unit::Distance('2000'); # no unit given, use the default print $d2->ToString, "\n"; # prints 2000 meter # Times $t = Physics::Unit::Time->new('36 hours'); print $t->ToString, "\n"; # prints 129600 second # Speed = Distance / Time $s = $d->div($t); # $s is a Physics::Unit::Speed object print $s->ToString, "\n"; # prints 1.2941... mps # Automatic typing $s = new Physics::Unit::Scalar('kg m s'); # Unrecognized type print ref $s, "\n"; # $s is a Physics::Unit::Scalar $f = $s->div('3000 s^3'); print ref $f, "\n"; # $f is a Physics::Unit::Force DESCRIPTIONThis package encapsulates information about physical quantities. Each instance of a class that derives from Physics::Unit::Scalar holds the value of some type of measurable quantity. When you use this module, several new classes are immediately available. See the UnitsByType page for a list of types included with the unit library.You will probably only need to use the classes that derive from Physics::Unit::Scalar, such as Physics::Unit::Distance, Physics::Unit::Speed, etc. You can also define your own derived classes, based on types of physical quantities. This module relies heavily on Physics::Unit. Each Scalar object references a Unit object that defines the dimensionality of the Scalar. The dimensionality also identifies (usually) the type of physical quantity that is stored, and the derived class of the object. For example, the class Physics::Unit::Distance uses the Physics::Unit object named 'meter' to define the scale of its object instances. The type of the 'meter' object is 'Distance'. Defining classes that correspond to physical quantity types allows us to overload the arithmetic methods to produce derived classes of the correct type automatically. For example: $d = new Physics::Unit::Distance('98 mi'); $t = new Physics::Unit::Time('36 years'); # $s will be of type Physics::Unit::Speed. $s = $d->div($t); When a new object is created, this package attempts to determine its subclass based on its dimensionality. Thus, when you multiply two Distances together, the result is an Area object. This behavior can be selectively overridden when necessary. For example, both energy and torque have the same dimensions, Force * Distance. Therefore, it remains the programmer's responsibility, in this case, to assign the correct subclass to Scalars that have this dimensionality. See also the Physics::Unit::Scalar::Implementation page for more details. EXPORT OPTIONSBy default, this module exports nothing. You can request all of the functions to be exported as follows:use Physics::Unit::Scalar ':ALL'; Or, you can just get specific ones. For example: use Physics::Unit::Scalar qw( ScalarFactory GetScalar ); FUNCTIONS
METHODS
AUTHORChris Maloney <voldrani@gmail.com>COPYRIGHT AND LICENSECopyright 2002-2003 by Chris MaloneyThis library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Visit the GSP FreeBSD Man Page Interface. |