Exemple #1
0
    def test1(self):
        'mcni: relative coordinates for geometer'

        from mcni.Geometer2 import Geometer, AbsoluteCoord as abs, RelativeCoord as rel
        geometer = Geometer()

        geometer.register('comp0', abs((0, 0, 0)), abs((0, 0, 0)))
        geometer.register('comp1', abs((0, 0, 0)), abs((0, 90, 0)))
        geometer.register('comp2', rel((0, 0, 1), 'comp1'), abs((0, 0, 0)))
        geometer.register('comp3', rel((0, 0, 0), 'comp2'),
                          rel((3, 4, 5), 'comp2'))
        geometer.register('comp4', abs((0, 0, 0)), rel((0, 0, 90), 'comp0'))
        geometer.register('comp5', abs((0, 0, 0)), rel((0, 90, 0), 'comp4'))
        geometer.register('comp6', rel((1, 2, 3), 'comp5'), abs((0, 0, 0)))

        comp2pos = geometer.position('comp2')
        nt.assert_array_almost_equal(comp2pos, (1, 0, 0))

        comp2ori = geometer.orientation('comp2')
        nt.assert_array_almost_equal(comp2ori, (0, 0, 0))

        comp3pos = geometer.position('comp3')
        nt.assert_array_almost_equal(comp3pos, (1, 0, 0))

        comp3ori = geometer.orientation('comp3')
        nt.assert_array_almost_equal(comp3ori, toMatrix((3, 4, 5)))

        comp5ori = geometer.orientation('comp5')
        nt.assert_array_almost_equal(comp5ori, toMatrix((-90, 0, 90)))

        comp6pos = geometer.position('comp6')
        nt.assert_array_almost_equal(comp6pos, (-2, 3, -1))

        return
Exemple #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