[Python] Can an arbitrary angle be trisected with a precision that surpasses any pratical...

Discussão em 'Python' iniciado por Stack, Dezembro 19, 2024.

  1. Stack

    Stack Membro Participativo

    The answer!

    import mpmath as mp


    # Set precision to 64-bit or higher
    mp.mp.dps = 64 # Decimal places for precision

    def trisect_angle(angle_degrees):
    print(f"\nTrisecting angle: {angle_degrees} degrees")
    angle_radians = mp.radians(angle_degrees)

    # Quadrisect the angle
    quadrisected_angle = angle_degrees / 4
    C = mp.radians(quadrisected_angle)

    # Lengths a and b (arbitrary but fixed values, can be adjusted)
    a = b = 40

    # Calculate the length of c using the law of cosines
    c = mp.sqrt(a**2 + b**2 - 2 * a * b * mp.cos(C))
    print(f"Length of c: {mp.nstr(c, 64)}")

    # Calculate angle D in degrees using the law of cosines
    f = g = 30
    angleD_radians = mp.acos((f**2 + g**2 - c**2) / (2 * f * g))
    angleD_degrees = mp.degrees(angleD_radians)
    print(f"Angle D in degrees: {mp.nstr(angleD_degrees, 64)}")

    # Calculate the small error in degrees outside the input angle
    D3 = angleD_degrees * 3 - angle_degrees
    print(f"Total error in degrees outside the input angle: {mp.nstr(D3, 64)}")

    # Calculate angle E in degrees
    angleE = D3 / 4
    angleE_radians = mp.radians(angleE)
    print(f"Angle E in degrees: {mp.nstr(angleE, 64)}")

    # Calculate the length of e using the given formula
    e = 2 * a * mp.sin(angleE_radians / 2)
    print(f"Length of e: {mp.nstr(e, 64)}")

    # Calculate angle H using the law of cosines
    angleH_radians = mp.acos((f**2 + g**2 - e**2) / (2 * f * g))
    angleH_degrees = mp.degrees(angleH_radians)
    print(f"Angle H in degrees: {mp.nstr(angleH_degrees, 64)}")

    # Calculate angle I as the difference between angle D and angle H
    angleI_degrees = angleD_degrees - angleH_degrees
    print(f"Angle I in degrees: {mp.nstr(angleI_degrees, 64)}")

    # Calculate angle J = theta - 3 * I
    angleJ = (angle_degrees - 3 * angleI_degrees) / 4
    print(f"Angle J in degrees: {mp.nstr(angleJ, 64)}")

    # Calculate the length of k using the given formula
    angleJ_radians = mp.radians(angleJ)
    k = 2 * a * mp.sin(angleJ_radians / 2)
    print(f"Length of k: {mp.nstr(k, 64)}")

    # Calculate angle L using the law of cosines
    angleL_radians = mp.acos((f**2 + g**2 - k**2) / (2 * f * g))
    angleL_degrees = mp.degrees(angleL_radians)
    print(f"Angle L in degrees: {mp.nstr(angleL_degrees, 64)}")

    # Calculate angle M as the sum of angle I and angle L
    angleM_degrees = angleI_degrees + angleL_degrees
    print(f"Angle M in degrees: {mp.nstr(angleM_degrees, 64)}")

    return angleM_degrees

    # Loop through angles from 100 to 360 in steps of 30
    for angle in range(0, 361, 20):
    trisect_angle(angle).



    Please analyze my algorithm and give me your opinion. This algorithm trisects arbitrary angles with very high accuracy, precision and simplicity. You can adjust the angles you want to find the results for. Thanks in advance. Written in Python code and you will need to import mpmath as mp.The code sets the precision for the results.

    Continue reading...

Compartilhe esta Página