当前位置: 首页>>代码示例>>Java>>正文


Java Crossing.solveCubic方法代码示例

本文整理汇总了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;
}
 
开发者ID:windwardadmin,项目名称:android-awt,代码行数:47,代码来源:GeometryUtil.java

示例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;
}
 
开发者ID:bullda,项目名称:DroidText,代码行数:46,代码来源:GeometryUtil.java

示例3: solveCubic

import org.apache.harmony.awt.gl.Crossing; //导入方法依赖的package包/类
public static int solveCubic(double eqn[], double res[]) {
    return Crossing.solveCubic(eqn, res);
}
 
开发者ID:windwardadmin,项目名称:android-awt,代码行数:4,代码来源:CubicCurve2D.java

示例4: solveCubic

import org.apache.harmony.awt.gl.Crossing; //导入方法依赖的package包/类
public static int solveCubic(double eqn[], double res[]) {
	return Crossing.solveCubic(eqn, res);
}
 
开发者ID:bullda,项目名称:DroidText,代码行数:4,代码来源:CubicCurve2D.java

示例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);
}
 
开发者ID:dritanlatifi,项目名称:AndroidPrefuse,代码行数:23,代码来源:CubicCurve2D.java


注:本文中的org.apache.harmony.awt.gl.Crossing.solveCubic方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。