Greetings ppl,
i’m in the process of creating a PROTRACTOR application for educational purposes and since it’s my first time attempt on such a thingy, i have some queries that i hope someone might be able to enlighten me regarding some math and trigonometry issues. :stare:
Basically, in order to make life easier for teachers/staff probing the codes later on, i decided to create a few functions and parameters for this application that will dynamically generate:
1.) The angles (A angles is stored every 5 degree) in an array
2.) Co-ordinates of each point on the protractor from 0 - 180 degrees (Don’t be alarmed, co-ordinates are created only every 5 degrees) and store them in multidimensional array.
Having said that, here is the buggy code that i have programmed so far.
Initialising codes:
var possibleAnglesCount:Number = 36; //Amount of angles you want to store into the array "AnglesPositionArray"
var AnglesArray:Array = new Array(); //Create an array to store (In this case - 36) elements containing all the diff. angles needed
var AnglesPositionArray:Array = new Array(); //Create an array to store the X and Y co-ordinates of each snapping points, done by generateSnapPoint()
This is the first function:
/* this function will generate an array containing all the range of angles in degrees needed for computation in generateSnapPoint()
based on the inputs given: AnglesIncrement - How much increment in degree needed for each angle */
function generateAngles(AnglesIncrement:Number):Void {
for(g=0; g<possibleAnglesCount; g++) {
AnglesArray[g] = AnglesIncrement;
AnglesIncrement+=5;
}
};
generateAngles(5);
Second chunk of function:
/* this function will generate an array containing X and Y co-ordinates of each snapping points based on the inputs given:
1.) Co-ordinates of CENTRE POINT for the protractor - x1, y1 2.) Hypotenuse of the triangle/radius - hypLength */
function generateSnapPoint(x1:Number, y1:Number, hypLength:Number):Void {
for(i=0; i<possibleAnglesCount; i++) {
AnglesPositionArray* = new Array();
for(j=0; j<2; j++) { //Max is 2 cos there is only "X & Y" Co-ordinates to store in the array.
if(j==0) {
//Generating & inserting "X Co-Ordinate" of each snapping point into AnglesPositionArray*[0]
adj = Math.cos(AnglesArray*)*hypLength; //length from x1 to "X Co-ordinate" of snapping point
if(AnglesArray*<90 || AnglesArray*==90) {
//if the angle in degree is less than 90, use this statement to produce X Co-ordinate of snapping pt
xCoordinate = x1 + adj; //variable containing the exact X Co-ordinate
}
else if(AnglesArray*>90) {
//if the angle in degree is less than 90, then use this statement to produce X Co-ordinate of snapping pt
xCoordinate = x1 + (adj); //variable containing the exact "X Co-ordinate"
}
AnglesPositionArray*[j] = Math.round(xCoordinate); //STORING of the exact X Co-ordinate into - AnglesPositionArray*[0]
}
else if (j==1) {
//Generating & inserting "Y Co-Ordinate" of each snapping point into AnglesPositionArray*[1]
opp = Math.sin(AnglesArray*)*hypLength; //length from y1 to "Y Co-ordinate" of snapping point
//No conditional statement cos length of "opp" does not contain negative so no need to separate into diff statement
yCoordinate = y1 - opp; //variable containing the exact "Y Co-ordinate"
AnglesPositionArray*[j] = Math.round(yCoordinate); //STORING of the exact Y Co-ordinate into - AnglesPositionArray*[1]
}
}
}
};
generateSnapPoint(300,250,15);
Trace statement -
for(x=0; x<AnglesPositionArray.length; x++) {
for(y=0; y<AnglesPositionArray[x].length; y++) {
trace(AnglesPositionArray[x][y]);
}
};
I hope the above comments is clear enuff to see what each of these statements does. Else, feel free to clarify with me.
Now, in theory, this generateSnapPoint() function would produce the X & Y co-ordinates for each “snap Point” (there will be some use for it later) of the protractor and stored them in multidimensional array.
Give it a go and compile it. In the trace output, you will see a list of number and each are actually a pair of X & Y co-ordinates of each “snap point” in the array.
But here’s the problem -
If you notice carefully, you will observe that the co-ordinates, after mapping out in graph paper, does NOT seem to produce shape following the curves of the protractor…
Now, that means that the co-ordinates are wrong! But if you look at the formulas, it does not look wrong to me…Unless any enlightened ones has spotted something that i did not see?
Please help me if ya able to, i would really really appreciate if someone can spare a little of their precious time to have a look! Thank you!