Пример #1
0
 public Polyhedron(Face[] _faces, Point3d _center)
 {
     faces = new Face[_faces.Length];
     for (int i = 0; i < faces.Length; ++i)
     {
         faces[i] = _faces[i].Clone() as Face;
     }
     center = _center.Clone() as Point3d;
 }
Пример #2
0
        public void Can_BeCloned()
        {
            const double a       = 3.3;
            const double b       = 2.2;
            const double c       = 4.11;
            var          ptA     = new Point3d(a, b, c);
            var          ptClone = ptA.Clone();

            Assert.False(ReferenceEquals(ptA, ptClone));
        }
Пример #3
0
    public IFigure Clone()
    {
        Polyhedron res = new Polyhedron();

        res.faces = new Face[faces.Length];
        for (int i = 0; i < faces.Length; ++i)
        {
            res.faces[i] = faces[i].Clone() as Face;
        }
        res.center = center.Clone() as Point3d;
        return(res);
    }
Пример #4
0
    public override bool find_cross(Point3d cam_pos, Point3d ray_pos, ref Point3d t)
    {
        if (!sph.find_cross(cam_pos, ray_pos, ref t))
        {
            return(false);
        }

        double  dist = double.MaxValue;
        Point3d res  = new Point3d();
        bool    flag = false;

        foreach (var face in ph.Faces)
        {
            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(cam_pos, ray_pos);
            Vector u = new Vector(cam_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 Point3d(
                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(cam_pos, t).Norm();
            if (dist_t < dist)
            {
                res  = t.Clone() as Point3d;
                dist = dist_t;
                flag = true;
            }
        }

        t = res.Clone() as Point3d;
        return(flag);
    }
Пример #5
0
 /**
  * Constructor for a ray
  *
  * @param direction direction ray
  * @param point beginning of the ray
  */
 public Line(Vector3d direction, Point3d point)
 {
     this.direction = direction.Clone();
     this.point = point.Clone();
     direction.normalize();
 }
Пример #6
0
 //-----------------------------------SETS---------------------------------------//
 /**
  * Sets a new point
  *
  * @param point new point
  */
 public void setPoint(Point3d point)
 {
     this.point = point.Clone();
 }