|
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
namespace PolygonIntersection {
public class Polygon {
private List<Vector> points = new List<Vector>();
private List<Vector> edges = new List<Vector>();
public void BuildEdges() {
Vector p1;
Vector p2;
edges.Clear();
for (int i = 0; i < points.Count; i++) {
p1 = points[i];
if (i + 1 >= points.Count) {
p2 = points[0];
} else {
p2 = points[i + 1];
}
edges.Add(p2 - p1);
}
}
public List<Vector> Edges {
get { return edges; }
}
public List<Vector> Points {
get { return points; }
}
public Vector Center {
get {
float totalX = 0;
float totalY = 0;
for (int i = 0; i < points.Count; i++) {
totalX += points[i].X;
totalY += points[i].Y;
}
return new Vector(totalX / (float)points.Count, totalY / (float)points.Count);
}
}
public void Offset(Vector v) {
Offset(v.X, v.Y);
}
public void Offset(float x, float y) {
for (int i = 0; i < points.Count; i++) {
Vector p = points[i];
points[i] = new Vector(p.X + x, p.Y + y);
}
}
public override string ToString() {
string result = "";
for (int i = 0; i < points.Count; i++) {
if (result != "") result += " ";
result += "{" + points[i].ToString(true) + "}";
}
return result;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Pogopixels is a London based software company specialising in the development of widgets, Flash and internet-based software.
It delivers innovative software solutions to companies using the latest technologies including Adobe AIR, Yahoo Widgets, or Google Desktop.
Have a look at pogopixels.com for more information.
On my spare time, I work on the Appetizer open source project: http://app.etizer.org It's a portable dock for Windows.