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

📄 line2d.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    }    /**     * Returns the square of the distance from a <code>Point2D</code> to      * this line segment.     * The distance measured is the distance between the specified     * point and the closest point between the current line's endpoints.       * If the specified point intersects the line segment in between the     * endpoints, this method returns 0.0.     * @param pt the specified <code>Point2D</code> being measured against     *	         this line segment.     * @return a double value that is the square of the distance from the     *			specified <code>Point2D</code> to the current      *			line segment.     * @see #ptLineDistSq(Point2D)     */    public double ptSegDistSq(Point2D pt) {	return ptSegDistSq(getX1(), getY1(), getX2(), getY2(),			   pt.getX(), pt.getY());    }    /**     * Returns the distance from a point to this line segment.     * The distance measured is the distance between the specified     * point and the closest point between the current line's endpoints.       * If the specified point intersects the line segment in between the     * endpoints, this method returns 0.0.     * @param PX,&nbsp;PY the coordinates of the specified point     *			  being measured against this line segment     * @return a double value that is the distance from the specified      *			point to the current line segment.     * @see #ptLineDist(double, double)     */    public double ptSegDist(double PX, double PY) {	return ptSegDist(getX1(), getY1(), getX2(), getY2(), PX, PY);    }    /**     * Returns the distance from a <code>Point2D</code> to this line     * segment.     * The distance measured is the distance between the specified     * point and the closest point between the current line's endpoints.       * If the specified point intersects the line segment in between the     * endpoints, this method returns 0.0.     * @param pt the specified <code>Point2D</code> being measured     *		against this line segment     * @return a double value that is the distance from the specified     *				<code>Point2D</code> to the current line     *				segment.     * @see #ptLineDist(Point2D)     */    public double ptSegDist(Point2D pt) {	return ptSegDist(getX1(), getY1(), getX2(), getY2(),			 pt.getX(), pt.getY());    }    /**     * Returns the square of the distance from a point to a line.     * The distance measured is the distance between the specified     * point and the closest point on the infinitely-extended line     * defined by the specified coordinates.  If the specified point      * intersects the line, this method returns 0.0.     * @param X1,&nbsp;Y1 the coordinates of one point on the     * 		specified line     * @param X2,&nbsp;Y2 the coordinates of another point on      *		the specified line     * @param PX,&nbsp;PY the coordinates of the specified point being     * 		measured against the specified line     * @return a double value that is the square of the distance from the     *			specified point to the specified line.     * @see #ptSegDistSq(double, double, double, double, double, double)     */    public static double ptLineDistSq(double X1, double Y1,				      double X2, double Y2,				      double PX, double PY) {	// Adjust vectors relative to X1,Y1	// X2,Y2 becomes relative vector from X1,Y1 to end of segment	X2 -= X1;	Y2 -= Y1;	// PX,PY becomes relative vector from X1,Y1 to test point	PX -= X1;	PY -= Y1;	double dotprod = PX * X2 + PY * Y2;	// dotprod is the length of the PX,PY vector	// projected on the X1,Y1=>X2,Y2 vector times the	// length of the X1,Y1=>X2,Y2 vector	double projlenSq = dotprod * dotprod / (X2 * X2 + Y2 * Y2);	// Distance to line is now the length of the relative point	// vector minus the length of its projection onto the line	double lenSq = PX * PX + PY * PY - projlenSq;	if (lenSq < 0) {	    lenSq = 0;	}	return lenSq;    }    /**     * Returns the distance from a point to a line.     * The distance measured is the distance between the specified     * point and the closest point on the infinitely-extended line     * defined by the specified coordinates.  If the specified point      * intersects the line, this method returns 0.0.     * @param X1,&nbsp;Y1 the coordinates of one point on the     *		specified line     * @param X2,&nbsp;Y2 the coordinates of another point on the     *		specified line     * @param PX,&nbsp;PY the coordinates of the specified point being     *		measured against the specified line     * @return a double value that is the distance from the specified     *			 point to the specified line.     * @see #ptSegDist(double, double, double, double, double, double)     */    public static double ptLineDist(double X1, double Y1,				    double X2, double Y2,				    double PX, double PY) {	return Math.sqrt(ptLineDistSq(X1, Y1, X2, Y2, PX, PY));    }    /**     * Returns the square of the distance from a point to this line.     * The distance measured is the distance between the specified     * point and the closest point on the infinitely-extended line     * defined by this <code>Line2D</code>.  If the specified point      * intersects the line, this method returns 0.0.     * @param PX,&nbsp;PY the coordinates of the specified point being     *		measured against this line     * @return a double value that is the square of the distance from a      *			specified point to the current line.     * @see #ptSegDistSq(double, double)     */    public double ptLineDistSq(double PX, double PY) {	return ptLineDistSq(getX1(), getY1(), getX2(), getY2(), PX, PY);    }    /**     * Returns the square of the distance from a specified      * <code>Point2D</code> to this line.     * The distance measured is the distance between the specified     * point and the closest point on the infinitely-extended line     * defined by this <code>Line2D</code>.  If the specified point      * intersects the line, this method returns 0.0.     * @param pt the specified <code>Point2D</code> being measured     *           against this line     * @return a double value that is the square of the distance from a     *			specified <code>Point2D</code> to the current     *			line.     * @see #ptSegDistSq(Point2D)     */    public double ptLineDistSq(Point2D pt) {	return ptLineDistSq(getX1(), getY1(), getX2(), getY2(),			    pt.getX(), pt.getY());    }    /**     * Returns the distance from a point to this line.     * The distance measured is the distance between the specified     * point and the closest point on the infinitely-extended line     * defined by this <code>Line2D</code>.  If the specified point      * intersects the line, this method returns 0.0.     * @param PX,&nbsp;PY the coordinates of the specified point being     *		measured against this line     * @return a double value that is the distance from a specified point     *			to the current line.     * @see #ptSegDist(double, double)     */    public double ptLineDist(double PX, double PY) {	return ptLineDist(getX1(), getY1(), getX2(), getY2(), PX, PY);    }    /**     * Returns the distance from a <code>Point2D</code> to this line.     * The distance measured is the distance between the specified     * point and the closest point on the infinitely-extended line     * defined by this <code>Line2D</code>.  If the specified point      * intersects the line, this method returns 0.0.     * @param pt the specified <code>Point2D</code> being measured     * @return a double value that is the distance from a specified      *			<code>Point2D</code> to the current line.     * @see #ptSegDist(Point2D)     */    public double ptLineDist(Point2D pt) {	return ptLineDist(getX1(), getY1(), getX2(), getY2(),			 pt.getX(), pt.getY());    }    /**     * Tests if a specified coordinate is inside the boundary of this     * <code>Line2D</code>.  This method is required to implement the      * {@link Shape} interface, but in the case of <code>Line2D</code>      * objects it always returns <code>false</code> since a line contains     * no area.     * @param x,&nbsp;y the coordinates of the specified point     * @return <code>false</code> because a <code>Line2D</code> contains     * no area.     */    public boolean contains(double x, double y) {	return false;    }    /**     * Tests if a given <code>Point2D</code> is inside the boundary of     * this <code>Line2D</code>.     * This method is required to implement the <code>Shape</code> interface,      * but in the case of <code>Line2D</code> objects it always returns      * <code>false</code> since a line contains no area.     * @param p the specified <code>Point2D</code> to be tested     * @return <code>false</code> because a <code>Line2D</code> contains     * no area.     */    public boolean contains(Point2D p) {	return false;    }    /**     * Tests if this <code>Line2D</code> intersects the interior of a     * specified set of rectangular coordinates.     * @param x,&nbsp;y the coordinates of the top-left corner of the     *		specified rectangular area     * @param w the width of the specified rectangular area     * @param h the height of the specified rectangular area     * @return <code>true</code> if this <code>Line2D</code> intersects      *		the interior of the specified set of rectangular     *		coordinates; <code>false</code> otherwise.	     */    public boolean intersects(double x, double y, double w, double h) {	return intersects(new Rectangle2D.Double(x, y, w, h));    }    /**     * Tests if this <code>Line2D</code> intersects the interior of a     * specified <code>Rectangle2D</code>.     * @param r the specified <code>Rectangle2D</code> to be tested     * @return <code>true</code> if this <code>Line2D</code> intersects     *		the interior of the specified <code>Rectangle2D</code>;     *		<code>false</code> otherwise.     */    public boolean intersects(Rectangle2D r) {	return r.intersectsLine(getX1(), getY1(), getX2(), getY2());    }    /**     * Tests if the interior of this <code>Line2D</code> entirely contains     * the specified set of rectangular coordinates.     * This method is required to implement the <code>Shape</code> interface,      * but in the case of <code>Line2D</code> objects it always returns      * false since a line contains no area.     * @param x,&nbsp;y the coordinates of the top-left corner of the     *		specified rectangular area     * @param w the width of the specified rectangular area     * @param h the height of the specified rectangular area     * @return <code>false</code> because a <code>Line2D</code> contains     * no area.     */    public boolean contains(double x, double y, double w, double h) {	return false;    }    /**     * Tests if the interior of this <code>Line2D</code> entirely contains     * the specified <code>Rectangle2D</code>.     * This method is required to implement the <code>Shape</code> interface,      * but in the case of <code>Line2D</code> objects it always returns      * <code>false</code> since a line contains no area.     * @param r the specified <code>Rectangle2D</code> to be tested     * @return <code>false</code> because a <code>Line2D</code> contains     * no area.     */    public boolean contains(Rectangle2D r) {	return false;    }    /**     * Returns the bounding box of this <code>Line2D</code>.     * @return a {@link Rectangle} that is the bounding box of the     *		<code>Line2D</code>.     */    public Rectangle getBounds() {	return getBounds2D().getBounds();    }    /**     * Returns an iteration object that defines the boundary of this     * <code>Line2D</code>.     * The iterator for this class is not multi-threaded safe,      * which means that this <code>Line2D</code> class does not      * guarantee that modifications to the geometry of this     * <code>Line2D</code> object do not affect any iterations of that     * geometry that are already in process.     * @param at the specified {@link AffineTransform}     * @return a {@link PathIterator} that defines the boundary of this     *		<code>Line2D</code>.     */    public PathIterator getPathIterator(AffineTransform at) {	return new LineIterator(this, at);    }    /**     * Returns an iteration object that defines the boundary of this     * flattened <code>Line2D</code>.     * The iterator for this class is not multi-threaded safe,     * which means that this <code>Line2D</code> class does not     * guarantee that modifications to the geometry of this     * <code>Line2D</code> object do not affect any iterations of that     * geometry that are already in process.      * @param at the specified <code>AffineTransform</code>     * @param flatness the maximum amount that the control points for a      *		given curve can vary from colinear before a subdivided     *		curve is replaced by a straight line connecting the     *		endpoints.  Since a <code>Line2D</code> object is      *	        always flat, this parameter is ignored.     * @return a <code>PathIterator</code> that defines the boundary of the     *			flattened <code>Line2D</code>     */    public PathIterator getPathIterator(AffineTransform at, double flatness) {	return new LineIterator(this, at);    }    /**     * Creates a new object of the same class as this object.     *     * @return     a clone of this instance.     * @exception  OutOfMemoryError            if there is not enough memory.     * @see        java.lang.Cloneable     * @since      1.2     */    public Object clone() {	try {	    return super.clone();	} catch (CloneNotSupportedException e) {	    // this shouldn't happen, since we are Cloneable	    throw new InternalError();	}    }}

⌨️ 快捷键说明

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