示例#1
0
 /// <summary>
 /// Rotate coordinate system
 /// </summary>
 public void Rotate(Rotation r)
 {
     _axes = _axes * r.ConvertToGlobal().ToRotationMatrix.Transpose();
 }
示例#2
0
 public Ellipse Rotate(Matrix3d m, Point3d p)
 {
     return(new Ellipse(this.Center.Rotate(m, p), _v1.Rotate(m), _v2.Rotate(m)));
 }
示例#3
0
 public Point3d Rotate(Matrix3d m)
 {
     return(m * this);
 }
示例#4
0
        /// <summary>
        /// Intersection of ellipsoid with plane.
        /// Returns 'null' (no intersection) or object of type 'Point3d' or 'Ellipse'.
        /// </summary>
        public object IntersectionWith(Plane3d plane)
        {
            // Solution 1:
            // Peter Paul Klein
            // On the Ellipsoid and Plane Intersection Equation
            // Applied Mathematics, 2012, 3, 1634-1640 (DOI:10.4236/am.2012.311226)

            // Solution 2:
            // Sebahattin Bektas
            // Intersection of an Ellipsoid and a Plane
            // International Journal of Research in Engineering and Applied Sciences, VOLUME 6, ISSUE 6 (June, 2016)

            Coord3d lc = new Coord3d(_point, _v1, _v2, "LC1");

            plane.SetCoord(lc);
            double Ax, Ay, Az, Ad;
            double a, b, c;

            if (Abs(plane.C) >= Abs(plane.A) && Abs(plane.C) >= Abs(plane.B))
            {
                a = this.A; b = this.B; c = this.C;
            }
            else
            {
                lc = new Coord3d(_point, _v2, _v3, "LC2");
                plane.SetCoord(lc);
                if (Abs(plane.C) >= Abs(plane.A) && Abs(plane.C) >= Abs(plane.B))
                {
                    a = this.B; b = this.C; c = this.A;
                }
                else
                {
                    lc = new Coord3d(_point, _v3, _v1, "LC3");
                    plane.SetCoord(lc);
                    a = this.C; b = this.A; c = this.B;
                }
            }

            Ax = plane.A; Ay = plane.B; Az = plane.C; Ad = plane.D;
            double tmp = (Az * Az * c * c);
            double AA  = 1.0 / (a * a) + Ax * Ax / tmp;
            double BB  = 2.0 * Ax * Ay / tmp;
            double CC  = 1.0 / (b * b) + Ay * Ay / tmp;
            double DD  = 2.0 * Ax * Ad / tmp;
            double EE  = 2.0 * Ay * Ad / tmp;
            double FF  = Ad * Ad / tmp - 1.0;

            double det = 4.0 * AA * CC - BB * BB;

            if (GeometRi3D.AlmostEqual(det, 0))
            {
                return(null);
            }
            double X0 = (BB * EE - 2 * CC * DD) / det;
            double Y0 = (BB * DD - 2 * AA * EE) / det;
            double Z0 = -(Ax * X0 + Ay * Y0 + Ad) / Az;

            Point3d P0 = new Point3d(X0, Y0, Z0, lc);

            if (P0.IsOnBoundary(this))
            {
                // the plane is tangent to ellipsoid
                return(P0);
            }
            else if (P0.IsInside(this))
            {
                Vector3d q  = P0.ToVector.ConvertTo(lc);
                Matrix3d D1 = Matrix3d.DiagonalMatrix(1 / a, 1 / b, 1 / c);
                Vector3d r  = plane.Normal.ConvertTo(lc).OrthogonalVector.Normalized;
                Vector3d s  = plane.Normal.ConvertTo(lc).Cross(r).Normalized;

                double omega = 0;
                double qq, qr, qs, rr, ss, rs;
                if (!GeometRi3D.AlmostEqual((D1 * r) * (D1 * s), 0))
                {
                    rr = (D1 * r) * (D1 * r);
                    rs = (D1 * r) * (D1 * s);
                    ss = (D1 * s) * (D1 * s);
                    if (GeometRi3D.AlmostEqual(rr - ss, 0))
                    {
                        omega = PI / 4;
                    }
                    else
                    {
                        omega = 0.5 * Atan(2.0 * rs / (rr - ss));
                    }
                    Vector3d rprim = Cos(omega) * r + Sin(omega) * s;
                    Vector3d sprim = -Sin(omega) * r + Cos(omega) * s;
                    r = rprim;
                    s = sprim;
                }

                qq = (D1 * q) * (D1 * q);
                qr = (D1 * q) * (D1 * r);
                qs = (D1 * q) * (D1 * s);
                rr = (D1 * r) * (D1 * r);
                ss = (D1 * s) * (D1 * s);

                double d = qq - qr * qr / rr - qs * qs / ss;
                AA = Sqrt((1 - d) / rr);
                BB = Sqrt((1 - d) / ss);

                return(new Ellipse(P0, AA * r, BB * s));
            }
            else
            {
                return(null);
            }
        }
