⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cubiccurve2d.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	}	/**	 * Returns the Y coordinate of the first control point 	 * in double precision.	 * @return the Y coordinate of the first control point of the	 *		<code>CubicCurve2D</code>.	 */	public double getCtrlY1() {	    return ctrly1;	}	/**	 * Returns the first control point.	 * @return a <code>Point2D</code> that is the first control point of the	 *		<code>CubicCurve2D</code>.	 */	public Point2D getCtrlP1() {	    return new Point2D.Double(ctrlx1, ctrly1);	}	/**	 * Returns the X coordinate of the second control point	 * in double precision.	 * @return the X coordinate of the second control point of the	 *		<code>CubicCurve2D</code>.	 */	public double getCtrlX2() {	    return ctrlx2;	}	/**	 * Returns the Y coordinate of the second control point	 * in double precision.	 * @return the Y coordinate of the second control point of the	 *		<code>CubicCurve2D</code>.	 */	public double getCtrlY2() {	    return ctrly2;	}	/**	 * Returns the second control point.	 * @return a <code>Point2D</code> that is the second control point of 	 *		the <code>CubicCurve2D</code>.		 */	public Point2D getCtrlP2() {	    return new Point2D.Double(ctrlx2, ctrly2);	}	/**	 * Returns the X coordinate of the end point	 * in double precision.	 * @return the X coordinate of the end point of the	 *		<code>CubicCurve2D</code>.	 */	public double getX2() {	    return x2;	}	/**	 * Returns the Y coordinate of the end point 	 * in double precision.	 * @return the Y coordinate of the end point of the	 *		<code>CubicCurve2D</code>.	 */	public double getY2() {	    return y2;	}	/**	 * Returns the end point.	 * @return a <code>Point2D</code> that is the end point of 	 *		the <code>CubicCurve2D</code>.		 */	public Point2D getP2() {	    return new Point2D.Double(x2, y2);	}	/**	 * Sets the location of the endpoints and controlpoints	 * of this curve to the specified double coordinates.	 * @param x1,&nbsp;y1 the first specified coordinates used to set the start	 *		point of this <code>CubicCurve2D</code>	 * @param ctrlx1,&nbsp;ctrly1 the second specified coordinates used to set the	 *		first control point of this <code>CubicCurve2D</code>	 * @param ctrlx2,&nbsp;ctrly2 the third specified coordinates used to set the 	 *		second control point of this <code>CubicCurve2D</code>			 * @param x2,&nbsp;y2 the fourth specified coordinates used to set the end	 *		point of this <code>CubicCurve2D</code>	 	 */	public void setCurve(double x1, double y1,			     double ctrlx1, double ctrly1,			     double ctrlx2, double ctrly2,			     double x2, double y2) {	    this.x1     = x1;	    this.y1     = y1;	    this.ctrlx1 = ctrlx1;	    this.ctrly1 = ctrly1;	    this.ctrlx2 = ctrlx2;	    this.ctrly2 = ctrly2;	    this.x2     = x2;	    this.y2     = y2;	}	/**	 * Returns the bounding box of the shape.	 * @return a <code>Rectangle2D</code> that is the bounding box	 *		of the shape.	 */	public Rectangle2D getBounds2D() {	    double left   = Math.min(Math.min(x1, x2),				     Math.min(ctrlx1, ctrlx2));	    double top    = Math.min(Math.min(y1, y2),				     Math.min(ctrly1, ctrly2));	    double right  = Math.max(Math.max(x1, x2),				     Math.max(ctrlx1, ctrlx2));	    double bottom = Math.max(Math.max(y1, y2),				     Math.max(ctrly1, ctrly2));	    return new Rectangle2D.Double(left, top,					  right - left, bottom - top);	}    }    /**     * This is an abstract class that cannot be instantiated directly.     * Type-specific implementation subclasses are available for     * instantiation and provide a number of formats for storing     * the information necessary to satisfy the various accessor     * methods below.     *     * @see java.awt.geom.CubicCurve2D.Float     * @see java.awt.geom.CubicCurve2D.Double     */    protected CubicCurve2D() {    }    /**     * Returns the X coordinate of the start point in double precision.     * @return the X coordinate of the start point of the     *		<code>CubicCurve2D</code>.     */    public abstract double getX1();    /**     * Returns the Y coordinate of the start point in double precision.     * @return the Y coordinate of the start point of the     *		<code>CubicCurve2D</code>.     */    public abstract double getY1();    /**     * Returns the start point.     * @return a <code>Point2D</code> that is the start point of      *		the <code>CubicCurve2D</code>.     */    public abstract Point2D getP1();    /**     * Returns the X coordinate of the first control point in double precision.     * @return the X coordinate of the first control point of the     *		<code>CubicCurve2D</code>.     */    public abstract double getCtrlX1();    /**     * Returns the Y coordinate of the first control point in double precision.     * @return the Y coordinate of the first control point of the     *		<code>CubicCurve2D</code>.     */    public abstract double getCtrlY1();    /**     * Returns the first control point.     * @return a <code>Point2D</code> that is the first control point of      *		the <code>CubicCurve2D</code>.     */    public abstract Point2D getCtrlP1();    /**     * Returns the X coordinate of the second control point     * in double precision.     * @return the X coordinate of the second control point of the     *		<code>CubicCurve2D</code>.     */    public abstract double getCtrlX2();    /**     * Returns the Y coordinate of the second control point     * in double precision.     * @return the Y coordinate of the second control point of the     *		<code>CubicCurve2D</code>.     */    public abstract double getCtrlY2();    /**     * Returns the second control point.     * @return a <code>Point2D</code> that is the second control point of      *		the <code>CubicCurve2D</code>.     */    public abstract Point2D getCtrlP2();    /**     * Returns the X coordinate of the end point in double precision.     * @return the X coordinate of the end point of the     *		<code>CubicCurve2D</code>.     */    public abstract double getX2();    /**     * Returns the Y coordinate of the end point in double precision.     * @return the Y coordinate of the end point of the     *		<code>CubicCurve2D</code>.     */    public abstract double getY2();    /**     * Returns the end point.     * @return a <code>Point2D</code> that is the end point of      *		the <code>CubicCurve2D</code>.     */    public abstract Point2D getP2();    /**     * Sets the location of the endpoints and controlpoints of this curve     * to the specified double coordinates.     * @param x1,&nbsp;y1 the first specified coordinates used to set the start     *		point of this <code>CubicCurve2D</code>     * @param ctrlx1,&nbsp;ctrly1 the second specified coordinates used to set the     *		first control point of this <code>CubicCurve2D</code>     * @param ctrlx2,&nbsp;ctrly2 the third specified coordinates used to set the      *		second control point of this <code>CubicCurve2D</code>		     * @param x2,&nbsp;y2 the fourth specified coordinates used to set the end     *		point of this <code>CubicCurve2D</code>	      */    public abstract void setCurve(double x1, double y1,				  double ctrlx1, double ctrly1,				  double ctrlx2, double ctrly2,				  double x2, double y2);    /**     * Sets the location of the endpoints and controlpoints of this curve     * to the double coordinates at the specified offset in the specified     * array.     * @param coords a double array containing coordinates     * @param offset the index of <code>coords</code> at which to begin      *		setting the endpoints and controlpoints of this curve     *		to the coordinates contained in <code>coords</code>	     */    public void setCurve(double[] coords, int offset) {	setCurve(coords[offset + 0], coords[offset + 1],		 coords[offset + 2], coords[offset + 3],		 coords[offset + 4], coords[offset + 5],		 coords[offset + 6], coords[offset + 7]);    }    /**     * Sets the location of the endpoints and controlpoints of this curve     * to the specified <code>Point2D</code> coordinates.     * @param p1 the first specified <code>Point2D</code> used to set the     *		start point of this curve     * @param cp1 the second specified <code>Point2D</code> used to set the     *		first control point of this curve     * @param cp2 the third specified <code>Point2D</code> used to set the     *		second control point of this curve     * @param p2 the fourth specified <code>Point2D</code> used to set the     *		end point of this curve     */    public void setCurve(Point2D p1, Point2D cp1, Point2D cp2, Point2D p2) {	setCurve(p1.getX(), p1.getY(), cp1.getX(), cp1.getY(),		 cp2.getX(), cp2.getY(), p2.getX(), p2.getY());    }    /**     * Sets the location of the endpoints and controlpoints of this curve     * to the coordinates of the <code>Point2D</code> objects at the specified      * offset in the specified array.     * @param pts an array of <code>Point2D</code> objects     * @param offset  the index of <code>pts</code> at which to begin setting     *		the endpoints and controlpoints of this curve to the      *		points contained in <code>pts</code>     */    public void setCurve(Point2D[] pts, int offset) {	setCurve(pts[offset + 0].getX(), pts[offset + 0].getY(),		 pts[offset + 1].getX(), pts[offset + 1].getY(),		 pts[offset + 2].getX(), pts[offset + 2].getY(),		 pts[offset + 3].getX(), pts[offset + 3].getY());    }    /**     * Sets the location of the endpoints and controlpoints of this curve     * to the same as those in the specified <code>CubicCurve2D</code>.     * @param c the specified <code>CubicCurve2D</code>     */    public void setCurve(CubicCurve2D c) {	setCurve(c.getX1(), c.getY1(), c.getCtrlX1(), c.getCtrlY1(),		 c.getCtrlX2(), c.getCtrlY2(), c.getX2(), c.getY2());    }    /**     * Returns the square of the flatness of the cubic curve specified     * by the indicated controlpoints. The flatness is the maximum distance      * of a controlpoint from the line connecting the endpoints.     * @param x1,&nbsp;y1 the first specified coordinates that specify the start     *		point of a <code>CubicCurve2D</code>     * @param ctrlx1,&nbsp;ctrly1 the second specified coordinates that specify the      * 		first control point of a <code>CubicCurve2D</code>     * @param ctrlx2,&nbsp;ctrly2 the third specified coordinates that specify the      * 		second control point of a <code>CubicCurve2D</code>	     * @param x2,&nbsp;y2 the fourth specified coordinates that specify the      * 		end point of a <code>CubicCurve2D</code>     * @return the square of the flatness of the <code>CubicCurve2D</code>     *		represented by the specified coordinates.     */    public static double getFlatnessSq(double x1, double y1,				       double ctrlx1, double ctrly1,				       double ctrlx2, double ctrly2,				       double x2, double y2) {	return Math.max(Line2D.ptSegDistSq(x1, y1, x2, y2, ctrlx1, ctrly1),			Line2D.ptSegDistSq(x1, y1, x2, y2, ctrlx2, ctrly2));			    }    /**     * Returns the flatness of the cubic curve specified     * by the indicated controlpoints. The flatness is the maximum distance      * of a controlpoint from the line connecting the endpoints.     * @param x1,&nbsp;y1 the first specified coordinates that specify the start     *		point of a <code>CubicCurve2D</code>     * @param ctrlx1,&nbsp;ctrly1 the second specified coordinates that specify the      * 		first control point of a <code>CubicCurve2D</code>     * @param ctrlx2,&nbsp;ctrly2 the third specified coordinates that specify the      * 		second control point of a <code>CubicCurve2D</code>	     * @param x2,&nbsp;y2 the fourth specified coordinates that specify the      * 		end point of a <code>CubicCurve2D</code>     * @return the flatness of the <code>CubicCurve2D</code>     *		represented by the specified coordinates.     */    public static double getFlatness(double x1, double y1,				     double ctrlx1, double ctrly1,				     double ctrlx2, double ctrly2,				     double x2, double y2) {	return Math.sqrt(getFlatnessSq(x1, y1, ctrlx1, ctrly1,				       ctrlx2, ctrly2, x2, y2));    }    /**     * Returns the square of the flatness of the cubic curve specified     * by the controlpoints stored in the indicated array at the      * indicated index. The flatness is the maximum distance      * of a controlpoint from the line connecting the endpoints.     * @param coords an array containing coordinates     * @param offset the index of <code>coords</code> at which to begin      *		setting the endpoints and controlpoints of this curve     *		to the coordinates contained in <code>coords</code>     * @return the square of the flatness of the <code>CubicCurve2D</code>     *		specified by the coordinates in <code>coords</code> at     *		the specified offset.     */    public static double getFlatnessSq(double coords[], int offset) {	return getFlatnessSq(coords[offset + 0], coords[offset + 1],			     coords[offset + 2], coords[offset + 3],			     coords[offset + 4], coords[offset + 5],			     coords[offset + 6], coords[offset + 7]);    }    /**     * Returns the flatness of the cubic curve specified     * by the controlpoints stored in the indicated array at the      * indicated index.  The flatness is the maximum distance      * of a controlpoint from the line connecting the endpoints.     * @param coords an array containing coordinates     * @param offset the index of <code>coords</code> at which to begin      *		setting the endpoints and controlpoints of this curve     *		to the coordinates contained in <code>coords</code>     * @return the flatness of the <code>CubicCurve2D</code>     *		specified by the coordinates in <code>coords</code> at     *		the specified offset.     */    public static double getFlatness(double coords[], int offset) {	return getFlatness(coords[offset + 0], coords[offset + 1],			   coords[offset + 2], coords[offset + 3],			   coords[offset + 4], coords[offset + 5],			   coords[offset + 6], coords[offset + 7]);    }    /**     * Returns the square of the flatness of this curve.  The flatness is the      * maximum distance of a controlpoint from the line connecting the      * endpoints.     * @return the square of the flatness of this curve.     */    public double getFlatnessSq() {	return getFlatnessSq(getX1(), getY1(), getCtrlX1(), getCtrlY1(),			     getCtrlX2(), getCtrlY2(), getX2(), getY2());    }    /**     * Returns the flatness of this curve.  The flatness is the      * maximum distance of a controlpoint from the line connecting the      * endpoints.     * @return the flatness of this curve.     */    public double getFlatness() {	return getFlatness(getX1(), getY1(), getCtrlX1(), getCtrlY1(),			   getCtrlX2(), getCtrlY2(), getX2(), getY2());    }    /**     * Subdivides this cubic curve and stores the resulting two     * subdivided curves into the left and right curve parameters.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -