public Polyhedron(Verge[] _verges, XYZPoint _center) { verges = new Verge[_verges.Length]; for (int i = 0; i < verges.Length; ++i) { verges[i] = _verges[i].Clone() as Verge; } center = _center.Clone() as XYZPoint; }
public Primitive Clone() { Polyhedron res = new Polyhedron(); res.verges = new Verge[verges.Length]; for (int i = 0; i < verges.Length; ++i) { res.verges[i] = verges[i].Clone() as Verge; } res.center = center.Clone() as XYZPoint; return(res); }
public override bool find_cross(XYZPoint Camera_pos, XYZPoint ray_pos, ref XYZPoint t) { if (!outside_sphere.find_cross(Camera_pos, ray_pos, ref t)) { return(false); } double dist = double.MaxValue; XYZPoint res = new XYZPoint(); bool flag = false; foreach (var face in ph.Verges) { var p1 = face.Edges[0].First; var p2 = face.Edges[1].First; var p3 = face.Edges[2].First; Vector v1 = new Vector(p1, p2); Vector v2 = new Vector(p1, p3); Vector n = v1[v2]; double d = -(n.X * p1.X + n.Y * p1.Y + n.Z * p1.Z); Vector v = new Vector(Camera_pos, ray_pos); Vector u = new Vector(Camera_pos); double denum = n * v; if (Math.Abs(denum) < eps) { continue; } double num = n * u + d; double tp = -num / denum; if (tp < eps) { continue; } t = new XYZPoint( v.X * tp + u.X, v.Y * tp + u.Y, v.Z * tp + u.Z); double square = 0; int cnt = face.Edges.Count(); for (int i = 0; i < cnt; ++i) { square += triangle_square(face.Edges[i].First, face.Edges[(i + 1) % cnt].First, t); } if (Math.Abs(squares[face] - square) > eps) { continue; } var dist_t = new Vector(Camera_pos, t).Norm(); if (dist_t < dist) { res = t.Clone() as XYZPoint; dist = dist_t; flag = true; } } t = res.Clone() as XYZPoint; return(flag); }