[CPP] Vector 계산 클래스 (v2.0)

simpled 2013.06.23 15:03 조회 수 : 4687

clVectorClass.h


제목 없음.png


저번의 벡터계산 클래스와 달라진것으로는, 3개의 멤버함수(메소드)가 있다.

그 멤버 함수들은 위의 그림과 같이, 각 평면에서 기울어진 각도만큼의 벡터 단위벡터로 표현해주는 행렬식을 갖는다.

"그렇다면 (1, 1, 1)을 표현할 수 있지 않을까?" 해서 한 1시간동안 해봤는데, 뭔가 내 생각과 잘 들어 맞지가 않았다. 
끝내 귀찮아서 슈퍼패스를 시동하였다. 아직 3축에 대한 각도입력 메소드는 무리인것 같다.
그리고 지금 이 시간에도 내게 할당된 시간은 많지 않다.

이것은 큰 프로젝트를 위한 극 소수의 클래스만을 올리는 것이다.
매번 구현하기 정말 귀찮은 것들만 올리는 것이다.

--- 생략 ---

 

// Y(가로)-Z(세로)평면의X축각도를이용해서정규화된벡터를구한다.

// 결과값은클래스내의멤버변수(x, y, z)값으로저장된다.

// 1사분면에서시작되는CCW가디폴트다.(상식기준)

void clVector::Angle_YZp_X_(double Sigma, bool Sigma_is_Degree, bool bCCW_is_True)

{

    double     A[4]={1, 1, 1, 1},

            B[4][4],

            C[4]={0, 0, 0, 0};

 

    if(Sigma_is_Degree)

        Sigma = Sigma * 3.141592 / 180.0 ;

 

    x = y = z = 0.0 ;

 

    if(bCCW_is_True)

    {

        B[0][0]=0;             B[1][0]=0;                 B[2][0]=0;                B[3][0]=0;

        B[0][1]=0;             B[1][1]=cos(Sigma);       B[2][1]=0;                 B[3][1]=0;

        B[0][2]=0;             B[1][2]=0;                 B[2][2]=sin(Sigma);              B[3][2]=0;

        B[0][3]=0;             B[1][3]=0;                 B[2][3]=0;                B[3][3]=1;

    }

    else

    {

        B[0][0]=0;             B[1][0]=0;                 B[2][0]=0;                B[3][0]=0;

        B[0][1]=0;             B[1][1]=cos(Sigma);       B[2][1]=0;                 B[3][1]=0;

        B[0][2]=0;             B[1][2]=0;                 B[2][2]=-sin(Sigma);      B[3][2]=0;

        B[0][3]=0;             B[1][3]=0;                 B[2][3]=0;                B[3][3]=1;

    }

 

    for(int i=0; i<4; i++)

        for (int j=0;j<4;j++)

            C[i]+=A[j]*B[j][i];

 

    x=C[0];

    y=C[1];

    z=C[2];

}

void clVector::Angle_YZp_X_(clVector &vlVector, double Sigma, bool Sigma_is_Degree, bool bCCW_is_True)

{

    double     A[4]={vlVector.x, vlVector.y, vlVector.z, 1},

            B[4][4],

            C[4]={0, 0, 0, 0};

 

    if(Sigma_is_Degree)

        Sigma = Sigma * 3.141592 / 180.0 ;

 

    x = y = z = 0.0 ;

 

    if(bCCW_is_True)

    {

        B[0][0]=1;             B[1][0]=0;                 B[2][0]=0;                B[3][0]=0;

        B[0][1]=0;             B[1][1]=cos(Sigma);       B[2][1]=0;                 B[3][1]=0;

        B[0][2]=0;             B[1][2]=0;                 B[2][2]=sin(Sigma);              B[3][2]=0;

        B[0][3]=0;             B[1][3]=0;                 B[2][3]=0;                B[3][3]=1;

    }

    else

    {

        B[0][0]=1;             B[1][0]=0;                 B[2][0]=0;                B[3][0]=0;

        B[0][1]=0;             B[1][1]=cos(Sigma);       B[2][1]=0;                 B[3][1]=0;

        B[0][2]=0;             B[1][2]=0;                 B[2][2]=-sin(Sigma);      B[3][2]=0;

        B[0][3]=0;             B[1][3]=0;                 B[2][3]=0;                B[3][3]=1;

    }

 

    for(int i=0; i<4; i++)

        for (int j=0;j<4;j++)

            C[i]+=A[j]*B[j][i];

 

    x=C[0];

    y=C[1];

    z=C[2];

}

 

 

