コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the Cube3D class
 /// </summary>
 /// <param name="faces">Faces</param>
 /// <param name="position">Position</param>
 public Cube3D(IEnumerable<Face3D> faces, CubeFlag position, Point3D location, double scale)
 {
     this.Faces = faces;
     this.Position = position;
       this.Location = location;
       this.Scale = scale;
 }
コード例 #2
0
ファイル: Point3D.cs プロジェクト: Borsos/RubiksCubeSolver-1
    // *** METHODS ***

    /// <summary>
    /// Rotates the point around a particular axis
    /// </summary>
    /// <param name="type">Rotation axis</param>
    /// <param name="angleInDeg">Angle to be rotated</param>
    public void Rotate(RotationType type, double angleInDeg)
    {
      // Rotation matrix: http://de.wikipedia.org/wiki/Drehmatrix
      double rad = angleInDeg * Math.PI / 180;
      double cosa = Math.Cos(rad);
      double sina = Math.Sin(rad);

      Point3D old = new Point3D(this.X, this.Y, this.Z);

      switch (type)
      {
        case RotationType.X:
          this.Y = old.Y * cosa - old.Z * sina;
          this.Z = old.Y * sina + old.Z * cosa;
          break;
        case RotationType.Y:
          this.X = old.Z * sina + old.X * cosa;
          this.Z = old.Z * cosa - old.X * sina;
          break;
        case RotationType.Z:
          this.X = old.X * cosa - old.Y * sina;
          this.Y = old.X * sina + old.Y * cosa;
          break;
      }
    }
コード例 #3
0
        // *** METHODS ***

        /// <summary>
        /// Rotates the point around a particular axis
        /// </summary>
        /// <param name="type">Rotation axis</param>
        /// <param name="angle">Angle to be rotated</param>
        /// <param name="center">Center point of rotation</param>
        public Cube3D Rotate(RotationType type, double angle, Point3D center)
        {
            //Deep Clone
            var faces = new List<Face3D>();
            foreach (var f2 in from f in this.Faces let edges = f.Vertices.Select(p => new Point3D(p.X, p.Y, p.Z)).ToList() select new Face3D(edges, f.Color, f.Position, f.MasterPosition))
            {
                f2.Vertices.ToList().ForEach(e => { e.X -= center.X; e.Y -= center.Y; e.Z -= center.Z; });
                f2.Rotate(type, angle);
                f2.Vertices.ToList().ForEach(e => { e.X += center.X; e.Y += center.Y; e.Z += center.Z; });
                faces.Add(f2);
            }
            return new Cube3D(faces, this.Position, this.Location, this.Scale);
        }
コード例 #4
0
 // *** CONSTRUCTOR ***
 /// <summary>
 /// Initializes a new instance of the Cube3D class
 /// </summary>
 /// <param name="location">Center point</param>
 /// <param name="scale">Scale</param>
 /// <param name="position">Position</param>
 /// <param name="faces">Faces</param>
 public Cube3D(Point3D location, double scale, CubeFlag position, IEnumerable<Face> faces)
 {
     this.Faces = UniCube.GenFaces3D(position);
     this.Position = position;
       this.Location = location;
       this.Scale = scale;
     this.Faces.ToList().ForEach(f =>
     {
         f.Color = faces.First(face => face.Position == f.Position).Color;
         f.Vertices.ToList().ForEach(e =>
         {
             e.X *= scale;
             e.Y *= scale;
             e.Z *= scale; //scale
             e.X += location.X;
             e.Y += location.Y;
             e.Z += location.Z; //translate
         });
     });
 }
コード例 #5
0
 // *** METHODS ***
 /// <summary>
 /// Rotates the point around a particular axis
 /// </summary>
 /// <param name="type">Rotation axis</param>
 /// <param name="angle">Angle to be rotated</param>
 /// <param name="center">Center point of rotation</param>
 public Cube3D Rotate(RotationType type, double angle, Point3D center)
 {
     //Deep Clone
       List<Face3D> faces = new List<Face3D>();
       foreach (Face3D f in Faces)
       {
     List<Point3D> edges = new List<Point3D>();
     foreach (Point3D p in f.Vertices) { edges.Add(new Point3D(p.X, p.Y, p.Z)); }
     Face3D f2 = new Face3D(edges, f.Color, f.Position, f.MasterPosition);
     f2.Vertices.ToList().ForEach(e => { e.X -= center.X; e.Y -= center.Y; e.Z -= center.Z; });
     f2.Rotate(type, angle);
     f2.Vertices.ToList().ForEach(e => { e.X += center.X; e.Y += center.Y; e.Z += center.Z; });
     faces.Add(f2);
       }
       return new Cube3D(faces, this.Position, this.Location,this.Scale);
 }