AxisVector.cpp
#include "AxisVector.h"
#include "Matrix.h"
using namespace Robotics;
using namespace System;
using namespace System::Diagnostics;
/// ๆๅใใ็ๆใใ [ Constructor ]
AxisVector::AxisVector( double x, double y, double z ) :
Vector( DefaultDimension )
{
this[ 1 ] = x;
this[ 2 ] = y;
this[ 3 ] = z;
Debug::Assert( IsUnitVector( Precision ), "ๅไฝใใฏใใซใงใใ" );
}
/// ใใฏใใซใใ็ๆใใ(ๆฌกๅ
ๆฐใ็ขบ่ชใใใใใซใใชใผใใผใฉใคใใใฆใใ) [ Constructor ]
AxisVector::AxisVector( Vector^ vector ) :
Vector( vector )
{
Debug::Assert( Dimension == DefaultDimension, "ๆขๅฎใฎๆฌกๅ
ใงใใ" );
Debug::Assert( IsUnitVector( Precision ), "ๅไฝใใฏใใซใงใใ" );
}
/// XMLใใ็ๆใใ [ Constructor ]
AxisVector::AxisVector( System::Xml::XmlElement^ element ) :
Vector( DefaultDimension )
{
Debug::Assert( element != nullptr, "ๆๅนใช่ฆ็ด ใงใใ" );
// ๅฑๆงใใ่จญๅฎใใ
this[ 1 ] = Double::Parse( element->GetAttribute( "x" ) );
this[ 2 ] = Double::Parse( element->GetAttribute( "y" ) );
this[ 3 ] = Double::Parse( element->GetAttribute( "z" ) );
Debug::Assert( IsUnitVector( Precision ), "ๅไฝใใฏใใซใงใใ" );
}
/// ็ๆใใ
AxisVector^ AxisVector::Create( System::Xml::XmlElement^ element )
{
Xml::XmlElement^ node = element[ "axisVector" ];
if( node == nullptr )
{
// ่ฆ็ด ใๅญๅจใใชใใชใใฐใใใซใ่ฟใ
return nullptr;
}
// ็ๆใใฆ่ฟใ
return gcnew AxisVector( node );
}
/// ้ใใฏใใซใ่ฟใ [ Operator Overloading ]
AxisVector^ AxisVector::operator-()
{
return gcnew AxisVector( -1.0 * this );
/// @note ่กจ่จใ้ฃ่งฃใซใชใใใใๅบๆฌใฏใฉในใใชใผใใผใฉใคใใใฆใใชใ
}
/// ็ฉ * (่ปธใใฏใใซใๅ่ปขใใใ) [ Operator Overloading ]
AxisVector^ AxisVector::operator*( Matrix^ rotationMatrix, AxisVector^ axisVector )
{
// ใใฏใใซใซใญใฃในใใใ
Vector^ vector = safe_cast< Vector^ >( axisVector );
// ... ่กๅใจใใฏใใซใฎ็ฉใจใใฆๆฑใใ
AxisVector^ result = gcnew AxisVector( rotationMatrix * vector );
return result;
}
/// ใคใณในใฟใณในใฎ่ชฌๆใๆๅญๅใง่ฟใ
String^ AxisVector::ToString()
{
return String::Format( "{0:0.000} {1:0.000} {2:0.000}", X, Y, Z );
}