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))
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})