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

straightedge.test.demo.WorldVogelSpiral Maven / Gradle / Ivy

Go to download

Includes 2 main parts: - Path finding through 2D polygons using the A star algorithm and navigation-mesh generation Field of vision / shadows / line of sight / lighting. The basic polygon and point classes are the KPolygon and KPoint. KPolygon contains a list of KPoints for vertices as well as a center (centroid), area, and radius (circular bound or distance from center to furthest point). KPolygon was born out of the need for a more game-oriented and flexible polygon class than the Path2D class in the standard Java library. KPolygon implements java.awt.geom.Shape so it can be easily drawn and filled by Java2D's Graphics2D object. - This API provides path-finding and field-of-vision. For other complex geometric operations such as buffering (fattening and shrinking) and constructive area geometry (intersections and unions) it is recommended to use the excellent Java Topology Suite (JTS). The standard Java2D library also provides the Area class which can be used for some constructive area geometry operations. Note that there is a utility class PolygonConverter that can quickly convert KPolygons to JTS polygons and vice versa.

The newest version!
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package straightedge.test.demo;

import java.awt.Container;
import java.util.ArrayList;
import straightedge.geom.KMultiPolygon;
import straightedge.geom.KPoint;
import straightedge.geom.KPolygon;

/**
 *
 * @author Keith
 */
public class WorldVogelSpiral extends World{
	public WorldVogelSpiral(Main main){
		super(main);
	}
	public void fillMultiPolygonsList(){
		Container cont = main.getParentFrameOrApplet();
		double contW = cont.getWidth() - (cont.getInsets().right + cont.getInsets().left);
		double contH = cont.getHeight() - (cont.getInsets().top + cont.getInsets().bottom);

		ArrayList allPolys = new ArrayList();

		// vogel spiral (137.5 degrees)
		{
			KPoint centerOfSpiral = new KPoint(contW/2f, contH/2f);
			double maxN = 100;
			double r = 0;
            double angle = 0;
			double angleConstant = Math.toRadians(137.5);
			for (int n = 0; n < maxN; n++){
				angle = n*angleConstant;
				r = 22*Math.sqrt(n);
				double x = r*Math.cos(angle);
				double y = r*Math.sin(angle);
				KPoint center = new KPoint((float)x, (float)y);
				KPolygon poly = KPolygon.createRegularPolygon(12, 8);
				poly.rotate((float)angle);
				poly.translateTo(center);
				poly.translate(centerOfSpiral);
				allPolys.add(poly);
			}
		}
		

		for (int i = 0; i < allPolys.size(); i++){
			KMultiPolygon multiPolygon = new KMultiPolygon(allPolys.get(i).getPolygon().copy());
			allMultiPolygons.add(multiPolygon);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy