Beispiel #1
0
def quadratic(a, b, c):
    # Returns the two roots of a quadratic
    inside = math.sqrt((b*b) - (4*a*c))
    if a != 0:
        return (-b + inside)/(2*a), (-b - inside)/(2*a)

    return -1, -1
Beispiel #2
0
def quadratic(a, b, c):
    # Returns the two roots of a quadratic
    inside = (b*b) - (4*a*c)

    try:
        inside = math.sqrt(inside)
    except ValueError:
        return -1, -1

    if a == 0:
        return -1, -1

    return (-b + inside)/(2*a), (-b - inside)/(2*a)
Beispiel #3
0
def ray_intersects_with_circle(origin, direction, center, radius):
    L = center - origin
    tca = L.dot(direction)

    if tca < 0:
        return False

    d2 = L.dot(L) - tca * tca

    if d2 > radius:
        return False

    thc = math.sqrt(radius * radius - d2)
    t0 = tca - thc
    t1 = tca + thc

    return t0 > 0 or t1 > 0
Beispiel #4
0
def quadratic(a, b, c):
    # Returns the two roots of a quadratic
    inside = (b*b) - (4*a*c)

    try:
        inside = math.sqrt(inside)
    except ValueError:
        return ()

    if inside < 0:
        return ()

    b = -b
    a = 2*a

    if inside == 0:
        return (b/a,)

    return ((b + inside)/a, (b - inside)/a)
Beispiel #5
0
def vertex_quadratic_solve_for_x_min_non_neg(a, h, k, y):
    try:
        v_sqrt = math.sqrt((y - k) / a)
    except ValueError:
        return 0
    return min_non_neg(v_sqrt + h, -v_sqrt + h)
Beispiel #6
0
def perimeter_of_ellipse(a,b):
    return math.pi * (3*(a+b) - math.sqrt((3*a + b) * (a + 3*b)))