• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Point2D类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中edu.princeton.cs.algs4.Point2D的典型用法代码示例。如果您正苦于以下问题:Java Point2D类的具体用法?Java Point2D怎么用?Java Point2D使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: nearest

import edu.princeton.cs.algs4.Point2D; //导入依赖的package包/类
private Champion nearest(Node node, Champion champ, Point2D p) {
    if (node==null) return champ;

    Double dist = node.point.distanceTo(p);
    if (dist < champ.distance) {
        champ.distance = dist;
        champ.point = node.point;
    }

    int cmp = node.compare(p);
    if (cmp < 0) {
        champ = nearest(node.left, champ, p);
        if (node.verticalDist(p) < champ.distance) {
            champ = nearest(node.right, champ, p);
        }
    }
    else if (cmp > 0) {
        champ = nearest(node.right, champ, p);
        if (node.verticalDist(p) < champ.distance) { champ = nearest(node.left, champ, p); }
    }
    return champ;
}
 
开发者ID:SkullTech,项目名称:algorithms-princeton,代码行数:23,代码来源:KdTree.java


示例2: nearest

import edu.princeton.cs.algs4.Point2D; //导入依赖的package包/类
public Point2D nearest(Point2D p) {
    if(p == null)
        throw new java.lang.NullPointerException("NULL ARGUMENT!");
    if(isEmpty())
        return null;
    Point2D ptmp = new Point2D(0,0);
    double minD =  Double.POSITIVE_INFINITY;
    for(Point2D ptable : rbst.keys()) {
        double tmpD = p.distanceSquaredTo(ptable);
        if(tmpD < minD) {
            minD = tmpD;
            ptmp = ptable;
        }
    }
    return ptmp;
}
 
开发者ID:robotenique,项目名称:intermediateProgramming,代码行数:17,代码来源:PointST.java


示例3: countTriples

import edu.princeton.cs.algs4.Point2D; //导入依赖的package包/类
private int countTriples(Point2D[] points) {

        boolean allYCoordinatesAreXCubic = true;

        for(Point2D point2D : points) {

            if (point2D.y() != Math.pow(point2D.x(), 3)) {
                allYCoordinatesAreXCubic = false;
                break;
            }
        }

        if (allYCoordinatesAreXCubic) {
            return countTriplesWithCubicYs(points);
        } else {
            return countTriplesUsingSlopes(points);
        }
    }
 
开发者ID:reneargento,项目名称:algorithms-sedgewick-wayne,代码行数:19,代码来源:Exercise26_3Collinearity.java


示例4: drawAndCreatePoints

import edu.princeton.cs.algs4.Point2D; //导入依赖的package包/类
private static void drawAndCreatePoints(Point2D[] points) {
	
	StdDraw.setCanvasSize(1024, 512);
	StdDraw.setPenRadius(.015);
       StdDraw.setXscale(0, 1);
       StdDraw.setYscale(0, 1);
	
	for (int i = 0; i<points.length; i++) {

		double pointX = StdRandom.uniform();
		double pointY = StdRandom.uniform();
		
		Point2D point = new Point2D(pointX, pointY);
		StdDraw.point(point.x(), point.y()); //The exercise doesn't require drawing, but it adds a nice touch
		
		points[i] = point;
	}
}
 
开发者ID:reneargento,项目名称:algorithms-sedgewick-wayne,代码行数:19,代码来源:Exercise1.java


示例5: calculateShortestDistance

import edu.princeton.cs.algs4.Point2D; //导入依赖的package包/类
private static double calculateShortestDistance(Point2D[] points) {
	
	double shortestDistance = Double.MAX_VALUE;
	double currentDistance = Double.MAX_VALUE;
	
	Arrays.sort(points, points[0].distanceToOrder());
	
	for (int i = 1; i < points.length; i++) {
		currentDistance = points[i].distanceTo(points[i-1]);
		
		if (currentDistance < shortestDistance) {
			shortestDistance = currentDistance;
		}
	}
	
	return shortestDistance;
}
 
开发者ID:reneargento,项目名称:algorithms-sedgewick-wayne,代码行数:18,代码来源:Exercise1.java


示例6: main

import edu.princeton.cs.algs4.Point2D; //导入依赖的package包/类
public static void main(String[] args) {
    RectHV rect = new RectHV(0.0, 0.0, 1.0, 1.0);
    StdDraw.show(0);
    KdTree kdtree = new KdTree();
    while (true) {
        if (StdDraw.mousePressed()) {
            double x = StdDraw.mouseX();
            double y = StdDraw.mouseY();
            StdOut.printf("%8.6f %8.6f\n", x, y);
            Point2D p = new Point2D(x, y);
            if (rect.contains(p)) {
                StdOut.printf("%8.6f %8.6f\n", x, y);
                kdtree.insert(p);
                StdDraw.clear();
                kdtree.draw();
            }
        }
        StdDraw.show(50);
    }

}
 
