001 // GraphLab Project: http://graphlab.sharif.edu 002 // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology 003 // Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/ 004 package graphlab.plugins.graphgenerator.core; 005 006 import java.awt.*; 007 008 /** 009 * User: root 010 */ 011 public class PositionGenerators { 012 public static Point[] line(int xOffset, int yOffset, int w, int h, int n) { 013 Point[] ret = new Point[n]; 014 int dx = w / n; 015 int dy = h / n; 016 for (int i = 0; i < n; i++) { 017 ret[i] = new Point(xOffset + i * dx, yOffset + i * dy); 018 } 019 return ret; 020 } 021 022 public static Point[] circle(int xOffset, int yOffset, int w, int h, int n) { 023 Point[] ret = new Point[n]; 024 w = w / 2; 025 h = h / 2; 026 w -= xOffset; 027 h -= yOffset; 028 for (int i = 0; i < n; i++) { 029 double deg = 2 * Math.PI / n * i; 030 double x = Math.sin(deg); 031 double y = Math.cos(deg); 032 x *= w; 033 y *= h; 034 x += w; 035 y += h; 036 x += xOffset; 037 y += yOffset; 038 ret[i] = new Point((int) x, (int) y); 039 } 040 return ret; 041 } 042 043 public static Point[] circle(int r, int x, int y, int n) { 044 Point[] ret = circle(0, 0, r, r, n); 045 shift(ret, x - r / 2, y - r / 2); 046 return ret; 047 } 048 049 public static Point[] shift(Point[] input, int xOffset, int yOffset) { 050 for (Point p : input) { 051 p.x += xOffset; 052 p.y += yOffset; 053 } 054 return input; 055 } 056 }