示例#5
0
 public Ellipsoid Rotate(Matrix3d m)
 {
     return(new Ellipsoid(this.Center.Rotate(m), _v1.Rotate(m), _v2.Rotate(m), _v3.Rotate(m)));
 }
示例#6
0
 public Sphere Rotate(Matrix3d m, Point3d p)
 {
     return(new Sphere(this.Center.Rotate(m, p), this.R));
 }
示例#7
0
 public Vector3d Rotate(Matrix3d m)
 {
     return(m * this);
 }
示例#8
0
 /// <summary>
 /// Initializes rotation using quaternion.
 /// </summary>
 /// <param name="q"></param>
 public Rotation(Quaternion q)
 {
     _r     = q.ToRotationMatrix();
     _coord = q.Coord;
 }
示例#9
0
        /// <summary>
        /// Combine two rotations.
        /// </summary>
        public Rotation Mult(Rotation r)
        {
            Matrix3d m = this.ToRotationMatrix * r.ConvertTo(this.Coord).ToRotationMatrix;

            return(new Rotation(m, this.Coord));
        }
示例#10
0
 /// <summary>
 /// Initializes rotation, equal to the rotation from global CS to 'coord'.
 /// </summary>
 public Rotation(Coord3d coord)
 {
     _r     = coord.Axes.Transpose();
     _coord = Coord3d.GlobalCS;
 }
示例#11
0
 /// <summary>
 /// Initializes rotation using rotation matrix.
 /// </summary>
 /// <param name="m">Rotation matrix.</param>
 /// <param name="coord">Reference coordinate system (default - Coord3d.GlobalCS).</param>
 public Rotation(Matrix3d m, Coord3d coord = null)
 {
     _r     = m.Copy();
     _coord = (coord == null) ? Coord3d.GlobalCS : coord;
 }
示例#12
0
 /// <summary>
 /// Default constructor, initializes identity matrix (zero rotation).
 /// </summary>
 public Rotation()
 {
     _r     = Matrix3d.Identity();
     _coord = Coord3d.GlobalCS;
 }
示例#13
0
 public Ray3d Rotate(Matrix3d m, Point3d p)
 {
     return(new Ray3d(this.Point.Rotate(m, p), this.Direction.Rotate(m)));
 }
示例#14
0
 public Triangle Rotate(Matrix3d m, Point3d p)
 {
     return(new Triangle(_a.Rotate(m, p), _b.Rotate(m, p), _c.Rotate(m, p)));
 }
示例#15
0
 /// <summary>
 /// Rotate coordinate system around rotation axis
 /// </summary>
 /// <param name="axis">Rotation axis</param>
 /// <param name="angle">Rotation angle (degrees, counterclockwise)</param>
 public void RotateDeg(Vector3d axis, double angle)
 {
     _axes = _axes * Matrix3d.RotationMatrix(axis.ConvertToGlobal(), angle * PI / 180).Transpose();
 }
示例#16
0
 public Plane3d Rotate(Matrix3d m, Point3d p)
 {
     return(new Plane3d(this.Point.Rotate(m, p), this.Normal.Rotate(m)));
 }
示例#17
0
 public Sphere Rotate(Matrix3d m)
 {
     return(new Sphere(this.Center.Rotate(m), this.R));
 }
示例#18
0
 public Circle3d Rotate(Matrix3d m, Point3d p)
 {
     return(new Circle3d(this.Center.Rotate(m, p), this.R, this.Normal.Rotate(m)));
 }
示例#19
0
 public Triangle Rotate(Matrix3d m)
 {
     return(new Triangle(_a.Rotate(m), _b.Rotate(m), _c.Rotate(m)));
 }
示例#20
0
 public Circle3d Rotate(Matrix3d m)
 {
     return new Circle3d(this.Center.Rotate(m), this.R, this.Normal.Rotate(m));
 }