2019-10-24 24일차 벡터

Console Programming/C# Console 2019. 10. 24. 18:51

벡터의 크기 구하기

벡터의 뺄셈

단위벡터 구하기

 

Program.cs

namespace Console1024
{
    class Program
    {

        static void Main(string[] args)
        {
            new App();
        }


    }
}

App.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Console1024
{
    public class App
    {
        public App()
        {      
            double result = GetDistance(vectorA, vectorB);

            var c = GetVectorBminusA(vectorB, vectorA);
            Console.WriteLine($"{c},{c.x},{c.y}");

            Console.WriteLine("{0:F3}",result);

            var normalizedVectorC = GetNormalize(c);

            Console.WriteLine($"{normalizedVectorC}, {normalizedVectorC.x}, {normalizedVectorC.y}");


            //double result2 = GetDistance(arrVector1, arrrVector2);

            //Console.WriteLine("{0:F3}",result2);
            

        }
        public Vector2 GetNormalize(Vector2 vector)
        {
            double length = Math.Sqrt(Math.Pow(vector.x, 2) + Math.Pow(vector.y, 2));
            double x = vector.x / length;
            double y = vector.y / length;
            Vector2 newVector = new Vector2(x, y);

            return newVector;

        }
        public Vector2 GetVectorBminusA(Vector2 vectorB, Vector2 vectorA)
        {
            double a = vectorB.x - vectorA.x;
            double b = vectorB.y - vectorA.y;
            Vector2 c = new Vector2(a, b);
            return c;
        }
        public double GetDistance(Vector2 vectorA, Vector2 vectorB)
        {
            double a = vectorA.x - vectorB.x;
            double b = vectorA.y - vectorB.y;

            double distance = Math.Sqrt(a * a + b * b);

            return distance;
        }







        public double GetDistance(int[] vectorA, int[] vectorB)
        {
            int a = vectorA[0] - vectorB[0];
            int b = vectorA[1] - vectorB[1];

            double distance = Math.Sqrt(a * a + b * b);

            return distance;            
        }

    }
}

Vector2.cs

namespace Console1024
{
    public class Vector2
    {
        public double x;
        public double y;
        public Vector2(double x, double y)
        {
            this.x = x;
            this.y = y;
            
        }
    }
}

 

 

: