Ejemplo n.º 1
0
def calculateAbsoluteCoordinates(relative_coordinates, component_sequence):
    '''calculate the "absolute coordindates" of elements out of the "relative coordinates"

    The so-called "relative coordinates" are used to describe the geometrical
    interrelation of the elements. For example

     "guide2":  "guide1", [0,0,3], [[1,0,0], [0,0,1], [0,-1,0]] 

    means that guide2 is z=3 relative to guide1, and rotated 90 degrees along x axis.

    The format of a relative_coordinate is

      element: reference_element, position, orientation

    where position is a vector, and orientation is a 3X3 matrix.

    When reference_element is not specified, the entry is an absolute coordinate.

    There must be at least one entry in relative_coordinates that is "absolute".

    The whole set of relative_coordinates specification must be complete enough
    to resolve the absolute coordinates of all elements.
    '''
    from mcni.Geometer2 import Geometer, RelativeCoord as rel, AbsoluteCoord as abs
    geometer = Geometer()
    geometer.element_sequence = component_sequence

    for element in relative_coordinates:
        reference, position, orientation = relative_coordinates[element]
        if reference:
            geometer.register(element, rel(position, reference),
                              rel(orientation, reference))
        else:
            geometer.register(element, abs(position), abs(orientation))
        continue

    d = {}
    for element in relative_coordinates:
        d[element] = geometer.position(element), geometer.orientation(element)
    return d
Ejemplo n.º 2
0
def calculateAbsoluteCoordinates(relative_coordinates, component_sequence):
    '''calculate the "absolute coordindates" of elements out of the "relative coordinates"

    The so-called "relative coordinates" are used to describe the geometrical
    interrelation of the elements. For example

     "guide2":  "guide1", [0,0,3], [[1,0,0], [0,0,1], [0,-1,0]] 

    means that guide2 is z=3 relative to guide1, and rotated 90 degrees along x axis.

    The format of a relative_coordinate is

      element: reference_element, position, orientation

    where position is a vector, and orientation is a 3X3 matrix.

    When reference_element is not specified, the entry is an absolute coordinate.

    There must be at least one entry in relative_coordinates that is "absolute".

    The whole set of relative_coordinates specification must be complete enough
    to resolve the absolute coordinates of all elements.
    '''
    from mcni.Geometer2 import Geometer, RelativeCoord as rel, AbsoluteCoord as abs
    geometer = Geometer()
    geometer.element_sequence = component_sequence
    
    for element in relative_coordinates:
        reference, position, orientation = relative_coordinates[element]
        if reference:
            geometer.register(element, rel(position, reference), rel(orientation, reference))
        else:
            geometer.register(element, abs(position), abs(orientation))
        continue
    
    d = {}
    for element in relative_coordinates:
        d[element] = geometer.position(element), geometer.orientation(element)
    return d