//******************************************** // Operator - //******************************************** CVector3d operator-(CVector3d& u, CVector3d& v) { CVector3d w; w.Set(u.x()-v.x(),u.y()-v.y(),u.z()-v.z()); return w; }
//******************************************** // Inner //******************************************** void CVector3d::Inner(CVector3d& vector) { double x = (double)m_y*(double)vector.z()-(double)m_z*(double)vector.y(); double y = (double)m_z*(double)vector.x()-(double)m_x*(double)vector.z(); double z = (double)m_x*(double)vector.y()-(double)m_y*(double)vector.x(); Set((float)x,(float)y,(float)z); }
//******************************************** // Operator ^ //******************************************** CVector3d operator^(CVector3d& u, CVector3d& v) { // w = u ^ v CVector3d w; w.Set(u.y()*v.z()-u.z()*v.y(), u.z()*v.x()-u.x()*v.z(), u.x()*v.y()-u.y()*v.x()); return w; }
//******************************************** // Collinear //******************************************** int CVector3d::Collinear(CVector3d &vector) { float x = vector.x() / m_x; float y = vector.y() / m_y; float z = vector.z() / m_z; return ((x == y) && (y == z)); }
//******************************************** // Cross //******************************************** CVector3d CVector3d::Cross(const CVector3d& v) const { return CVector3d(y() * v.z() - z() * v.y(), z() * v.x() - x() * v.z(), x() * v.y() - y() * v.x()); }
//******************************************** // IsCollinear //******************************************** int CVector3d::IsCollinear(CVector3d &vector) const { double x = vector.x() / vec[0]; double y = vector.y() / vec[1]; double z = vector.z() / vec[2]; return ((x == y) && (y == z)); }
/** Compute the distance from a point pta * to the line defined by the 2 points ptb and ptc * The two points ptb and ptc defining the baseline also define * its positive direction from point ptb toward point ptc. * It is assumed that the 3 points pta, ptb, ptc define a plane * not far from the X-Y plane. * The sign of d is positive if the point pta * is left of the line ptb=>ptc * The sign of d is negative if pta is right of the line. * * @author Robert Laine alias Sailcuter */ real Distance3d(const CPoint3d &pta, const CPoint3d &ptb, const CPoint3d &ptc) { real d; CVector3d Va = CVector3d( pta - ptb ); CVector3d Vb = CVector3d( ptc - ptb).normalized(); CVector3d Vd = CVector3d::crossProduct(Vb, Va); d = Vd.length(); if ( Vd.z() < 0 ) d = -d; // return d; }
//******************************************** // Rotate this vector around pAround by angle // by Haeyoung Lee //******************************************** CVector3d CVector3d::Rotate(double angle, CVector3d Around) { double f1, f2, f3; CVector3d t1, t2; f1 = (double)cos((double)angle); f2 = (double)sin((double)angle); t1 = Projection(&Around); t2 = Around.Cross(this); f3 = Dot(Around); return CVector3d((double)(f1*t1.x()+f2*t2.x()+f3*Around.x()), (double)(f1*t1.y()+f2*t2.y()+f3*Around.y()), (double)(f1*t1.z()+f2*t2.z()+f3*Around.z())); }
//******************************************** // Set //******************************************** void CVector3d::Set(CVector3d &vector) { Set(vector.x(),vector.y(),vector.z()); }