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

Basic Curves And Surfaces Modeler

, 18 Apr 2012
A basic demo of modeling curves and surfaces in OpenGL.
cadsurfexe.zip
CadSurfexe
CadSurf.exe
VKGeom.dll
VKGraphic.dll
cadsurf_demo.zip
cadsurf_src.zip
CadSurf_src
VKernel
VKGraphic
VKGraphic.dsp
VKGraphic.dsw
VKGraphic.plg
VKGeom
VKGeom.dsp
VKGeom.dsw
cadsurf
CadSurf.clw
CadSurf.dsp
cadsurf.dsw
Thumbs.db
res
bmp00001.bmp
cadsurf.ico
CADSURFDOC.ICO
new_splash.bmp
new_splash.PNG
new_splash_small.bmp
tb_geom.bmp
Thumbs.db
toolbar.bmp
toolbar1.bmp
untitled.bmp
XPStyle.manifest
CadSurf_VS2008.zip
CadSurf
cadsurf
CadSurf.suo
res
bmp00001.bmp
cadsurf.ico
CADSURFDOC.ICO
new_splash.bmp
new_splash.PNG
new_splash_small.bmp
tb_geom.bmp
Thumbs.db
toolbar.bmp
toolbar1.bmp
untitled.bmp
VKernel
VKGeom
VKGraphic
VKGraphic.plg
// Line2D.cpp: implementation of the CLine2D class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"

#include "Line2D.h"
#include "MMath.h"

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

CLine2D::CLine2D()
{
	cType = LINE2D;
}

CLine2D::CLine2D(const CPoint2D& sP, const CPoint2D& eP) : startPoint(sP), endPoint(eP)
{
	COneAxis2D Ax(sP, CVector2D(sP, eP));
	itsLocation = Ax;
	cType = LINE2D;
}

CLine2D::CLine2D(const CPoint2D& P, const CVector2D& V)
{
	CVector2D dir = V;
	CVector2D sv = dir.Unit() * -INFINITY;
	CVector2D ev = dir.Unit() * INFINITY;
	sv.SetParam(sv.GetX()+P.GetX(), sv.GetY()+P.GetY());
	ev.SetParam(ev.GetX()+P.GetX(), ev.GetY()+P.GetY());

	startPoint.SetParam(sv.GetX(), sv.GetY());
	endPoint.SetParam(ev.GetX(), ev.GetY());

	COneAxis2D Ax(startPoint, CVector2D(sv, ev));
	itsLocation = Ax;

	cType = LINE2D;
}

CLine2D::~CLine2D()
{
}

void CLine2D::Reverse()
{
	CPoint2D tPnt = startPoint;
	startPoint = endPoint;
	endPoint = tPnt;
}

CPoint2D CLine2D::PointAtPara(const double& par)
{
	double u;
	if (par < 0)
		u = 0;
	else if(par > 1)
		u = 1;
	else
		u = par;

	CPoint2D aPnt;
	aPnt = startPoint + (endPoint - startPoint) * u;
	return aPnt;
}

bool CLine2D::IsClosed() const
{
	return false;
}

bool CLine2D::operator == (const CLine2D& L) const
{
	bool eq = (startPoint == L.StartPoint() && endPoint == L.EndPoint());
	return eq;
}

void CLine2D::operator = (const CLine2D& L)
{
	itsLocation = L.GetLocation();
	startPoint = L.StartPoint();
	endPoint = L.EndPoint();
}

CVector2D CLine2D::Direction() const
{
	CVector2D sv(startPoint);
	CVector2D ev(endPoint);
	CVector2D dir(sv, ev);
	return dir.Unit();
}

CVector2D CLine2D::NormalThrough(const CPoint2D& P)
{
	CPoint2D P3 = P;
	CPoint2D P1 = startPoint;
	double D = Distance(P3);
	D = 1/D;
	CVector2D N1 = Direction();
	CVector2D PV = CVector2D(P3 - P1);
	double dt = PV.Dot(N1);
	CVector2D N = (CVector2D(P3 - P1) - N1*(dt)) * D;
	return N;
}

double CLine2D::Distance(const CPoint2D& P)
{
	CPoint2D P3 = P;
	CPoint2D P1 = startPoint;
	CPoint2D P2 = endPoint;
	double x1, y1, x2, y2, x3, y3;
	x1 = P1.GetX(); y1 = P1.GetY();
	x2 = P2.GetX(); y2 = P2.GetY();
	x3 = P3.GetX(); y3 = P3.GetY();
	double L = P1.Distance(P2);
	L = 1/L;
	double D = L * (sqrt(pow((x3-x1)*(y2-y1)-(y3-y1)*(x2-x1),2)));
	return D;
}

void CLine2D::Translate(const COneAxis2D& Ax, const double& amt)
{
	CGeometry2D::Translate(Ax, amt);
}

void CLine2D::Translate(double dx, double dy)
{
	startPoint.Translate(dx,dy);
	endPoint.Translate(dx,dy);
}

void CLine2D::Translate(const CVector2D& V)
{
	startPoint.Translate(V);
	endPoint.Translate(V);
}

CCurve2D* CLine2D::Copy() const
{
	CLine2D* L = new CLine2D(startPoint, endPoint);
	return L;
}

void CLine2D::Translate(const CPoint2D& P1, const CPoint2D& P2)
{
	startPoint.Translate(P1, P2);
	endPoint.Translate(P1, P2);
}

void CLine2D::Rotate(const CPoint2D& Ax, double ang)
{
	startPoint.Rotate(Ax, ang);
	endPoint.Rotate(Ax, ang);
}

void CLine2D::Scale(const CPoint2D& P, double fact)
{
	startPoint.Scale(P, fact);
	endPoint.Scale(P, fact);
}

void CLine2D::Mirror(const CPoint2D& P)
{
	startPoint.Mirror(P);
	endPoint.Mirror(P);
}

void CLine2D::Mirror(const COneAxis2D& Ax)
{
	startPoint.Mirror(Ax);
	endPoint.Mirror(Ax);
}

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 Code Project Open License (CPOL)

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
Web03 | 2.8.140718.1 | Last Updated 18 Apr 2012
Article Copyright 2003 by Sharjith
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid