SRL Archive - Help and Support

SinRule Script


Naum

2009-01-19 11:58:59

Im trying to make this script work out an angle by using values inputted (0 is unknown) and finding a length or angle (depending upon the boolean) for a triangle. Doesn't work?? I've tried lots of things, could someone help. Thanks!

Function FindAngle_SineRule(FindLength : Boolean; SinA, Lengtha, SinB, Lengthb : Extended) : Extended;
Var
Lz : Array [0..1] Of Variant;
Begin
If Not FindLength Then
Begin
If Lengtha > 0 Then
Begin
Lz[0] := Lengtha;
Lz[1] := Lengthb;
End Else
Begin
Lz[0] := Lengthb;
Lz[1] := Lengtha;
end;
If SinB > 0 Then
Result := (Lz[0] * (Sin(SinB)/Lz[1]))
Else
Result := (Lz[1] * (Sin(SinA)/Lz[0]));

End Else
If FindLength Then
Begin
If SinA > 0 Then
Begin
Lz[0] := SinA;
Lz[1] := SinB;
End Else
Lz[0] := SinB;
Lz[1] := SinA;
If Lengtha > 0 Then
Result := (Lz[0] * Lengtha/Sin(Lz[1]))
Else
Result := (Lz[1] * Lengthb/Sin(Lz[0]))
end;
Result := ArcSin(Result);
end;

A G E N T

2009-01-19 17:58:00

Where you're saying:
Sin(angle)
You need to be doing:
Sin(Radians(angle))
as the Sin in SCAR uses radians. I think your code could be simplified a lot though.

E: Here is what I did, if you still have problems with yours

program New;

function SineLaw(Angles, Sides:TExtendedArray):Extended;
begin
if(GetArrayLength(Angles) >= 2)then //need length
begin
Result := ((Sides[0] * Sin(Angles[1]))/Sin(Angles[0]));
Exit;
end else
if(GetArrayLength(Sides) >= 2)then //need angle
begin
Result := Degrees(ArcSin( (Sin(Radians(Angles[0])) * Sides[1]) / Sides[0] ));
Exit;
end else
Writeln('You need SAS or ASA :P');
end;

begin
writeln(floattostr(SineLaw([60], [3,3])));
end.