C# 두 벡터의 내적 계산

Unity3D/C# 2013. 6. 26. 20:52
반응형

두 백터 (1,0), (0,1) 이 있다고 할 떄, 아래의 백터 특성으로~ 두 백터 간의 내적을 구할수 있다.



C#으로 구현해 보면 


using System;
using System.Collections.Generic;

namespace Test_01
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Console.WriteLine ("Hello World!");
            new Test ();
        }
    }

    class Test{

        public struct Vector2{
            public double x, y;
        }

        public Test(){
        
            Vector2 v1;
            Vector2 v2;

            v1.x = 1;
            v1.y = 0;

            v2.x = 0;
            v2.y = 1;

            double leftExpression = v1.x * v2.x + v1.y * v2.y;
            double theta = leftExpression /
                (Math.Sqrt (Math.Pow( v1.x, 2) + Math.Pow( v1.y, 2) * Math.Sqrt( Math.Pow(v2.x, 2) + Math.Pow(v2.y, 2))));
            double innerD = (double)Math.Acos (theta) * (180 / Math.PI);

            Console.WriteLine (innerD);
            

        }
    }
}



결과 값 90이 나옵니다.

반응형
: