本文整理汇总了Java中org.apache.harmony.awt.gl.Crossing.solveCubic方法的典型用法代码示例。如果您正苦于以下问题:Java Crossing.solveCubic方法的具体用法?Java Crossing.solveCubic怎么用?Java Crossing.solveCubic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.harmony.awt.gl.Crossing
的用法示例。
在下文中一共展示了Crossing.solveCubic方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: intersectLineAndCubic
import org.apache.harmony.awt.gl.Crossing; //导入方法依赖的package包/类
/**
* It checks up if the line (x1, y1) - (x2, y2) and
* the cubic curve (cx1, cy1) - (cx2, cy2) - (cx3, cy3) - (cx4, cy4).
* The points of the intersection is saved to points array.
* Therefore the points size must be at learst 6.
* @return The method returns the quantity of roots lied in the defined interval
*/
public static int intersectLineAndCubic(double x1, double y1, double x2, double y2,
double cx1, double cy1, double cx2, double cy2,
double cx3, double cy3, double cx4, double cy4,
double[] params) {
double[] eqn = new double[4];
double[] t = new double[3];
double[] s = new double[3];
double dy = y2 - y1;
double dx = x2 - x1;
int quantity = 0;
int count = 0;
eqn[0] = (cy1 - y1) * dx + (x1 - cx1) * dy;
eqn[1] = - 3 * (cy1 - cy2) * dx + 3 * (cx1 - cx2) * dy ;
eqn[2] = (3 * cy1 - 6 * cy2 + 3 * cy3) * dx - (3 * cx1 - 6 * cx2 + 3 * cx3) * dy;
eqn[3] = (- 3 * cy1 + 3 * cy2 - 3 * cy3 + cy4) * dx +
(3 * cx1 - 3 * cx2 + 3 * cx3 - cx4) * dy;
if ((count = Crossing.solveCubic(eqn, t)) == 0) {
return 0;
}
for (int i = 0; i < count; i++) {
if (dx != 0) {
s[i] = (cubic(t[i], cx1, cx2, cx3, cx4) - x1) / dx;
} else if (dy != 0) {
s[i] = (cubic(t[i], cy1, cy2, cy3, cy4) - y1) / dy;
} else {
s[i] = 0.0;
}
if (t[i] >= 0 && t[i] <= 1 && s[i] >= 0 && s[i] <= 1) {
params[2 * quantity] = t[i];
params[2 * quantity + 1] = s[i];
++quantity;
}
}
return quantity;
}
示例2: intersectLineAndCubic
import org.apache.harmony.awt.gl.Crossing; //导入方法依赖的package包/类
/**
* It checks up if the line (x1, y1) - (x2, y2) and the cubic curve (cx1,
* cy1) - (cx2, cy2) - (cx3, cy3) - (cx4, cy4). The points of the
* intersection is saved to points array. Therefore the points size must be
* at learst 6.
*
* @return The method returns the quantity of roots lied in the defined
* interval
*/
public static int intersectLineAndCubic(double x1, double y1, double x2, double y2, double cx1, double cy1,
double cx2, double cy2, double cx3, double cy3, double cx4, double cy4, double[] params) {
double[] eqn = new double[4];
double[] t = new double[3];
double[] s = new double[3];
double dy = y2 - y1;
double dx = x2 - x1;
int quantity = 0;
int count = 0;
eqn[0] = (cy1 - y1) * dx + (x1 - cx1) * dy;
eqn[1] = -3 * (cy1 - cy2) * dx + 3 * (cx1 - cx2) * dy;
eqn[2] = (3 * cy1 - 6 * cy2 + 3 * cy3) * dx - (3 * cx1 - 6 * cx2 + 3 * cx3) * dy;
eqn[3] = (-3 * cy1 + 3 * cy2 - 3 * cy3 + cy4) * dx + (3 * cx1 - 3 * cx2 + 3 * cx3 - cx4) * dy;
if ((count = Crossing.solveCubic(eqn, t)) == 0) {
return 0;
}
for (int i = 0; i < count; i++) {
if (dx != 0) {
s[i] = (cubic(t[i], cx1, cx2, cx3, cx4) - x1) / dx;
} else if (dy != 0) {
s[i] = (cubic(t[i], cy1, cy2, cy3, cy4) - y1) / dy;
} else {
s[i] = 0.0;
}
if (t[i] >= 0 && t[i] <= 1 && s[i] >= 0 && s[i] <= 1) {
params[2 * quantity] = t[i];
params[2 * quantity + 1] = s[i];
++quantity;
}
}
return quantity;
}
示例3: solveCubic
import org.apache.harmony.awt.gl.Crossing; //导入方法依赖的package包/类
public static int solveCubic(double eqn[], double res[]) {
return Crossing.solveCubic(eqn, res);
}
示例4: solveCubic
import org.apache.harmony.awt.gl.Crossing; //导入方法依赖的package包/类
public static int solveCubic(double eqn[], double res[]) {
return Crossing.solveCubic(eqn, res);
}
示例5: solveCubic
import org.apache.harmony.awt.gl.Crossing; //导入方法依赖的package包/类
/**
* Finds the roots of the cubic polynomial. This is accomplished by finding
* the (real) values of x that solve the following equation: eqn[3]*x*x*x +
* eqn[2]*x*x + eqn[1]*x + eqn[0] = 0. The solutions are written into the
* array res starting from the index 0 in the array. The return value tells
* how many array elements have been changed by this method call.
*
* @param eqn
* an array containing the coefficients of the cubic polynomial
* to solve.
* @param res
* the array that this method writes the results into.
* @return the number of roots of the cubic polynomial.
* @throws ArrayIndexOutOfBoundsException
* if eqn.length < 4 or if res.length is less than the number of
* roots.
* @throws NullPointerException
* if either array is null.
*/
public static int solveCubic(double eqn[], double res[]) {
return Crossing.solveCubic(eqn, res);
}