phystricks
Public Member Functions | Public Attributes | List of all members
phystricks.src.Utilities.ConversionAngles Class Reference
Inheritance diagram for phystricks.src.Utilities.ConversionAngles:
Inheritance graph
[legend]
Collaboration diagram for phystricks.src.Utilities.ConversionAngles:
Collaboration graph
[legend]

Public Member Functions

def __init__ (self, conversion_factor, max_value, exit_attribute=None, create_function=None)
 
def simplify (self, angle, keep_max=False, keep_large=False, number=False, numerical=False)
 
def conversion (self, theta, number=False, keep_max=False, keep_large=False, converting=True, numerical=False)
 

Public Attributes

 conversion_factor
 
 max_value
 
 exit_attribute
 
 create_function
 

Detailed Description

Simplify and convert angle units.

This class serves to factorise conversion degree -> radian and radian -> degree
INPUT:
- ``conversion_factor`` - the conversion factor from the considered unit to the other (radian->degree or the contrary)
- ``max_value`` - the maximal value (360 or 2*pi)

Constructor & Destructor Documentation

def phystricks.src.Utilities.ConversionAngles.__init__ (   self,
  conversion_factor,
  max_value,
  exit_attribute = None,
  create_function = None 
)

Member Function Documentation

def phystricks.src.Utilities.ConversionAngles.conversion (   self,
  theta,
  number = False,
  keep_max = False,
  keep_large = False,
  converting = True,
  numerical = False 
)
Makes the conversion and simplify.

INPUT:

- ``theta`` - the angle to be converted.
- ``number`` - (default =False) If true, return a number. Not to be confused with <numerical>.
- ``keep_max`` - (default False) If true, does not convert the max value into the minimal value.  Typically, leaves 2*pi as 2*pi instead of returning 0.
- ``keep_large`` - (default False) if an angle larger that 2pi is given, return an angle larger than 2pi.
- ``converting`` - (defaut = True) If False, make no conversion.
- ``numerical`` - (default = False) boolean. If True, return a numerical approximation.  If <numerical>=True, then <number> is automatically switched to True.

EXAMPLES:

For converting 7 radian into degree, make the following::

    sage: from phystricks.SmallComputations import *
    sage: degree=ConversionAngles(180/pi,360).conversion
    sage: degree(7)     
    1260/pi - 360

Notice that the result is an exact value. If you want a numerical approximation::

    sage: degree(7,numerical=True)
    41.0704565915763
    sage: numerical_approx(degree(7))
    41.0704565915763
    sage: degree(120,converting=False)
    120

Using `converting=False,number=True` is a way to ensure something to be a number instead of a AngleMeasure. For that, we need to precise
what unit we want to produce. This is done by `self.exit_attribute`.
A realistic way to define a function that converts to degree is::

    sage: DegreeConversions=ConversionAngles(SR(180)/pi,360,exit_attribute="degree",create_function=DegreeAngleMeasure)
    sage: degree=DegreeConversions.conversion
    sage: a=45 
    sage: b=AngleMeasure(value_radian=pi/4)
    sage: degree(a,number=True,converting=False)
    45
    sage: degree(b,number=True,converting=False)
    45
def phystricks.src.Utilities.ConversionAngles.simplify (   self,
  angle,
  keep_max = False,
  keep_large = False,
  number = False,
  numerical = False 
)
Simplify the angles modulo the maximum (if 'keep_large'=False, which is default). 

If what is given is a number, return a number. If what is given is a AngleMeasure, return a new AngleMeasure.

Keep the negative numbers to negative numbers. The return interval is
[-2 pi,2pi]
which could be open or closed following the `keep_max` boolean.
    
INPUT:

- ``angle`` - an angle that can be an instance of AngleMeasure or a number.  if it is a number, the simplify modulo self.max_value if it is a AngleMeasure, then first extract the value of the angle using self.exit_attribute .

- ``keep_max`` - (default=False) If True, does not simplify the angle with max value.  Typically, keeps 2*pi as 2*pi.  This is used in order to keep track of the difference between 0 and 2*pi in the context of drawing an full circle.
- ``keep_large`` - (default=False)  If True, an angle larger than 2pi remains large than 2pi.

- ``number`` - (default=False) If True, return a number even is a AngleMeasure is given.

- ``numerical`` - (default=False) If True, return numerical_approx of the result

NOTE:
`number=True` allows exit like pi/2 while numerical will return 1.57079632679490.


EXAMPLES::

    sage: from phystricks.SmallComputations import *
    sage: simplify_degree=ConversionAngles(180/pi,360).simplify
    sage: simplify_degree(400)
    40

If <keep_max> is True, maximal values are kept::

    sage: simplify_degree(500,keep_max=True)
    140
    sage: simplify_degree(360,keep_max=True)
    360

Negative numbers are kept negative::

    sage: simplify_degree(-10)
    -10
    sage: simplify_degree(-380)
    -20
    sage: simplify_degree(-360)
    0
    sage: simplify_degree(-360,keep_max=True)
    -360

Member Data Documentation

phystricks.src.Utilities.ConversionAngles.conversion_factor
phystricks.src.Utilities.ConversionAngles.create_function
phystricks.src.Utilities.ConversionAngles.exit_attribute
phystricks.src.Utilities.ConversionAngles.max_value

The documentation for this class was generated from the following file: