当前位置: 首页>>代码示例>>C#>>正文


C# Vector.Length方法代码示例

本文整理汇总了C#中Vector.Length方法的典型用法代码示例。如果您正苦于以下问题:C# Vector.Length方法的具体用法?C# Vector.Length怎么用?C# Vector.Length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector的用法示例。


在下文中一共展示了Vector.Length方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DistanceToGround

        public static float DistanceToGround(Vector observer, List<Quad> quads)
        {
            float closestGround = float.MaxValue;
            Vector down = new Vector(0F, -1F, 0F);

            foreach (Quad quad in quads)
            {
                Vector ab = quad.vertices[0].Difference(quad.vertices[1]);
                Vector ac = quad.vertices[0].Difference(quad.vertices[2]);
                Vector N = ab.CrossProduct(ac);
                float d = -N.DotProduct(quad.vertices[0]);
                float t = -(d + observer.DotProduct(N)) / (N.DotProduct(down));
                if (t > 0)
                    t *= -1F;
                float distance = (float)Math.Abs(t * down.Length());

                Vector projection = observer.Difference(down.GetScaledVector(t));

                if (!PointIsInQuad(projection, quad))
                    continue;

                if (distance < closestGround)
                    closestGround = distance;
            }

            return closestGround;
        }
开发者ID:NickStupich,项目名称:game-version1,代码行数:27,代码来源:MovingTools.cs

示例2: TestLength

        public void TestLength()
        {
            Vector v1 = new Vector( 0.0f, 0.0f, 1.0f );
            Vector v2 = new Vector( 0.0f, 2.0f, 0.0f );

            Assert.AreEqual( 1.0, v1.Length() );
            Assert.AreEqual( 2.0f, v2.Length() );
        }
开发者ID:BradleyMarie,项目名称:IrisSharp,代码行数:8,代码来源:VectorTest.cs

示例3: InfinitePlane

        public InfinitePlane( Point P0, Vector Normal )
        {
            if ( Normal.Length() == 0.0f )
            {
                throw new ArgumentException( "Normal must be of length >= 0.0" );
            }

            this.P0 = P0;
            this.Normal = Normal;
        }
开发者ID:BradleyMarie,项目名称:IrisSharp,代码行数:10,代码来源:InfinitePlane.cs

示例4: ConstantNormal

        public ConstantNormal( NormalType Type, Vector Vector )
            : base(Type)
        {
            if ( Vector.Length() == 0.0f )
            {
                throw new ArgumentException( "Vector.Length() == 0.0f" );
            }

            this.Vector = Vector;
        }
开发者ID:BradleyMarie,项目名称:IrisSharp,代码行数:10,代码来源:ConstantNormal.cs

示例5: FFTReOrder

 /// <summary>
 /// Переворачивает входной массив длины 2^i в соответствии с некоторым правилом.
 /// Например, при порядке 01234567 получим 04261537
 /// </summary>
 /// <param name="Data">Массив комплексных чисел</param>
 public static void FFTReOrder(Vector<Complex> Data)
 {
     ulong N = Data.Length();
     Complex temp;
     if (N <= 2) return;
     ulong r = 0;
     for (ulong x = 1; x < N; x++)
     {
         r = rev_next(r, N);
         if (r > x) { temp = Data[x]; Data[x] = Data[r]; Data[r] = temp; }
     }
 }
开发者ID:glebmillenium,项目名称:projects,代码行数:17,代码来源:Transformation.cs

示例6: FFT_L

        /// <summary>
        /// Глупый (прямой) алгоритм вычисления ДПФ. 
        /// Коэффициенты вычисляются прямо по формулам без какой-либо отпимизации.
        /// </summary>
        /// <param name="Data"> Входной массив длины Len = 2^k </param>
        /// <param name="Dir"> Переменная равная 1 или -1 для хранения данных о том, прямое или обратное ДПФ мы вычисляем </param>
        /// <returns></returns>
        public static Vector<Complex> FFT_L(Vector<Complex> Data, int Dir)
        {
            ulong Len = Data.Length();
            Vector<Complex> NewData = new Vector<Complex>(Len);

            //Инициализируем переменные для вычисления корней
            Complex PRoot, Root;

            ulong k;

            for (ulong i = 0; i < Len; i++)
            {

                PRoot = new Complex(1.0, 0.0);

                Root = new Complex(); //w_n = w
                Root.i = Math.Sin(2 * Math.PI / Len);
                Root.r = Math.Cos(2 * Math.PI / Len);

                Complex KRoot = new Complex();
                KRoot = Root;

                k = 1;
                //вычисляем w^k
                while (k < i)
                {
                    KRoot *= Root;
                    k++;
                }

                //Инициализируем ai нового вектора
                Complex a = new Complex(0, 0);
                for (ulong j = 0; j < Len; j++)
                {
                    if (j == 0)
                    {
                        a += Data[j];
                    }
                    else
                    {
                        if (Dir == 1) a += Data[j] * PRoot;
                        else a += Data[j] * (new Complex(PRoot.r / (PRoot.r* PRoot.r + PRoot.i* PRoot.i), -PRoot.i / (PRoot.r * PRoot.r + PRoot.i * PRoot.i)));
                    }
                    if (i == 0) continue;
                    //вычисялем w^kj
                    PRoot *= KRoot;
                }
                NewData[i] = a;
            }
            return NewData;
        }
开发者ID:glebmillenium,项目名称:projects,代码行数:58,代码来源:Transformation.cs

示例7: Main

        static void Main(string[] args)
        {
            Complex a1 = new Complex(2, 5);
            Complex a2 = new Complex(4, 3);
            Complex a3 = new Complex(1, 4);
            Complex a4 = new Complex(2, 6);
            Complex a5 = new Complex(2, 8);
            Complex a6 = new Complex(7, 3);
            Complex a7 = new Complex(4, 5);
            Complex a8 = new Complex(1, 3);
            Complex[] Vec = { a1, a2, a3, a4, a5, a6, a7, a8 };
            Vector<Complex> Data = new Vector<Complex>(Vec);

            ulong Len = Data.Length();
            int Dir = 1;
            Vector<Complex> NewData = Transformation.FFT_L(Data, Dir);
            Console.WriteLine(NewData.ToString());
            Console.WriteLine();

            Transformation.FFTReOrder(Data);
            Transformation.FFT_T(Data, 0, Len, Dir);

            Console.WriteLine(Data.ToString());
            Console.WriteLine();

            Dir = -1;
            NewData = Transformation.FFT_L(Data, Dir);

            Transformation.FFTReOrder(Data);
            Transformation.FFT_T(Data, 0, Len, Dir);

            if (Dir == -1) {
                for (ulong i = 0; i < Len; i++)
                {
                    Data[i].i /= Len;
                    Data[i].r /= Len;

                    NewData[i].i /= Len;
                    NewData[i].r /= Len;
                }
            }

            Console.WriteLine(NewData.ToString());
            Console.WriteLine();

            Console.WriteLine(Data.ToString());

            Console.ReadKey();
        }
开发者ID:glebmillenium,项目名称:projects,代码行数:49,代码来源:Program.cs

示例8: Angle

 public float Angle(Vector other)
 {
     return (float)Math.Acos(Scalar(other) / (Length() * other.Length()));
 }
开发者ID:QuantumPhi,项目名称:SpaceDefense,代码行数:4,代码来源:Vector.cs

示例9: GetAngleDegBetween

 public static float GetAngleDegBetween(Vector a, Vector b)
 {
     return (float)(Math.Acos(Dot(a, b) / (a.Length() * b.Length())) * RadToDeg);
 }
开发者ID:egoquat,项目名称:SolutionTest_CSharp,代码行数:4,代码来源:Program.cs

