All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.invation.code.toval.graphic.misc.RegularPolygon Maven / Gradle / Ivy

Go to download

TOVAL comprises a set of java classes for common programming issues. It includes utils for arrays, lists, sets and collections for convenient handling and modification, but also support for mathematic definitions concerning logic (clauses + resolution) together with some algorithms for permutations, powersets and resolution. Additionally it contains a number of types for multisets, matrices with object keys and much more.

The newest version!
package de.invation.code.toval.graphic.misc;

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

import de.invation.code.toval.validate.ParameterException;
import de.invation.code.toval.validate.Validate;

/**
 * This class stands for a circle that maintains a number of points that are positioned on the circle line with equal distance.
 */
public class RegularPolygon {

	/**
	 * The radius of the circle that is used for placement.
	 */
	protected double radius;
	/**
	 * The number of points.
	 */
	protected int numPoints;
	protected Point origin = new Point(0,0);
	/**
	 * The coordinates on the circular line that are used to place points.
	 */
	protected List coordinates = null;

	/**
	 * Creates a new PointCircle with the given order.
	 * @throws ParameterException 
	 */
	public RegularPolygon(int radius, int numPoints) throws ParameterException{
		Validate.positive(radius);
		Validate.positive(numPoints);
		Validate.bigger(numPoints, 2);
		
		this.radius = radius;
		this.numPoints = numPoints;
		coordinates = new ArrayList(numPoints);
		for(int i=0; i getCoordinates() {
		determineCoordinates();
		return coordinates;
	}
	
	public Polygon getPolygon(){
		Polygon result = new Polygon();
		for(Position coordinate: coordinates){
			result.addPoint(coordinate.getX(), coordinate.getY());
		}
		return result;
	}
	
	public Point getOrigin(){
		return new Point((int) origin.getX(), (int) origin.getY());
	}
	
	public double getArea(){
		getCoordinates();
		int oldOriginX = (int) origin.getX();
		int oldOriginY = (int) origin.getY();
		boolean resetNecessary = pushIntoFirstQuadrant();
		int sum = 0;
		int index = 0;
		int nextIndex = 0;
		for(int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy