示例#1
0
def pds_test():
    x = e.Variable(5, "x")
    y = e.Variable(5, "y")
    z = e.Variable(5, "z")

    check_pds(x, {x: 10, y:4})
    check_pds(e.sq(x) + e.sqrt(y) + z, {x: 0.6, y: 10, z: 3})
    check_pds(x - y, {x: 0.6, y: 10})
    check_pds(x * e.pow(y, 4) * z, {x: 0.6, y: 10, z: 3})
    check_pds(x / y, {x: 0.6, y: 10})
    check_pds(e.sq(e.sq(x)), {x: 0.6})
    check_pds(-x, {x: 0.6})
    check_pds(e.sqrt(x), {x: 0.6})
    check_pds(e.pow(x, 2), {x: 0.6})
    check_pds(e.pow(x, 5), {x: 0.6})
    check_pds(e.acos(x), {x: 0.6})
示例#2
0
    def __init__(self, p1, p2):
        self.p1 = p1
        self.p2 = p2

        vx = p1.x - p2.x
        vy = p1.y - p2.y
        self.length = expressions.sqrt(expressions.dot_product(vx, vy, vx, vy))

        super(LineSegment, self).__init__([p1, p2], [])
示例#3
0
def angle(a, b):
    ax = a.p2.x - a.p1.x
    ay = a.p2.y - a.p1.y
    bx = b.p2.x - b.p1.x
    by = b.p2.y - b.p1.y

    dot = e.dot_product(ax, ay, bx, by)
    len_a_squared = e.dot_product(ax, ay, ax, ay)
    len_b_squared = e.dot_product(bx, by, bx, by)

    return e.acos(dot / e.sqrt(len_a_squared * len_b_squared))