def angle(u):
    l = vec.length(u)

    if util.isAlmostZero(l):
       return 0.0

    assert util.isAlmostEq(vec.length(u), 1.0), "input must be normalized, not " + str(u)

    return math.atan2(u[1], u[0])
Beispiel #2
0
def angle(u):
    l = vec.length(u)

    if util.isAlmostZero(l):
        return 0.0

    assert util.isAlmostEq(vec.length(u),
                           1.0), "input must be normalized, not " + str(u)

    return math.atan2(u[1], u[0])
Beispiel #3
0
def drawArrow(begin, lvec, lineSize):
    assert util.isAlmostEq(1.0, vec.length(lvec)), "unnormalized input"

    headSize = 0.5 * lineSize
    lAngle = 2.5
    rAngle = -2.5

    # TODO: get rid of all these constructor calls
    hvec1 = zeros((util.numDim, ), float)
    hvec2 = zeros((util.numDim, ), float)
    tmp = zeros((util.numDim, ), float)

    hvec1 = vec.scale(
        array([
            lvec[0] * math.cos(lAngle) - lvec[1] * math.sin(lAngle),
            lvec[0] * math.sin(lAngle) + lvec[1] * math.cos(lAngle)
        ]), headSize, hvec1)
    hvec2 = vec.scale(
        array([
            lvec[0] * math.cos(rAngle) - lvec[1] * math.sin(rAngle),
            lvec[0] * math.sin(rAngle) + lvec[1] * math.cos(rAngle)
        ]), headSize, hvec2)

    tmp = vec.scale(lvec, lineSize, tmp)

    rightWay = True
    glPushMatrix()
    if rightWay:
        glTranslate(begin[0], begin[1], 0.0)
    else:
        glTranslate(begin[0] - tmp[0], begin[1] - tmp[1], 0.0)

    glBegin(GL_LINE_STRIP)
    glVertex(0.0, 0.0)
    glVertex(tmp[0], tmp[1])
    glVertex(tmp[0] + hvec1[0], tmp[1] + hvec1[1])
    glEnd()
    glPopMatrix()

    glPushMatrix()
    if rightWay:
        glTranslate(begin[0] + tmp[0], begin[1] + tmp[1], 0.0)
    else:
        glTranslate(begin[0], begin[1], 0.0)

    glBegin(GL_LINES)
    glVertex(0.0, 0.0)
    glVertex(hvec2[0], hvec2[1])
    glEnd()
    glPopMatrix()
Beispiel #4
0
    def setOrientation(self, orientation):
        assert util.isAlmostEq(1.0, vec.length(orientation)), 'invalid orientation ' + str(orientation)

        vec.copy(orientation, self.orientation)
Beispiel #5
0
    def getOrientation(self):
        assert util.isAlmostEq(1.0, vec.length(self.shape.orientation)), 'invalid orientation ' + str(self.shape.orientation)

        return self.shape.orientation
    def setOrientation(self, orientation):
        assert util.isAlmostEq(1.0, vec.length(orientation)), 'invalid orientation ' + str(orientation)

        vec.copy(orientation, self.orientation)
    def getOrientation(self):
        assert util.isAlmostEq(1.0, vec.length(self.shape.orientation)), 'invalid orientation ' + str(self.shape.orientation)

        return self.shape.orientation