// Use this for initialization void Awake() { // Initiates and sets users line to a graphical object of type line_user user = FindObjectOfType <line_user> (); // Initiates and sets users line to a graphical object of type line_user comp = FindObjectOfType <line_computer> (); // Sets the parameters for the sin(x) function // Sets the initial amplitude to be one cons_u [0, 0] = 1F; // Choses randomly the initial amplitude cons_u[0, 1] = 5 * Random.value - 2.5F; // Choses randomly the initial phase difference cons_u[0, 2] = 5 * Random.value - 2.5F; // Stores the initial amplitude cons_u[0, 3] = cons_u[0, 1]; // Sets the parameters for the cos(x) function // Sets the initial amplitude to be one cons_u[1, 0] = 1F; // Choses randomly the initial amplitude cons_u[1, 1] = 5 * Random.value - 2.5F; // Choses randomly the initial phase difference cons_u[1, 2] = 5 * Random.value - 2.5F; // Stores the initial amplitude cons_u[1, 3] = cons_u[1, 1]; // Sets the value of slider to the stored value of the amplitude // Look up into this // user.mainSlider.value = (cons_u[0, 1] + 2.5F) / 5F; // Sets up the computer line user.Set_y(cons_u); // Creates a copy of a constant matix for (int i = 0; i < degree * 2; i++) { for (int j = 0; j < 4; j++) { cons_c[i, j] = cons_u[i, j]; } } // Choses the constants for the computer's graph that would not differ from the // previously choosen constants for more then one. while (Mathf.Abs(cons_c [0, 1] - cons_u [0, 1]) < 1) { while (Mathf.Abs(cons_c [0, 2] - cons_u [0, 2]) < 1) { cons_c [0, 2] = 5 * Random.value - 2.5F; } cons_c [0, 1] = 5 * Random.value - 2.5F; } // Sets up the computer line comp.Set_y(cons_c); }
public float MaxDif(line_computer line_comp_temp, line_user line_user_temp) { float max = -1F; term_id = -1; float temp = max; for (int i = 3; i < n_points - 1; i++) { temp = Mathf.Abs(line_user_temp.y[i] - line_comp_temp.y[i]); if (temp > max) { max = temp; term_id = i; } } return(max); }