SRL Archive - Research & Development Lounge

a few pythag functions


Awkwardsaw

2009-07-14 07:22:06

im bored, and i figured i would do some math stuff, since its just so gosh dang fun :p

the first function says if the triangle is acute, right, or obtuse based off of the sides, and the second one solves the sides of a RIGHT triangle(leave the side you dont know as what ever you want). i might make sin cos and tan stuff, but those where my weak spots in school =\

and if you don't remember, a = long leg, b = short leg, and c = hypotenuses

the solveside uses either sin, cos, or tan, and a side length to find the measurement of the other unknown side. what you use is up to you, but you have to do it correctly, as in get the correct sin/cos/tan value, and side measure. remember, the trig values are in DEGREES not radians.

the areoftri solves the area of a triangle. either equilateral or other(every other type of triangle, based off of sides).

function TriAngType(a, b, c: extended): string;
begin
if a + b <= c then
begin
writeln('Wrong Triangle side measures');
exit;
end;
if Sqr(a) + sqr(b) > sqr(c) then result:= 'acute';
if Sqr(a) + sqr(b) = sqr(c) then result:= 'right';
if Sqr(a) + sqr(b) < sqr(c) then result:= 'obtuse';
end;

function RightTriSideMeasure(a, b, c: extended; sidetosolve: string; showwork: boolean): extended;
begin
case lowercase(sidetosolve) of
'a': begin
if showwork then
begin
writeln(floattostr(c) + '^2 = ' + floattostr(b) + '^2 + a^2');
writeln(floattostr(Sqr(c)) + ' = ' + floattostr(Sqr(b)) + ' + a^2');
writeln(floattostr(Sqr(c) - Sqr(b)) + ' = a^2');
writeln(floattostr(sqrt((Sqr(c)) - (sqr(b)))) + ' = a');
end;
result:= sqrt((Sqr(c)) - (sqr(b)));
end;
'b': begin
if showwork then
begin
writeln(floattostr(c) + '^2 = b^2 + ' + floattostr(a) + '^2');
writeln(floattostr(Sqr(c)) + ' = b^2 + ' + floattostr(Sqr(a)));
writeln(floattostr(Sqr(c) - Sqr(a)) + ' = b^2');
writeln(floattostr(sqrt((Sqr(c)) - (sqr(a)))) + ' = b');
end;
result:= sqrt((Sqr(c)) - (sqr(a)));
end;
'c': begin
if showwork then
begin
writeln('c^2 = ' + floattostr(b) + '^2 + ' + floattostr(a) + '^2');
writeln('c^2 = ' + floattostr(sqr(b)) + ' + ' + floattostr(sqr(a)));
writeln('c^2 = ' + floattostr(sqr(b) + sqr(a)));
writeln('c = ' + floattostr(sqrt(Sqr(a) + sqr(b))));
end;
result:= sqrt(Sqr(a) + sqr(b));
end;
end;
end;

function solveside(sincostannum, l: extended): extended;
var a, b: extended;
begin
a:= sincostannum;
b:= l;
result:= (a * b) * 2;
end;

function AreaOfTri(typeoftri: string; side1, side2: extended):extended;
begin
case lowercase(typeoftri) of
'equilateral': result:= (sqr(side1) * sqrt(3)) / 4;
'other': result:= ((side1 * side2) / 2);
end;
end;

i tested all of these using the theorem and properties that i remember, so if they aren't correct post here. although they do work

enjoy :p

ian.

2009-07-14 07:51:03

A few flaws, one sec.


program New;

function TriAngType(a, b, c: extended): string;
begin
if a + b <= c then //30, 60, 90? :o 45, 45, 90? ;)
begin
writeln('Wrong Triangle side measures');
exit;
end;
if Sqr(a) + sqr(b) < sqr(c) then result:= 'acute';
if Sqr(a) + sqr(b) = sqr(c) then result:= 'right';
if Sqr(a) + sqr(b) > sqr(c) then result:= 'obtuse'; //60, 60, 60 is acute ;)
end;

function RightTriSideMeasure(a, b, c: extended; sidetosolve: string; showwork: boolean): extended;
begin
case lowercase(sidetosolve) of
'a': begin
if showwork then
begin
writeln(floattostr(c) + '^2 = ' + floattostr(b) + '^2 + a^2');
writeln(floattostr(Sqr(c)) + ' = ' + floattostr(Sqr(b)) + ' + a^2');
writeln(floattostr(Sqr(c) - Sqr(b)) + ' = a^2');
writeln(floattostr(sqrt((Sqr(c)) - (sqr(b)))) + ' = a');
end;
result:= sqrt((Sqr(c)) - (sqr(b)));
end;
'b': begin
if showwork then
begin
writeln(floattostr(c) + '^2 = b^2 + ' + floattostr(a) + '^2');
writeln(floattostr(Sqr(c)) + ' = b^2 + ' + floattostr(Sqr(a)));
writeln(floattostr(Sqr(c) - Sqr(a)) + ' = b^2');
writeln(floattostr(sqrt((Sqr(c)) - (sqr(a)))) + ' = b');
end;
result:= sqrt((Sqr(c)) - (sqr(a)));
end;
'c': begin
if showwork then
begin
writeln('c^2 = ' + floattostr(b) + '^2 + ' + floattostr(a) + '^2');
writeln('c^2 = ' + floattostr(sqr(b)) + ' + ' + floattostr(sqr(a)));
writeln('c^2 = ' + floattostr(sqr(b) + sqr(a)));
writeln('c = ' + floattostr(sqrt(Sqr(a) + sqr(b))));
end;
result:= sqrt(Sqr(a) + sqr(b));
end;
end;
end;