开发者ID:goldsborough,项目名称:algs4,代码行数:22,代码来源:KdTreeVisualizer.java


示例7: nearest

import edu.princeton.cs.algs4.Point2D; //导入依赖的package包/类
public Point2D nearest(Point2D target)
{
	assertArgument(target);

	Point2D champion = null;

	double best = Double.POSITIVE_INFINITY;

	for (Point2D point : set)
	{
		double distance = point.distanceTo(target);

		if (champion == null || distance < best)
		{
			champion = point;
			best = distance;
		}
	}

	return champion;
}
 
开发者ID:goldsborough,项目名称:algs4,代码行数:22,代码来源:PointSET.java


示例8: compare

import edu.princeton.cs.algs4.Point2D; //导入依赖的package包/类
private int compare(Point2D p) {
    if (point.compareTo(p)==0) { return 0; }

    if (vertical) {
        if      (p.x() < point.x()) { return -1; }
        else if (p.x() > point.x()) { return  1; }
        else                        { return -1; }
    }
    else {
        if      (p.y() < point.y()) { return -1; }
        else if (p.y() > point.y()) { return  1; }
        else                        { return -1; }
    }
}
 
开发者ID:SkullTech,项目名称:algorithms-princeton,代码行数:15,代码来源:KdTree.java


示例9: insert

import edu.princeton.cs.algs4.Point2D; //导入依赖的package包/类
private Node insert(Node node, Point2D p, boolean vertical) {
    if (node==null) {
        this.N++;
        return new Node(p, vertical);
    }

    assert (node.vertical == vertical);
    int cmp = node.compare(p);
    if      (cmp < 0) { node.left  = insert(node.left,  p, !vertical); }
    else if (cmp > 0) { node.right = insert(node.right, p, !vertical); }

    return node;
}
 
开发者ID:SkullTech,项目名称:algorithms-princeton,代码行数:14,代码来源:KdTree.java


示例10: contains

import edu.princeton.cs.algs4.Point2D; //导入依赖的package包/类
public boolean contains(Point2D p) {
    Node node = root;

    while (node!=null) {
        int cmp = node.compare(p);
        if      (cmp < 0) { node = node.left;  }
        else if (cmp > 0) { node = node.right; }
        else              { return true;       }
    }

    return false;
}
 
开发者ID:SkullTech,项目名称:algorithms-princeton,代码行数:13,代码来源:KdTree.java


示例11: range

import edu.princeton.cs.algs4.Point2D; //导入依赖的package包/类
private void range(ArrayList<Point2D> list, Node node, RectHV rect) {
    if (node==null) return;

    int cmp = node.compare(rect);

    if      (cmp > 0) { range(list, node.right, rect); }
    else if (cmp < 0) { range(list, node.left,  rect); }
    else {
        if (rect.contains(node.point)) { list.add(node.point); }
        range(list, node.left, rect);
        range(list, node.right, rect);
    }
}
 
开发者ID:SkullTech,项目名称:algorithms-princeton,代码行数:14,代码来源:KdTree.java


示例12: range

import edu.princeton.cs.algs4.Point2D; //导入依赖的package包/类
public Iterable<Point2D> range(RectHV rect) {
    if (rect==null) { throw new IllegalArgumentException(); }

    ArrayList<Point2D> it = new ArrayList<>();
    for (Point2D p: set) { if (rect.contains(p)) { it.add(p); } }
    return it;
}
 
开发者ID:SkullTech,项目名称:algorithms-princeton,代码行数:8,代码来源:PointSET.java


示例13: updatePositionAndVelocity

import edu.princeton.cs.algs4.Point2D; //导入依赖的package包/类
public Vector updatePositionAndVelocity(Boid nearest) {
    double x = x() + velocity.cartesian(0);
    double y = y() + velocity.cartesian(1);
    position = new Point2D(x, y);
    Vector desire = eatBoid(nearest).direction().scale(0.0003);
    velocity = velocity.plus(desire);
    return desire;
}
 
开发者ID:robotenique,项目名称:intermediateProgramming,代码行数:9,代码来源:Hawk.java


示例14: lookUpBoids

import edu.princeton.cs.algs4.Point2D; //导入依赖的package包/类
private static Iterable<Boid> lookUpBoids(KdTreeST<Boid> bkd, Iterable<Point2D> points) {
    Queue<Boid> values = new Queue<Boid>();
    for (Point2D p : points) {
        values.enqueue(bkd.get(p));
    }
    return values;
}
 
