// // Vector getRelationship(f, r, c, theta) // Last modified: 28Aug2006 // // Uses the secant method to calculate the intersection of the function // and a circle centered at the parameterized vector position c with // the appropriate radius, returning a vector from c to this intersection. // // The secant method is defined by the following recurrence relation: // // x_(n + 1) = x_n - f(x_n) * (x_n - x_(n - 1)) / (f(x_n) - f(x_(n - 1))). // // Returns: vector from the parameterized vector position c // to the intersection of the function and appropriate circle // Parameters: // f in the intersecting function // r in the radius of the intersecting circle // c in the position to be centered at // theta in the rotation of the relationship (default 0) // Vector Formation::getRelationship(const Function f, const GLfloat r, const Vector c, const GLfloat theta) { if (f == NULL) return Vector(); GLfloat xn = c.x + r + X_ROOT_THRESHOLD, xn_1 = c.x + r - X_ROOT_THRESHOLD, intersect = 0.0f, error = 0.0f; for (int i = 0; i < X_N_ITERATIONS; ++i) { intersect = fIntersect(f, r, c, xn); error = intersect * (xn - xn_1) / (intersect - fIntersect(f, r, c, xn_1)); if (abs(error) <= X_ROOT_THRESHOLD) break; xn_1 = xn; xn -= error; } Vector rel = Vector(xn, f(xn)) - c; rel.rotateRelative(-theta); return rel; } // getRelationship(const..{Function, GLfloat, Vector, GLfloat})
// Uses the secant method to calculate the intersection of the function // and a circle centered at the parameterized vector position c with // the appropriate radius, returning a vector from c to this intersection. // // The secant method is defined by the following recurrence relation: // // x_(n + 1) = x_n - f(x_n) * (x_n - x_(n - 1)) / (f(x_n) - f(x_(n - 1))). // // Returns: vector from the parameterized vector position c // to the intersection of the function and appropriate circle // Parameters: // f in the intersecting function // r in the radius of the intersecting circle // c in the position to be centered at // theta in the rotation of the relationship (default 0) // Vector Formation::calculateDesiredRelationship(const Function f, const float r, const Vector c, const float theta) { // TODO: HERE IS THE GOOFY ONE if (f == NULL) return Vector(); float xn = c.x + r + X_ROOT_THRESHOLD, xn_1 = c.x + r - X_ROOT_THRESHOLD, intersect = 0.0f, error = 0.0f; for (int i = 0; i < X_N_ITERATIONS; ++i) { intersect = fIntersect(f, r, c, xn); error = intersect * (xn - xn_1) / (intersect - fIntersect(f, r, c, xn_1)); if (abs(error) <= X_ROOT_THRESHOLD) break; xn_1 = xn; xn -= error; } Vector rel = Vector(xn, f(xn)) - c; rel.rotateRelative(-theta); return rel; }