示例10: RenderScene

	/**
	 * RenderScene
	 */
	public void RenderScene(Canvas canvas, int width, int section, int nsections)
	{
		Vector view = camera.GetViewDir();
		Vector up = camera.GetOrthoUp();
		Vector plane = new Vector();
		Vector horIncr = new Vector();
		Vector vertIncr = new Vector();
		double ylen = camera.GetFocalDist() * (double)Math.Tan(0.5f * camera.GetFOV());
		double xlen = ylen * canvas.GetWidth() / canvas.GetHeight();
		Point upleft = new Point();
		Point upright = new Point();
		Point lowleft = new Point();
		Point basepoint = new Point();
		Point current;
		Ray eyeRay = new Ray();
		int ypixel, xpixel;

		RayID = 1;
		plane.Cross(view, up);
		view.Scale(camera.GetFocalDist());
		up.Scale(ylen);
		plane.Scale(-xlen);
		upleft.FindCorner(view, up, plane, camera.GetPosition());
		plane.Negate();
		upright.FindCorner(view, up, plane, camera.GetPosition());
		up.Negate();
		plane.Negate();
		lowleft.FindCorner(view, up, plane, camera.GetPosition());
		horIncr.Sub(upright, upleft);
		horIncr.Scale(horIncr.Length() / ((double)canvas.GetWidth()));
		vertIncr.Sub(lowleft, upleft);
		vertIncr.Scale(vertIncr.Length() / ((double)canvas.GetHeight()));
		basepoint.Set(upleft.GetX() + 0.5f * (horIncr.GetX() + vertIncr.GetX()), upleft.GetY() + 0.5f * (horIncr.GetY() + vertIncr.GetY()),
			upleft.GetZ() + 0.5f * (horIncr.GetZ() + vertIncr.GetZ()));
		eyeRay.SetOrigin(camera.GetPosition());

		int xstart = section * width / nsections;
		int xend = xstart + width / nsections;

		Console.WriteLine("+" + xstart + " to " + (xend - 1) + " by " + canvas.GetHeight());

		for(ypixel = 0; ypixel < canvas.GetHeight(); ypixel++)
		{
			current = new Point(basepoint);
			for(xpixel = 0; xpixel < canvas.GetWidth(); xpixel++)
			{
				if(xpixel >= xstart && xpixel < xend)
				{
					Color color = new Color(0.0f, 0.0f, 0.0f);
					eyeRay.GetDirection().Sub(current, eyeRay.GetOrigin());
					eyeRay.GetDirection().Normalize();
					eyeRay.SetID(RayID);
					this.RayID = this.RayID + 1;
					Shade(octree, eyeRay, color, 1.0f, 0, 0);
					canvas.Write(Brightness, xpixel, ypixel, color);
				}
				current.Add(horIncr);
			}
			basepoint.Add(vertIncr);
		}
		Console.WriteLine("-" + xstart + " to " + (xend - 1) + " by " + canvas.GetHeight());
	}
开发者ID:lewurm,项目名称:benchmarker,代码行数:65,代码来源:Scene.cs

示例11: TriangleObj

	/**
	 * TriangleObj
	 *
	 * @param objmaterial
	 * @param newobjID
	 * @param numverts
	 * @param vertices
	 * @param MaxX
	 * @param MinX
	 * @param MaxY
	 * @param MinY
	 * @param MaxZ
	 * @param MinZ
	 */
	public TriangleObj(Material objmaterial, int newobjID, int numverts, Point[] vertices, Point max, Point min)
		: base(objmaterial, newobjID, numverts, vertices, max, min)
	{
		Vector[] temp = new Vector[3];
		for(int i = 0; i < 3; i++)
		{
			temp[i] = new Vector(vertices[i].GetX(), vertices[i].GetY(), vertices[i].GetZ());
		}

		S1 = new Vector();
		S2 = new Vector();
		S3 = new Vector();
		S1.Cross(temp[1], temp[2]);
		S2.Cross(temp[2], temp[0]);
		S3.Cross(temp[0], temp[1]);
		double delta = 1.0f / S1.Dot(temp[0]);
		S1.Scale(delta * S1.Length());
		S2.Scale(delta * S2.Length());
		S3.Scale(delta * S3.Length());
	}
开发者ID:lewurm,项目名称:benchmarker,代码行数:34,代码来源:TriangleObj.cs


注:本文中的Vector.Length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。