开发者ID:robotenique,项目名称:intermediateProgramming,代码行数:8,代码来源:BoidSimulator.java


示例15: range

import edu.princeton.cs.algs4.Point2D; //导入依赖的package包/类
public Iterable<Point2D> range(RectHV rect) {
    if(rect == null)
        throw new java.lang.NullPointerException("NULL ARGUMENT!");
    Queue<Point2D> internalPoints = new Queue<>();
    for(Point2D p : rbst.keys())
        if(rect.contains(p))
            internalPoints.enqueue(p);
    return internalPoints;
}
 
开发者ID:robotenique,项目名称:intermediateProgramming,代码行数:10,代码来源:PointST.java


示例16: updatePositionAndVelocity

import edu.princeton.cs.algs4.Point2D; //导入依赖的package包/类
public Vector updatePositionAndVelocity(Iterable<Boid> neighbors, Hawk hawk) {
    double x = x() + velocity.cartesian(0);
    double y = y() + velocity.cartesian(1);
    position = new Point2D(x, y);
    Vector desire = desiredAcceleration(neighbors, hawk);
    velocity = velocity.plus(desire);
    return desire;
}
 
开发者ID:robotenique,项目名称:intermediateProgramming,代码行数:9,代码来源:Boid.java


示例17: main

import edu.princeton.cs.algs4.Point2D; //导入依赖的package包/类
public static void main(String[] args) {

        Exercise26_3Collinearity exercise26_3Collinearity = new Exercise26_3Collinearity();

        Point2D[] points = new Point2D[6];
        for(int i = 0; i < points.length; i++) {
            Point2D point = new Point2D(i, i + 1.5);
            points[i] = point;
        }

        int numberOfTriples1 = exercise26_3Collinearity.countTriples(points);
        StdOut.println("Number of triples: " + numberOfTriples1  + " Expected: 10");

        //Based on https://www.algebra.com/algebra/homework/Length-and-distance/Length-and-distance.faq.question.530663.html
        //(-3,4) (3,2) (6,1) are on the same line
        Point2D pointA = new Point2D(-3, 4);
        Point2D pointB = new Point2D(3, 2);
        Point2D pointC = new Point2D(6, 1);

        Point2D[] points2 = {pointA, pointB, pointC};

        int numberOfTriples2 = exercise26_3Collinearity.countTriples(points2);
        StdOut.println("Number of triples: " + numberOfTriples2  + " Expected: 1");

        Point2D pointD = new Point2D(6, 1);

        Point2D[] points3 = {pointA, pointB, pointC, pointD};

        int numberOfTriples3 = exercise26_3Collinearity.countTriples(points3);
        StdOut.println("Number of triples: " + numberOfTriples3  + " Expected: 3");

        //Case with cubic y coordinate
        Point2D pointE = new Point2D(1, 1);
        Point2D pointF = new Point2D(2, 8);
        Point2D pointG = new Point2D(-3, -27);

        Point2D[] points4 = {pointE, pointF, pointG};
        int numberOfTriples4 = exercise26_3Collinearity.countTriples(points4);
        StdOut.println("Number of triples: " + numberOfTriples4  + " Expected: 1");
    }
 
开发者ID:reneargento,项目名称:algorithms-sedgewick-wayne,代码行数:41,代码来源:Exercise26_3Collinearity.java


示例18: range

import edu.princeton.cs.algs4.Point2D; //导入依赖的package包/类
public Iterable<Point2D> range(RectHV rect)
{
	assertArgument(rect);

	ArrayList<Point2D> points = new ArrayList<>(set.size());

	for (Point2D point : set)
	{
		if (rect.contains(point)) points.add(point);
	}

	return points;
}
 
开发者ID:goldsborough,项目名称:algs4,代码行数:14,代码来源:PointSET.java


示例19: main

import edu.princeton.cs.algs4.Point2D; //导入依赖的package包/类
public static void main(String[] args)
{
	PointSET set = new PointSET();

	set.insert(new Point2D(1, 1));
	set.insert(new Point2D(2, 2));
	set.insert(new Point2D(3, 3));

	System.out.println(set.nearest(new Point2D(1.5, 1.5)).toString());
}
 
开发者ID:goldsborough,项目名称:algs4,代码行数:11,代码来源:PointSET.java


示例20: Node

import edu.princeton.cs.algs4.Point2D; //导入依赖的package包/类
private Node(Point2D p, boolean vertical) {
    point = p;
    this.vertical = vertical;
}
 
开发者ID:SkullTech,项目名称:algorithms-princeton,代码行数:5,代码来源:KdTree.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java LogstashTcpSocketAppender类代码示例发布时间:2022-05-23
下一篇:
Java OtpErlangObject类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap