Fractrace.Geometry.VecRotation.getTransform C# (CSharp) 메소드

getTransform() 공개 메소드

calculates the effect of this rotation on a point the new point is given by=q * P1 * q' this version does not alter P1 but returns the result. for theory see: http://www.martinb.com/maths/algebra/realNormedAlgebra/quaternions/transforms/index.htm
public getTransform ( Fractrace.Geometry.Vec3 p1 ) : Fractrace.Geometry.Vec3
p1 Fractrace.Geometry.Vec3
리턴 Fractrace.Geometry.Vec3
        public Vec3 getTransform(Vec3 p1)
        {
            double wh = Angle;
            double xh = X;
            double yh = Y;
            double zh = Z;
            double s = Math.Sin(Angle / 2);
            xh = X * s;
            yh = Y * s;
            zh = Z * s;
            wh = Math.Cos(Angle / 2);
            Vec3 p2 = new Vec3(0, 0, 0);
            p2.X = (double)(wh * wh * p1.X + 2 * yh * wh * p1.Z - 2 * zh * wh * p1.Y + xh * xh * p1.X + 2 * yh * xh * p1.Y + 2 * zh * xh * p1.Z - zh * zh * p1.X - yh * yh * p1.X);
            p2.Y = (double)(2 * xh * yh * p1.X + yh * yh * p1.Y + 2 * zh * yh * p1.Z + 2 * wh * zh * p1.X - zh * zh * p1.Y + wh * wh * p1.Y - 2 * xh * wh * p1.Z - xh * xh * p1.Y);
            p2.Z = (double)(2 * xh * zh * p1.X + 2 * yh * zh * p1.Y + zh * zh * p1.Z - 2 * wh * yh * p1.X - yh * yh * p1.Z + 2 * wh * xh * p1.Y - xh * xh * p1.Z + wh * wh * p1.Z);
            return p2;
        }

Usage Example

예제 #1
0
        /// <summary>
        /// Benutzung der Vektorrotation.
        /// </summary>
        /// <param name="ar"></param>
        /// <param name="ai"></param>
        /// <param name="aj"></param>
        /// <param name="ak"></param>
        /// <param name="br"></param>
        /// <param name="bi"></param>
        /// <param name="bj"></param>
        /// <param name="bk"></param>
        /// <param name="zkl"></param>
        /// <param name="invers"></param>
        /// <returns></returns>
        long H7(double ar, double ai, double aj, double ak, double br, double bi, double bj, double bk, long zkl, bool invers)
        {
            double xx, yy, zz;
            long tw;
            int n;
            ai = 0; aj = 0; ak = 0;

            double x = 1, y = 0, z = 0;

            xx = x * x; yy = y * y; zz = z * z;
            tw = 0;
            double r = Math.Sqrt(xx + yy + zz);
            VecRotation vecRot = new VecRotation();

            x = 1; // Um den Startwinkel eindeutig zu definieren.
            for (n = 1; n < zkl; n++)
            {

                double theta = Math.Atan2(Math.Sqrt(xx + yy), z);
                double phi = Math.Atan2(y, x);

                vecRot.X = y;
                vecRot.Y = x;
                vecRot.Z = z;
                vecRot.Angle = theta;
                //   vecRot.angle = 0.03;
                vecRot.X = x;
                vecRot.Y = z;
                vecRot.Z = y;
                vecRot.Angle = phi;

                /*
                vecRot.x = 0.4;
                vecRot.y = 0.2;
                vecRot.z = 0.8;
                vecRot.angle = phi;
                */
                y += bj;
                x += bi;
                z += br;
                Vec3 pos = new Vec3(x, y, z);
                Vec3 newPos = vecRot.getTransform(pos);

                x = newPos.X;
                y = newPos.Y;
                z = newPos.Z;

                xx = x * x; yy = y * y; zz = z * z;// aak = ak * ak;
                r = Math.Sqrt(xx + yy + zz);

                x *= r;
                y *= r;
                z *= r;
                if (r > gr)
                {
                    tw = n; break;
                }

            }

            if (invers)
            {
                if (tw == 0)
                    tw = 1;
                else
                    tw = 0;
            }
            return (tw);
        }