예제 #1
0
        public void DirToDxDyDz(ref ChVector Vx,
                                ref ChVector Vy,
                                ref ChVector Vz,
                                ChVector Vsingular)
        {
            // set Vx.
            if (this.IsNull())
            {
                Vx = new ChVector(1, 0, 0);
            }
            else
            {
                Vx = this.GetNormalized();
            }

            Vz.Cross(Vx, Vsingular);
            double zlen = Vz.Length();

            // if near singularity, change the singularity reference vector.
            if (zlen < 0.0001)
            {
                ChVector mVsingular = new ChVector(0, 0, 0);

                if (Mathfx.Abs(Vsingular.x) < 0.9)
                {
                    mVsingular = new ChVector(1, 0, 0);
                }
                else if (Mathfx.Abs(Vsingular.y) < 0.9)
                {
                    mVsingular = new ChVector(0, 1, 0);
                }
                else if (Mathfx.Abs(Vsingular.z) < 0.9)
                {
                    mVsingular = new ChVector(0, 0, 1);
                }

                Vz.Cross(Vx, mVsingular);
                zlen = Vz.Length();  // now should be nonzero length.
            }

            // normalize Vz.
            Vz.Scale(1 / zlen);

            // compute Vy.
            Vy.Cross(Vz, Vx);
        }