Click here to Skip to main content
Click here to Skip to main content
Articles » Multimedia » OpenGL » General » Downloads
 
Add your own
alternative version

StL Data File Viewer

, 5 Mar 2003
A simple StereoLithography data file viewer.
// Point3D.cpp: implementation of the CPoint3D class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Point3D.h"
#include "Vector3D.h"
#include "OneAxis.h"
#include "Line3D.h"
#include "Plane.h"
#include "Matrix33.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CPoint3D::CPoint3D()
{
	SetParam(0,0,0);
	geomType = CPOINT;
}

CPoint3D::CPoint3D(double x, double y, double z)
{
    SetParam(x, y, z);
	geomType = CPOINT;
}

CPoint3D::~CPoint3D()
{

}

void CPoint3D::SetParam(double x, double y, double z)
{
    itsX=x;
    itsY=y;
    itsZ=z;
}

double CPoint3D::GetX() const
{
    return itsX;
}

double CPoint3D::GetY() const
{
    return itsY;
}

double CPoint3D::GetZ() const
{
    return itsZ;
}

CPoint3D CPoint3D::operator+(const CPoint3D &newPoint)
{
	return CPoint3D(itsX+newPoint.GetX(),itsY+newPoint.GetY(),itsZ+newPoint.GetZ());
}

CPoint3D CPoint3D::operator+(const double & inc)
{
	return CPoint3D(itsX+inc,itsY+inc,itsZ+inc);
}

CPoint3D CPoint3D::operator-(const CPoint3D &newPoint)
{
	return CPoint3D(itsX-newPoint.GetX(),itsY-newPoint.GetY(),itsZ-newPoint.GetZ());
}

CPoint3D CPoint3D::operator-(const double & dec)
{
	return CPoint3D(itsX-dec,itsY-dec,itsZ-dec);
}

CPoint3D CPoint3D::operator*(const double scale)
{
	return CPoint3D(itsX*scale,itsY*scale,itsZ*scale);
}

CPoint3D CPoint3D::operator/(const double scale)
{
	return CPoint3D(itsX/scale,itsY/scale,itsZ/scale);
}

void CPoint3D::operator+=(const CPoint3D& P)
{
	(*this) = (*this) + P;
}

void CPoint3D::operator+=(const double& inc)
{
	(*this) = (*this) + inc;
}

void CPoint3D::operator-=(const CPoint3D& P)
{
	(*this) = (*this) - P;
}

void CPoint3D::operator-=(const double& dec)
{
	(*this) = (*this) - dec;
}

void CPoint3D::operator*=(const double scale)
{
	(*this) = (*this) * scale;
}

void CPoint3D::operator/=(const double scale)
{
	(*this) = (*this) / scale;
}

bool CPoint3D::operator == (const CPoint3D& p) const
{
	return (itsX==p.GetX() && itsX==p.GetX() && itsX==p.GetX());
}

CPoint3D::operator CVector3D()
{
	CVector3D V((*this));
	return V;
}

double CPoint3D::Distance(const CPoint3D& P)
{
	
	double sqad, root;
	double x,y,z,tx,ty,tz;
	x=P.GetX(); y=P.GetY(); z=P.GetZ();
	tx = fabs(this->GetX()-x);
	ty = fabs(this->GetY()-y);
	tz = fabs(this->GetZ()-z);
	sqad=((pow(tx,2))+(pow(ty,2))+(pow(tz,2)));
	root=sqrt(sqad);
	
	return root;
}

double CPoint3D::Distance(const CPlane& P)
{
	
	CPoint3D p = P.GetPosition();
	CPoint3D dp = (*this);
	CVector3D V1 = P.GetDirection();
	CVector3D V2(dp);
	double D = V1.Dot(V2) + P.GetConstant();
	return D;
}

void CPoint3D::Translate(const COneAxis& Ax, const double& amt)
{
	CGeometry::Translate(Ax, amt);
}

void CPoint3D::Translate(double dx, double dy, double dz)
{
	itsX+=dx;
	itsY+=dy;
	itsZ+=dz;
}

void CPoint3D::Translate(const CVector3D& VDir)
{
	CVector3D V = VDir;
	itsX+=V.GetX();
	itsY+=V.GetY();
	itsZ+=V.GetZ();
}

void CPoint3D::Translate(const CPoint3D& P1, const CPoint3D& P2)
{
	CVector3D V(P1, P2);
	Translate(V);
}

void CPoint3D::Rotate(const COneAxis& Ax, double ang)
{
	COneAxis ax = Ax;
	CVector3D P1 = ax.GetOrigin();
	CVector3D V = ax.GetDirection();
	V.Normalize();
	CMatrix33 M; CVector3D PV(*this);
	M.SetRotation(V, ang);
	CVector3D RV = M*(PV-P1);
	RV = RV + P1;
	*this = RV.Point();
}

void CPoint3D::Scale(const CPoint3D& P, double fact)
{	
	CPoint3D p = P;
	p = p * (1.0 - fact);
	(*this) = (*this)*(fact);
	(*this) = (*this) + p;
}

void CPoint3D::Mirror(const CPoint3D& P)
{
	CPoint3D p = P;
	(*this) *= -1;
	p *= (2.0);
	(*this) += p;
}

void CPoint3D::Mirror(const COneAxis& Ax)
{
	CPoint3D P1 = Ax.GetPosition();
	CPoint3D P = (*this);
	CVector3D N = Ax.GetDirection();
	CLine3D L(P1, N);
	double D = L.Distance(P);
	CVector3D Q = L.NormalThrough(P) * D * (-2.0);
	CVector3D PV((*this));
	CVector3D R = PV + Q;
	this->SetParam(R.GetX(), R.GetY(), R.GetZ());
}

void CPoint3D::Mirror(const CPlane& Pln)
{
	CPlane pln = Pln;
	CPoint3D P = (*this);
	double D = P.Distance(pln);
	CVector3D N = pln.GetDirection().Unit();
	CVector3D Q = N * D * (-2.0);
	CPoint3D QP = Q.Point();
	(*this) = P + QP;
}

CPoint3D CPoint3D::Origin()
{
	return  CPoint3D(0,0,0);
}

istream &operator>>(istream& input, CPoint3D &p)
{
	input>>p.itsX>>p.itsY>>p.itsZ;
	return input;
}

ostream &operator<<(ostream& output, CPoint3D &p)
{
	output<<p.itsX<<p.itsY<<p.itsZ;
	return output;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

About the Author

Sharjith
Engineer Tata Technologies Ltd
India India
Sharjith is a Mechanical Engineer with strong passion for Automobiles, Aircrafts and Software development.

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 6 Mar 2003
Article Copyright 2003 by Sharjith
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid