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


Java Point2D.getX方法代码示例

本文整理汇总了Java中math.geom2d.Point2D.getX方法的典型用法代码示例。如果您正苦于以下问题:Java Point2D.getX方法的具体用法?Java Point2D.getX怎么用?Java Point2D.getX使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在math.geom2d.Point2D的用法示例。


在下文中一共展示了Point2D.getX方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getBoundingBox

import math.geom2d.Point2D; //导入方法依赖的package包/类
public Box2D getBoundingBox() {
    double xmin = Double.MAX_VALUE;
    double ymin = Double.MAX_VALUE;
    double xmax = Double.MIN_VALUE;
    double ymax = Double.MIN_VALUE;

    Iterator<Point2D> iter = points.iterator();
    Point2D point;
    double x, y;
    while (iter.hasNext()) {
        point = iter.next();
        x = point.getX();
        y = point.getY();
        xmin = Math.min(xmin, x);
        xmax = Math.max(xmax, x);
        ymin = Math.min(ymin, y);
        ymax = Math.max(ymax, y);
    }

    return new Box2D(xmin, xmax, ymin, ymax);
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:22,代码来源:Polyline2D.java

示例2: create

import math.geom2d.Point2D; //导入方法依赖的package包/类
/**
 * Create a new Ellipse by specifying the two focii, and the length of the
 * chord. The chord equals the sum of distances between a point of the
 * ellipse and each focus.
 * 
 * @param focus1 the first focus
 * @param focus2 the second focus
 * @param chord the sum of distances to focii
 * @return a new instance of Ellipse2D
 */
public static Ellipse2D create(Point2D focus1, Point2D focus2, 
		double chord) {
    double x1 = focus1.getX();
    double y1 = focus1.getY();
    double x2 = focus2.getX();
    double y2 = focus2.getY();

    double xc = (x1+x2)/2;
    double yc = (y1+y2)/2;
    double theta = Angle2D.getHorizontalAngle(x1, y1, x2, y2);

    double dist = focus1.getDistance(focus2);
    if (dist<Shape2D.ACCURACY)
        return new Circle2D(xc, yc, chord/2);

    double r1 = chord/2;
    double r2 = Math.sqrt(chord*chord-dist*dist)/2;

    return new Ellipse2D(xc, yc, r1, r2, theta);
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:31,代码来源:Ellipse2D.java

示例3: getIntersectionParametric

import math.geom2d.Point2D; //导入方法依赖的package包/类
/** Get parametric representation of intersection with another linear shape
 * 
 * @param other the other linear shape
 * @return parametric representation of the intersection or NaN if doesn't exist (parallel lines, etc)
 */
public double getIntersectionParametric(LinearShape2D line) {
    Vector2D vect = line.getVector();
    double dx2 = vect.getX();
    double dy2 = vect.getY();

    // test if two lines are parallel
    if (Math.abs(dx*dy2-dy*dx2)<Shape2D.ACCURACY)
        return Double.NaN;

    // compute position on the line
    Point2D origin = line.getOrigin();
    double x2 = origin.getX();
    double y2 = origin.getY();
    double t = ((y0-y2)*dx2-(x0-x2)*dy2)/(dx*dy2-dy*dx2);
    
	if ( !containsParametric( t ) ) {
		return Double.NaN;
	}
	
	if ( !line.contains( getPoint(t) ) ) {
		return Double.NaN;
	}
	
	return t;
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:31,代码来源:AbstractLine2D.java

示例4: transform

import math.geom2d.Point2D; //导入方法依赖的package包/类
/**
 * Transforms this Hyperbola by an affine transform.
 */
@Override
public Hyperbola2D transform(AffineTransform2D trans) {
    Hyperbola2D result = Hyperbola2D.transformCentered(this, trans);
    Point2D center = this.getCenter().transform(trans);
    result.xc = center.getX();
    result.yc = center.getY();
    //TODO: check convention for transform with indirect transform, see Curve2D.
    result.direct = this.direct^!trans.isDirect();
    return result;
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:14,代码来源:Hyperbola2D.java

示例5: getBoundingBox

import math.geom2d.Point2D; //导入方法依赖的package包/类
public Box2D getBoundingBox() {

        // first get ending points
        Point2D p0 = getFirstPoint();
        Point2D p1 = getLastPoint();

        // get coordinate of ending points
        double x0 = p0.getX();
        double y0 = p0.getY();
        double x1 = p1.getX();
        double y1 = p1.getY();

        // intialize min and max coords
        double xmin = Math.min(x0, x1);
        double xmax = Math.max(x0, x1);
        double ymin = Math.min(y0, y1);
        double ymax = Math.max(y0, y1);

        // check cases arc contains one maximum
        Point2D center = ellipse.getCenter();
        double xc = center.getX();
        double yc = center.getY();
        if (Angle2D.containsAngle(startAngle, startAngle+angleExtent, Math.PI/2
                +ellipse.theta, angleExtent>=0))
            ymax = Math.max(ymax, yc+ellipse.r1);
        if (Angle2D.containsAngle(startAngle, startAngle+angleExtent, 3*Math.PI
                /2+ellipse.theta, angleExtent>=0))
            ymin = Math.min(ymin, yc-ellipse.r1);
        if (Angle2D.containsAngle(startAngle, startAngle+angleExtent,
                ellipse.theta, angleExtent>=0))
            xmax = Math.max(xmax, xc+ellipse.r2);
        if (Angle2D.containsAngle(startAngle, startAngle+angleExtent, Math.PI
                +ellipse.theta, angleExtent>=0))
            xmin = Math.min(xmin, xc-ellipse.r2);

        // return a bounding with computed limits
        return new Box2D(xmin, xmax, ymin, ymax);
    }
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:39,代码来源:EllipseArc2D.java

示例6: rangeSearch

import math.geom2d.Point2D; //导入方法依赖的package包/类
/**
 * range search, by recursively adding points to the collection.
 */
private void rangeSearch(Box2D range, 
        Collection<Point2D> points, Node node, int depth) {
    if(node==null)
        return;
    
    // extract the point
    Point2D point = node.getPoint();
    double x = point.getX();
    double y = point.getY();
    
    // check if point is in range
    boolean tx1 = range.getMinX()<x;
    boolean ty1 = range.getMinY()<y;
    boolean tx2 = x<=range.getMaxX();
    boolean ty2 = y<=range.getMaxY();
    
    // adds the point if it is present
    if(tx1 && tx2 && ty1 && ty2)
        points.add(point);
    
    // select direction
    int dir = depth%2;
    
    if(dir==0 ? tx1 : ty1)
        rangeSearch(range, points, node.left, depth+1);
    if(dir==0 ? tx2 : ty2)
        rangeSearch(range, points, node.right, depth+1);
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:32,代码来源:KDTree2D.java

示例7: isInside

import math.geom2d.Point2D; //导入方法依赖的package包/类
/**
 * Test whether the point is inside the ellipse. The test is performed by
 * rotating the ellipse and the point to align with axis, rescaling in each
 * direction, then computing distance to origin.
 */
public boolean isInside(java.awt.geom.Point2D point) {
    AffineTransform2D rot = AffineTransform2D.createRotation(this.xc,
            this.yc, -this.theta);
    Point2D pt = rot.transform(point);
    double xp = (pt.getX()-this.xc)/this.r1;
    double yp = (pt.getY()-this.yc)/this.r2;
    return (xp*xp+yp*yp<1)^!direct;
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:14,代码来源:Ellipse2D.java

示例8: transform

import math.geom2d.Point2D; //导入方法依赖的package包/类
/**
 * Returns an instance of EllipseArc2D, or CircleArc2D if transform is a
 * similarity.
 */
@Override
public EllipseArc2D transform(AffineTransform2D trans) {
    if (!AffineTransform2D.isSimilarity(trans))
        return super.transform(trans);

    // System.out.println("transform a circle");

    // extract the control points
    Point2D center = circle.getCenter();
    Point2D point1 = this.getFirstPoint();
    Point2D point2 = this.getLastPoint();

    // transform each point
    center = center.transform(trans);
    point1 = point1.transform(trans);
    point2 = point2.transform(trans);

    // compute new angles
    double angle1 = Angle2D.getHorizontalAngle(center, point1);
    double angle2 = Angle2D.getHorizontalAngle(center, point2);

    // compute factor of transform
    double[] coefs = trans.getCoefficients();
    double factor = Math.sqrt(coefs[0]*coefs[0]+coefs[3]*coefs[3]);

    // compute parameters of new circle arc
    double xc = center.getX(), yc = center.getY();
    double r2 = circle.getRadius()*factor;
    double startAngle = angle1;
    double angleExtent = Angle2D.formatAngle(angle2-angle1);

    boolean b1 = AffineTransform2D.isDirect(trans);
    boolean b2 = this.isDirect();
    if (b1&!b2|!b1&b2)
        angleExtent = angleExtent-2*Math.PI;

    // return new CircleArc
    return new CircleArc2D(xc, yc, r2, startAngle, angleExtent);
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:44,代码来源:CircleArc2D.java

示例9: contains

import math.geom2d.Point2D; //导入方法依赖的package包/类
@Override
public boolean contains(double x, double y) {
    Point2D point = toLocal(new Point2D(x, y));
    double xa = point.getX()/a;
    double yb = point.getY()/b;
    double res = xa*xa-yb*yb-1;
    // double res = x*x*b*b - y*y*a*a - a*a*b*b;
    return Math.abs(res)<1e-6;
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:10,代码来源:Hyperbola2D.java

示例10: setRay

import math.geom2d.Point2D; //导入方法依赖的package包/类
/**
 * @deprecated lines will become immutable in a future release
 */
@Deprecated
public void setRay(Point2D p1, Point2D p2) {
    this.x0 = p1.getX();
    this.y0 = p1.getY();
    this.dx = p2.getX()-this.x0;
    this.dy = p2.getY()-this.y0;
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:11,代码来源:Ray2D.java

示例11: getPoint

import math.geom2d.Point2D; //导入方法依赖的package包/类
public math.geom2d.Point2D getPoint(double t) {
    // format position to stay between limits
    double t0 = this.getT0();
    double t1 = this.getT1();
    t = Math.max(Math.min(t, t1), t0);

    // index of vertex before point
    int ind0 = (int) Math.floor(t+Shape2D.ACCURACY);
    double tl = t-ind0;
    Point2D p0 = points.get(ind0);

    // check if equal to a vertex
    if (Math.abs(t-ind0)<Shape2D.ACCURACY)
        return new Point2D(p0);

    // index of vertex after point
    int ind1 = ind0+1;
    Point2D p1 = points.get(ind1);

    // position on line;

    double x0 = p0.getX();
    double y0 = p0.getY();
    double dx = p1.getX()-x0;
    double dy = p1.getY()-y0;

    return new Point2D(x0+tl*dx, y0+tl*dy);
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:29,代码来源:Polyline2D.java

示例12: windingNumber

import math.geom2d.Point2D; //导入方法依赖的package包/类
/**
 * Computes the winding number of the polygon. Algorithm adapted from
 * http://www.geometryalgorithms.com/Archive/algorithm_0103/algorithm_0103.htm
 * 
 * @param vertices the vertices of the polygon
 * @param point the reference point
 * @return the number of windings of the curve around the point
 */
public final static int windingNumber(Collection<Point2D> vertices,
        java.awt.geom.Point2D point) {
    int wn = 0; // the winding number counter

    // Extract the last point of the collection
    Point2D previous = null;
    for (Point2D vertex : vertices)
        previous = vertex;
    double x1 = previous.getX();
    double y1 = previous.getY();
    double x2, y2;

    // Iterate on couple of vertices, starting from couple (last,first)
    double y = point.getY();
    for (Point2D p : vertices) {
        // second vertex of current edge
        x2 = p.getX();
        y2 = p.getY();

        // TODO: should avoid create new objects, and use a dedicated method
        if (y1<=y) {
            if (y2>y) // an upward crossing
                if (new LineSegment2D(x1, y1, x2, y2).isInside(point))
                    wn++;
        } else {
            if (y2<=y) // a downward crossing
                if (!(new LineSegment2D(x1, y1, x2, y2).isInside(point)))
                    wn--;
        }

        // for next iteration
        x1 = x2;
        y1 = y2;
    }

    return wn;
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:46,代码来源:Polygon2DUtils.java

示例13: Hyperbola2D

import math.geom2d.Point2D; //导入方法依赖的package包/类
public Hyperbola2D(Point2D center, double a, double b, double theta,
        boolean d) {
    this(center.getX(), center.getY(), a, b, theta, d);
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:5,代码来源:Hyperbola2D.java

示例14: setOrigin

import math.geom2d.Point2D; //导入方法依赖的package包/类
/**
 * @deprecated grids are supposed to be immutable (0.8.0)
 */
@Deprecated
public void setOrigin(Point2D point) {
    this.x0 = point.getX();
    this.y0 = point.getY();
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:9,代码来源:TriangleGrid2D.java

示例15: Ray2D

import math.geom2d.Point2D; //导入方法依赖的package包/类
/**
 * Creates a new Ray2D, originating from
 * <code>point1<\code>, and going in the
 * direction of <code>point2<\code>.
 */
public Ray2D(Point2D point1, Point2D point2) {
    this(point1.getX(), point1.getY(), 
    		point2.getX()-point1.getX(),
    		point2.getY()-point1.getY());
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:11,代码来源:Ray2D.java


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