Hello
firstly i have looked through so many examples explaining trigonometry, ive even got out my old GCSE maths text books (no hope) and my old scientific calculator doesnt seem to give sensible answers.
Here is some code so i can explain what is happening, i hope…
xPos = 100;
yPos = 100;
wPos = 200;
hPos = 200;
// square
clear();
lineStyle(1, 0, 100);
moveTo(xPos,yPos);
lineTo(xPos+wPos,yPos);
lineTo(xPos+wPos,yPos+hPos);
lineTo(xPos,yPos+hPos);
lineTo(xPos,yPos);
// triangle
lineStyle(1, 0xff0000, 100);
moveTo(xPos,yPos+hPos);
lineTo(xPos+wPos,yPos+(hPos/2));
lineTo(xPos+wPos,yPos+hPos);
lineTo(xPos,yPos+hPos);
var pythagoras:Number;
pythagoras = (wPos*wPos)+((hPos/2)*(hPos/2));
pythagoras = Math.sqrt(pythagoras);
trace(pythagoras);
var theta:Number = 22.5;
var rad = theta*(Math.PI/180);
hyp = wPos/Math.sin(rad)
trace(hyp+" - hyp");
opp = (Math.cos(rad)*wPos);
trace(opp+" - opp");
adj = (Math.sin(rad)*hPos);
trace(adj+" - adj");
the trace results are…
223.606797749979
522.625185950551 - hyp
184.775906502257 - opp
76.5366864730179 - adj
My main problem (my current project) is calculating the hypotenuse value of a triangle. I know what the angle is; the example is 22.5 The two sides for problem solving reasons i have kept simple, 200 each. Though in my current project the sides will differ.
I need to know the hypotenuse value as the angle in the botom left corner changes. My understanding goes like this…
I know the angle and one side of the shape. Using cos and sin i work out the x,y values. Based on my GCSE text book (again that is if i have understood this properly) to get the hyp value, I use sin. The flash code i have used is “wPos/Math.sin(rad)” but the result is not the same as the pythagoras value…
In my example have i written the syntax correctly, what am i doing wrong??? The trace results do not return correct values…
adj should be 200, opp should be 100 and i believe the hyp should be 223.61
Have I totaly misunderstood and got it all wrong??? Please forgive me for being thick especially when maths is involved!!!
Could anyone put me out of my misery???
Many thanks
Mike :o)