begin
Writeln(RightTriSideMeasure(30, 60, 90, 'c', True));
end.

{For a 30, 60, 90 triangle..
Successfully compiled (45 ms)
90^2 = 60^2 + a^2
8100 = 3600 + a^2
4500 = a^2
67.0820393249937 = a
67.0820393249937
Successfully executed
Successfully compiled (39 ms)
90^2 = b^2 + 30^2
8100 = b^2 + 900
7200 = b^2
84.8528137423857 = b
84.8528137423857
Successfully executed
Successfully compiled (40 ms)
c^2 = 60^2 + 30^2
c^2 = 3600 + 900
c^2 = 4500
c = 67.0820393249937
67.0820393249937
Successfully executed

That's not right.}

Just commented stuff. Didn't change anything :) I think you can do it.

Awkwardsaw

2009-07-14 07:58:22

you messed up :P its based off of sides, not angles.


RightTriSideMeasure(3, 4, 5, 'c', true);

3-4-5 side triangles are 30-60-90 angle triangles.


5^2 = 4^2 + a^2
25 = 16 + a^2
9 = a^2
3 = a

5^2 = b^2 + 3^2
25 = b^2 + 9
16 = b^2
4 = b

c^2 = 4^2 + 3^2
c^2 = 16 + 9
c^2 = 25
c = 5

ian.

2009-07-14 08:18:01

Ohhh ;) haha mmkay. :] Good work.

Awkwardsaw

2009-07-14 08:22:06

From: 99_ aka ian.
Ohhh ;) haha mmkay. :] Good work.


;) ty haha

marpis

2009-07-14 08:32:38

30, 60, 90 isn't even a right triangle

30^2 + 60^2 = 90^2
900 + 3600 = 8100
4500 <> 8100

EDIT: I really can't get into your mind :D

Awkwardsaw

2009-07-14 08:36:09

:p

you use SIDES to determine them, not angles ;) i guess i have to write a mini tut haha

and ffs, sin cos tan is pissing me off.

haha

function solveside(sincostannum, l: extended): extended;
var a, b: extended;
begin
a:= sincostannum;
b:= l;
result:= a * b;
end;

i know for a fact, that sin 45 degrees = 0.7071, and a side length of a side is 4(which means the other is 4, because its an isosceles right triangle). and i know for a fact that the hypot is 5.65.

BUT when i use solveside(0.7071, 4) it returns 2.8284, which is totally not right.

when i use my calculator, i get the correct answer though, using the same formula.

edit: i didnt know radians where = to half of degrees :p

2.8284 * 2 = 6.6568

/facepalm

n3ss3s

2009-07-14 12:06:52

Cosine law, blasting triangles since 15th century… Right triangle or not.

mixster

2009-07-14 12:20:10

Radians aren't half of degrees silly! On a basic level, a radian is relates more to the circumference of a circle with 1 radian being an angle that results in an arc the same length as the radius.
If you do not know them, then just use Radians(deg) and Degrees(rad) to convert between the two - afaik all Scar trig functions take and return radian based values where an angle is needed or returned :)

n3s: I made something for cosine and sine laws - it's somewhere in some other trig topic where someone mentioned it.

Awkwardsaw

2009-07-14 17:10:44

:p i wasnt awear of the converter of degrees and radians. although tbh, just doubling a radian has fixed it so far.

and n3s, i only took basic geometery :p. i think thats over my head still

Naum

2009-07-14 19:37:06

From: mixster
Radians aren't half of degrees silly! On a basic level, a radian is relates more to the circumference of a circle with 1 radian being an angle that results in an arc the same length as the radius.
If you do not know them, then just use Radians(deg) and Degrees(rad) to convert between the two - afaik all Scar trig functions take and return radian based values where an angle is needed or returned :)

n3s: I made something for cosine and sine laws - it's somewhere in some other trig topic where someone mentioned it.


Mixster Skillz:

function CosineLaw(a, b, c: Extended; len: Boolean): Extended;
//a^2 = b^2 + c^2 - 2bcCosA
begin
if (len) then
Result := Sqrt(Sqr(b) + Sqr(c) - (2 * b * c * Cos(a)))
else
Result := ArcCos((Sqr(c) + Sqr(b) - Sqr(a)) / (2 * b * c));
end;

:)

Awkwardsaw

2009-07-14 19:40:08

From: NaumanAkhlaQ
Mixster Skillz:

function CosineLaw(a, b, c: Extended; len: Boolean): Extended;
//a^2 = b^2 + c^2 - 2bcCosA
begin
if (len) then
Result := Sqrt(Sqr(b) + Sqr(c) - (2 * b * c * Cos(a)))
else
Result := ArcCos((Sqr(c) + Sqr(b) - Sqr(a)) / (2 * b * c));
end;

:)


like i said :p all i know about sin-cos-tan is the very basics, as in how to find the value, and how to use it( i guess )

Blender

2009-07-15 02:09:51

That's why you take a trig class :P

And personally, I like the Law of Sines better than the Law of Cosines.


This is the sine function owning the cosine.

Awkwardsaw

2009-07-15 02:52:04

my school doesnt have trig, nor engineer math =\

unless this stuff is used in pre/norm calc. or algebra 3/4 (or 2 for some people)