Question: How to fix 'Illegal use of a formal parameter' error in triangle calculation procedure?

Hello. I am trying to create a procedure that calculates the properties of a triangle (such as the sides, angles, area, and centroid) and then plots it. However, when I try to run my code, I keep getting the error:

Runtime error: Error, (in triangle) illegal use of a formal parameter

Here is the code I am using:

triangle := proc({a::numeric := 0, b::numeric := 0, c::numeric := 0, AngleA::numeric := 0, AngleB::numeric := 0, AngleC::numeric := 0})
    local A, B, C, T, Tr, DegreeA, DegreeB, DegreeC, TA, TB, TC, Area, Centroid, AreaLabel, deg, rad;
    uses geometry, plots;

    # Function to convert degrees to radians
    rad := proc(deg) evalf(deg * Pi / 180) end proc;

    # Function to convert radians to degrees
    deg := proc(rad) evalf(rad * 180 / Pi) end proc;

    # Temporary variables for calculations
    local a_calc, b_calc, c_calc, AngleA_calc, AngleB_calc, AngleC_calc;

    a_calc := a;
    b_calc := b;
    c_calc := c;
    AngleA_calc := AngleA;
    AngleB_calc := AngleB;
    AngleC_calc := AngleC;

    # Calculate missing sides or angles
    if a_calc = 0 then
        if AngleA_calc <> 0 and AngleB_calc <> 0 then
            a_calc := b_calc * sin(rad(AngleA_calc)) / sin(rad(AngleB_calc));
        elif AngleA_calc <> 0 and AngleC_calc <> 0 then
            a_calc := c_calc * sin(rad(AngleA_calc)) / sin(rad(AngleC_calc));
        end if;
    elif b_calc = 0 then
        if AngleB_calc <> 0 and AngleA_calc <> 0 then
            b_calc := a_calc * sin(rad(AngleB_calc)) / sin(rad(AngleA_calc));
        elif AngleB_calc <> 0 and AngleC_calc <> 0 then
            b_calc := c_calc * sin(rad(AngleB_calc)) / sin(rad(AngleC_calc));
        end if;
    elif c_calc = 0 then
        if AngleC_calc <> 0 and AngleA_calc <> 0 then
            c_calc := a_calc * sin(rad(AngleC_calc)) / sin(rad(AngleA_calc));
        elif AngleC_calc <> 0 and AngleB_calc <> 0 then
            c_calc := b_calc * sin(rad(AngleC_calc)) / sin(rad(AngleB_calc));
        end if;
    end if;

    if AngleA_calc = 0 then
        AngleA_calc := deg(arccos((b_calc^2 + c_calc^2 - a_calc^2) / (2 * b_calc * c_calc)));
    end if;
    if AngleB_calc = 0 then
        AngleB_calc := deg(arccos((a_calc^2 + c_calc^2 - b_calc^2) / (2 * a_calc * c_calc)));
    end if;
    if AngleC_calc = 0 then
        AngleC_calc := 180 - AngleA_calc - AngleB_calc;
    end if;

    # Convert angles to radians for calculation
    AngleA := rad(AngleA_calc);
    AngleB := rad(AngleB_calc);
    AngleC := rad(AngleC_calc);

    # Define points A, B, and C
    geometry:-point(A, 0, 0);
    geometry:-point(B, c_calc, 0);
    geometry:-point(C, b_calc * cos(AngleA), b_calc * sin(AngleA));

    # Calculate the area using Heron's formula
    s := (a_calc + b_calc + c_calc) / 2;
    Area := sqrt(s * (s - a_calc) * (s - b_calc) * (s - c_calc));
    Area := evalf(Area, 4);

    # Calculate the centroid of the triangle
    Centroid := [(0 + c_calc + b_calc * cos(AngleA)) / 3, (0 + 0 + b_calc * sin(AngleA)) / 3];

    # Text plot for side labels
    T := plots:-textplot([[1/2 * c_calc, 0, cat("c = ", c_calc), align = below], 
                          [1/2 * c_calc + 1/2 * b_calc * cos(AngleA) + 1/30 * a_calc, 1/2 * b_calc * sin(AngleA), cat("a = ", a_calc), align = right], 
                          [1/2 * b_calc * cos(AngleA) - 1/30 * a_calc, 1/2 * b_calc * sin(AngleA), cat("b = ", b_calc), align = left]]);

    # Text plot for angle labels with valid alignment options
    TA := plots:-textplot([0, 0, cat(evalf(deg(AngleA)), "°"), align = right]);
    TB := plots:-textplot([c_calc, 0, cat(evalf(deg(AngleB)), "°"), align = left]);
    TC := plots:-textplot([b_calc * cos(AngleA), b_calc * sin(AngleA), cat(evalf(deg(AngleC)), "°"), align = above]);

    # Text plot for the area of the triangle
    AreaLabel := plots:-textplot([Centroid[1], Centroid[2], cat("Area= ", Area), align = above]);

    # Display the triangle with labels
    plots:-display([geometry:-draw([geometry:-triangle(Tr, [A, B, C])], 
                      font = [times, roman, 18], labels = [x, y], axes = none, printtext = true), T, TA, TB, TC, AreaLabel]);
end proc:

What am I doing wrong, and how can I fix this error? Thanks! 

Please Wait...