Java Geometry Algorithm generateRobotPositions(Point start, Point end, int stepSize)

Here you can find the source of generateRobotPositions(Point start, Point end, int stepSize)

Description

generate Robot Positions

License

Open Source License

Declaration

public static List<Point> generateRobotPositions(Point start, Point end, int stepSize) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Point;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<Point> generateRobotPositions(Point start, Point end, int stepSize) {
        List<Point> positions = new ArrayList<Point>();

        int numXIterations = Math.abs(start.x - end.x) / stepSize;
        int lastStepSize = Math.abs(start.x - end.x) % stepSize;
        int startX = start.x;
        int startY = start.y;
        for (int i = 0; i < numXIterations; i++) {
            startX = (start.x > end.x) ? startX - stepSize : startX + stepSize;
            Point temp = new Point(startX, startY);
            positions.add(temp);/*from  w w w .  j  ava 2  s.com*/
        }
        if (lastStepSize > 0) {
            startX = (start.x > end.x) ? startX - lastStepSize : startX + lastStepSize;
            Point temp = new Point(startX, startY);
            positions.add(temp);
        }

        int numYIterations = Math.abs(start.y - end.y) / stepSize;
        lastStepSize = Math.abs(start.y - end.y) % stepSize;
        for (int i = 0; i < numYIterations; i++) {
            startY = (start.y > end.y) ? startY - stepSize : startY + stepSize;
            Point temp = new Point(startX, startY);
            positions.add(temp);
        }
        if (lastStepSize > 0) {
            startY = (start.y > end.y) ? startY - lastStepSize : startY + lastStepSize;
            Point temp = new Point(startX, startY);
            positions.add(temp);
        }

        return positions;
    }
}

Related

  1. fitCircle(final Point2D P1, final Point2D P2, final Point2D P3)
  2. forceMouseMove(Point pos)
  3. generateLine(Point2D.Double point, double length, double angle)
  4. generateLookAtTag(ArrayList geoCoords, ArrayList modsAM)
  5. generatePoint(Shape region)
  6. generateSpline(final Point[] controls)
  7. gridAlign(final Point2D point, final double gridX, final double gridY)
  8. hitsLine(final Point2D p, final Point2D fromPoint, final Point2D toPoint, final double thickness)
  9. insidePoly(Polygon pg, Point p)