public static UniformPoint operator -(UniformPoint a, UniformPoint b) { UniformPoint ret = new UniformPoint(0, 0, 0, 1); for (int i = 0; i < 3; i++) ret.coordinates[i] = a.coordinates[i] - b.coordinates[i]; return ret; }
public static double DotProduct(UniformPoint a, UniformPoint b) { double ret = 0; for (int i = 0; i < 3; i++) ret += a.coordinates[i] * b.coordinates[i]; return ret; }
public static UniformPoint CrossProduct(UniformPoint a, UniformPoint b) { double x1 = a.coordinates[0]; double y1 = a.coordinates[1]; double z1 = a.coordinates[2]; double x2 = b.coordinates[0]; double y2 = b.coordinates[1]; double z2 = b.coordinates[2]; return new UniformPoint(y1 * z2 - y2 * z1, z1 * x2 - x1 * z2, x1 * y2 - y1 * x2, 1); }
public UniformPoint(UniformPoint p) { coordinates = new double[4]; p.coordinates.CopyTo(coordinates, 0); }
public void Transform(double[][] t, ref UniformPoint p) { p.coordinates = Matrix.VectorMatrixMlp(coordinates, t, 4); }
void MakePrism(int edgeCount, int height, int radius) { triangles = new Triangle[edgeCount * 4]; vertices = new UniformPoint[edgeCount * 2 + 2]; UniformPoint[] tmp = new UniformPoint[edgeCount]; MakePolygon(edgeCount, radius, 0, tmp); for (int i = 0; i < edgeCount; i++) vertices[i] = tmp[i]; MakePolygon(edgeCount, radius, height, tmp); for (int i = 0; i < edgeCount; i++) vertices[i + edgeCount] = tmp[i]; vertices[edgeCount * 2] = new UniformPoint(0, 0, 0, 1); vertices[edgeCount * 2 + 1] = new UniformPoint(0, 0, height, 1); for (int i = 0; i < triangles.Length; i++) triangles[i] = new Triangle(0, 0, 0); for (int i = 0; i < edgeCount; i++) { int v1 = i; int v2 = (i + 1) % edgeCount; int v3 = i + edgeCount; int v4 = i + edgeCount + 1; if(v4 == edgeCount * 2) v4 = edgeCount; triangles[i] = new Triangle(edgeCount * 2, v1, v2); triangles[i + edgeCount] = new Triangle(edgeCount * 2 + 1, v3, v4); triangles[i + edgeCount * 2] = new Triangle(v1, v3, v4); triangles[i + edgeCount * 3] = new Triangle(v1, v4, v2); } }
void MakePolygon(int n, double radius, double h, UniformPoint[] ret) { double addAngle = Math.PI * 2 / n; double angle = 0; for (int i = 0; i < n; i++) { ret[i] = new UniformPoint(radius * Math.Cos(angle), radius * Math.Sin(angle), h, 1); angle += addAngle; } }