// X(가로)-Z(세로)평면의Y축각도를이용해서정규화된벡터를구한다.

// 결과값은클래스내의멤버변수(x, y, z)값으로저장된다.

// 1사분면에서시작되는CCW가디폴트다.(상식기준)

void clVector::Angle_XZp_Y_(double Zeta, bool Zeta_is_Degree, bool bCCW_is_True)

{

    double     A[4]={1, 1, 1, 1},

            B[4][4],

            C[4]={0, 0, 0, 0};

 

    x = y = z = 0.0 ;

 

    if(Zeta_is_Degree)

        Zeta = Zeta * 3.141592 / 180.0 ;

 

    if(bCCW_is_True)

    {

        B[0][0]=cos(Zeta);    B[1][0]=0;                 B[2][0]=0;                B[3][0]=0;

        B[0][1]=0;             B[1][1]=0;                 B[2][1]=0;                B[3][1]=0;

        B[0][2]=0;             B[1][2]=0;                 B[2][2]=sin(Zeta);        B[3][2]=0;

        B[0][3]=0;             B[1][3]=0;                 B[2][3]=0;                B[3][3]=1;

    }

    else

    {

        B[0][0]=cos(Zeta);    B[1][0]=0;                 B[2][0]=0;                B[3][0]=0;

        B[0][1]=0;             B[1][1]=0;                 B[2][1]=0;                B[3][1]=0;

        B[0][2]=0;             B[1][2]=0;                 B[2][2]=-sin(Zeta);       B[3][2]=0;

        B[0][3]=0;             B[1][3]=0;                 B[2][3]=0;                B[3][3]=1;

    }

 

    for(int i=0; i<4; i++)

        for (int j=0;j<4;j++)

            C[i]+=A[j]*B[j][i];

 

    x=C[0];

    y=C[1];

    z=C[2];

}

 

void clVector::Angle_XZp_Y_(clVector &vlVector, double Zeta, bool Zeta_is_Degree, bool bCCW_is_True)

{

    double     A[4]={vlVector.x, vlVector.y, vlVector.z, 1},

            B[4][4],

            C[4]={0, 0, 0, 1};

 

    x = y = z = 0.0 ;

 

    if(Zeta_is_Degree)

        Zeta = Zeta * 3.141592 / 180.0 ;

 

    if(bCCW_is_True)

    {

        B[0][0]=cos(Zeta);    B[1][0]=0;                 B[2][0]=0;                B[3][0]=0;

        B[0][1]=0;             B[1][1]=1;                 B[2][1]=0;                B[3][1]=0;

        B[0][2]=0;             B[1][2]=0;                 B[2][2]=sin(Zeta);        B[3][2]=0;

        B[0][3]=0;             B[1][3]=0;                 B[2][3]=0;                B[3][3]=1;

    }

    else

    {

        B[0][0]=cos(Zeta);    B[1][0]=0;                 B[2][0]=0;                B[3][0]=0;

        B[0][1]=0;             B[1][1]=1;                 B[2][1]=0;                B[3][1]=0;

        B[0][2]=0;             B[1][2]=0;                 B[2][2]=-sin(Zeta);           B[3][2]=0;

        B[0][3]=0;             B[1][3]=0;                 B[2][3]=0;                B[3][3]=1;

    }

 

    for(int i=0; i<4; i++)

        for (int j=0;j<4;j++)

            C[i]+=A[j]*B[j][i];

 

    x=C[0];

    y=C[1];

    z=C[2];

 

}

 

// X(가로)-Y(세로)평면의Z축각도를이용해서정규화된벡터를구한다.

// 결과값은클래스내의멤버변수(x, y, z)값으로저장된다.

// 1사분면에서시작되는CCW가디폴트다.(상식기준)

void clVector::Angle_XYp_Z_(double Omega, bool Omega_is_Degree, bool bCCW_is_True)

{

    double     A[4]={1, 1, 1, 1},

            B[4][4],

            C[4]={0, 0, 0, 1};

 

    x = y = z = 0.0 ;

 

    if(Omega_is_Degree)

        Omega = Omega * (3.141592 / 180.0) ;

 

    if(bCCW_is_True)

    {

        B[0][0]=cos(Omega);   B[1][0]=0;                 B[2][0]=0;                B[3][0]=0;

        B[0][1]=0;             B[1][1]=sin(Omega);     B[2][1]=0;                   B[3][1]=0;

        B[0][2]=0;             B[1][2]=0;                 B[2][2]=0;             B[3][2]=0;

        B[0][3]=0;             B[1][3]=0;                 B[2][3]=0;                B[3][3]=1;

    }

    else

    {

        B[0][0]=cos(Omega);   B[1][0]=0;                 B[2][0]=0;                B[3][0]=0;

        B[0][1]=0;             B[1][1]=-sin(Omega);    B[2][1]=0;                   B[3][1]=0;

        B[0][2]=0;             B[1][2]=0;                 B[2][2]=0;             B[3][2]=0;

        B[0][3]=0;             B[1][3]=0;                 B[2][3]=0;                B[3][3]=1;

    }

 

    for(int i=0; i<4; i++)

        for (int j=0;j<4;j++)

            C[i]+=A[j]*B[j][i];

 

    x=C[0];

    y=C[1];

    z=C[2];

}

void clVector::Angle_XYp_Z_(clVector &vlVector, double Omega, bool Omega_is_Degree, bool bCCW_is_True)

{

    double     A[4]={vlVector.x, vlVector.y, vlVector.z, 1},

            B[4][4],

            C[4]={0, 0, 0, 1};

 

    x = y = z = 0.0 ;

 

    if(Omega_is_Degree)

        Omega = Omega * (3.141592 / 180.0) ;

 

    if(bCCW_is_True)

    {

        B[0][0]=cos(Omega);   B[1][0]=0;                 B[2][0]=0;                B[3][0]=0;

        B[0][1]=0;             B[1][1]=sin(Omega);     B[2][1]=0;                   B[3][1]=0;

        B[0][2]=0;             B[1][2]=0;                 B[2][2]=1;             B[3][2]=0;

        B[0][3]=0;             B[1][3]=0;                 B[2][3]=0;                B[3][3]=1;

    }

    else

    {

        B[0][0]=cos(Omega);   B[1][0]=0;                 B[2][0]=0;                B[3][0]=0;

        B[0][1]=0;             B[1][1]=-sin(Omega);    B[2][1]=0;                   B[3][1]=0;

        B[0][2]=0;             B[1][2]=0;                 B[2][2]=1;             B[3][2]=0;

        B[0][3]=0;             B[1][3]=0;                 B[2][3]=0;                B[3][3]=1;

    }

 

    for(int i=0; i<4; i++)

        for (int j=0;j<4;j++)

            C[i]+=A[j]*B[j][i];

 

    x=C[0];

    y=C[1];

    z=C[2];

}

 

void clVector::Angle_XYZp(double Ro_X, double Ro_Y, double Ro_Z, bool Angle_is_Degree, bool bCCW_is_True)

{

    double     A[4]={1, 1, 1, 1},

            B[4][4],

            C[4][4],

            D[4][4],

            F[4]={0, 0, 0, 0},

            G[4]={0, 0, 0, 0},

            H[4]={0, 0, 0, 0},

            I[4]={0, 0, 0, 0};

 

    x = y = z = 0.0 ;

 

    if(Angle_is_Degree)

    {

        Ro_X = Ro_X * (3.141592 / 180.0) ;

        Ro_Y = Ro_Y * (3.141592 / 180.0) ;

        Ro_Z = Ro_Z * (3.141592 / 180.0) ;

    }

 

    if(bCCW_is_True)

    {

        B[0][0]=1;             B[1][0]=0;                 B[2][0]=0;                B[3][0]=0;

        B[0][1]=0;             B[1][1]=cos(Ro_X);      B[2][1]=0;                   B[3][1]=0;

        B[0][2]=0;             B[1][2]=0;                 B[2][2]=sin(Ro_X);     B[3][2]=0;

        B[0][3]=0;             B[1][3]=0;                 B[2][3]=0;                B[3][3]=1;

 

        C[0][0]=cos(Ro_Y);    C[1][0]=0;                 C[2][0]=0;                C[3][0]=0;

        C[0][1]=0;             C[1][1]=1;              C[2][1]=0;                   C[3][1]=0;

        C[0][2]=0;             C[1][2]=0;                 C[2][2]=sin(Ro_Y);     C[3][2]=0;

        C[0][3]=0;             C[1][3]=0;                 C[2][3]=0;                C[3][3]=1;

 

        D[0][0]=cos(Ro_Z);    D[1][0]=0;                 D[2][0]=0;                D[3][0]=0;

        D[0][1]=0;             D[1][1]=sin(Ro_Z);      D[2][1]=0;                   D[3][1]=0;

        D[0][2]=0;             D[1][2]=0;                 D[2][2]=1;             D[3][2]=0;

        D[0][3]=0;             D[1][3]=0;                 D[2][3]=0;                D[3][3]=1;

    }

    else

    {

        B[0][0]=1;            B[1][0]=0;                 B[2][0]=0;                B[3][0]=0;

        B[0][1]=0;             B[1][1]=cos(Ro_X);      B[2][1]=0;                   B[3][1]=0;

        B[0][2]=0;             B[1][2]=0;                 B[2][2]=-sin(Ro_X);           B[3][2]=0;

        B[0][3]=0;             B[1][3]=0;                 B[2][3]=0;                B[3][3]=1;

 

        C[0][0]=cos(Ro_Y);    C[1][0]=0;                 C[2][0]=0;                C[3][0]=0;

        C[0][1]=0;             C[1][1]=1;              C[2][1]=0;                   C[3][1]=0;

        C[0][2]=0;             C[1][2]=0;                 C[2][2]=-sin(Ro_Y);           C[3][2]=0;

        C[0][3]=0;             C[1][3]=0;                 C[2][3]=0;                C[3][3]=1;

 

        D[0][0]=cos(Ro_Z);    D[1][0]=0;                 D[2][0]=0;                D[3][0]=0;

        D[0][1]=0;             D[1][1]=-sin(Ro_Z);     D[2][1]=0;                   D[3][1]=0;

        D[0][2]=0;             D[1][2]=0;                 D[2][2]=1;             D[3][2]=0;

        D[0][3]=0;             D[1][3]=0;                 D[2][3]=0;                D[3][3]=1;

    }

 

    for(int i=0; i<4; i++)

        for (int j=0;j<4;j++)

            F[i]+=A[j]*B[j][i];

 

    cout <<F[0] <<endl;

    cout <<F[1] <<endl;

    cout <<F[2] <<endl;

 

    for(int i=0; i<4; i++)

        for (int j=0;j<4;j++)

            G[i]+=F[j]*C[j][i];

 

    cout <<G[0] <<endl;

    cout <<G[1] <<endl;

    cout <<G[2] <<endl;

 

    for(int i=0; i<4; i++)

        for (int j=0;j<4;j++)

            H[i]+=G[j]*D[j][i];

 

    cout <<H[0] <<endl;

    cout <<H[1] <<endl;

    cout <<H[2] <<endl;

 

    x=G[0];

    y=G[1];

    z=G[2];

}

번호 제목 글쓴이 날짜 조회 수
29 [CPP] file 입출력 : space data file simpled 2013.06.23 5271
28 [CPP] 1차 방정식을 통한 y값 구하기 simpled 2013.06.23 5790
» [CPP] Vector 계산 클래스 (v2.0) file simpled 2013.06.23 4687
26 [CPP] 자리수 표현 simpled 2013.06.23 5633
25 [CPP] 각도 클래스(+ 아크탄젠트 리턴값 조정) file simpled 2013.06.23 6040
24 [CPP] 벡터 계산 클래스 file simpled 2013.06.23 6103
23 [CPP] file 입출력 simpled 2013.06.23 4977
22 [CPP] 수치해석 : Rectangle Method 구분구적분 (적분 프로그래밍) simpled 2013.06.23 8124
21 [CPP] 분포하중 _ Beam의 SFD, BMD 값 simpled 2013.06.23 6488
20 [CPP] OOP6. CPP Programming :: Virtual Banking system PPT [끝] file 심플디 2013.06.23 6623
19 [CPP] OOP6. CPP Programming :: Virtual Banking system v3.8 file simpled 2013.06.23 5933
18 [CPP] OOP6. CPP Programming :: Virtual Banking system 모듈프로그램들 file simpled 2013.06.23 5257
17 [CPP] OOP6. CPP Programming :: Virtual Banking system v3.7 file simpled 2013.06.23 5967
16 [CPP] OOP6. CPP Programming :: Virtual Banking system v3.6 file simpled 2013.06.23 6304
15 [CPP] OOP6. CPP Programming :: Virtual Banking system v3.5.1 file simpled 2013.06.23 6456
14 [CPP] OOP6. CPP Programming :: Virtual Banking system v3.5 file simpled 2013.06.23 6635
13 [CPP] -----------------------------------절취선----------------------------------- simpled 2013.06.23 5843
12 [CPP] Banksys 휴식 simpled 2013.06.23 6510
11 [CPP] OOP5. CPP Programming :: Virtual Banking system v3.0.2 [Class design3. String Sorting] simpled 2013.06.23 5627
10 [CPP] OOP5. CPP Programming :: Virtual Banking system v3.0.2 [Class design2. File I/O] simpled 2013.06.23 6563