Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

A Matrix-Based 2-D Polygon Clipping Class

, 28 Mar 2003 CDDL
An article on 2-D Polygon Clipping
polyclipdemo.zip
PolyClipDemo
PolyClipDemo.clw
PolyClipDemo.dsw
PolyClipDemo.dsp
PolyClipDemo.plg
PolyClipDemo.opt
res
PolyClipDemoDoc.ico
PolyClipDemo.ico
Toolbar.bmp
polyclipdemo1.zip
PolyClipDemo.aps
PolyClipDemo.clw
PolyClipDemo.dsp
PolyClipDemo.dsw
res
PolyClipDemo.ico
PolyClipDemoDoc.ico
Toolbar.bmp
PolyClipDemo.ncb
PolyClipDemo.opt
PolyClipDemo.plg
polyclipdemoapp.zip
PolyClipDemo.exe
polyclipdemoapp1.zip
PolyClipDemo.exe
// PolygonClip.h: interface for the CPolygonClip class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_POLYGONCLIP_H__3410F6D8_11EC_11D7_8CED_00C0F0172654__INCLUDED_)
#define AFX_POLYGONCLIP_H__3410F6D8_11EC_11D7_8CED_00C0F0172654__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define MAX_NUM_VERTICIES 100	// Maximum number of verticies allowed
#define MaxDetChanges 50        // Max number of determinant changes per line
#define DotSize 3				// Size of the intersection dot
#define PenSize 1				// Size of the pen
		
class CPolygonClip : public CObject  
{
public:
	void Draw(CDC* pDC);
	unsigned int FindArrayMax(unsigned int* pNumChanges);
	bool CalculateIntersections(double* LineX1, double* LineX2, 
								double* LineY1, double* LineY2, 
								double* PolyVertexX, double* PolyVertexY, 
								unsigned int nMaxNumSignChanges);
	unsigned int* CalcSiDeterm(double* LineX1, double* LineY1, 
						   	   double* LineX2, double* LineY2, 
							   double* PolyVertexX, double* PolyVertexY);
	CPolygonClip(unsigned int nNumVerticies, unsigned int nNumLines);
	virtual ~CPolygonClip();

protected:
	double** m_ppdTempIntrY;						// Temp arrays for sorting
	double** m_ppdTempIntrX;
	bool** m_ppbSignChangeTable;					// The sign change table
	unsigned int* m_pnNumSignChanges;				// Number of determinant sign changes per line
	unsigned int* m_pnIntersectsPerLine;			// The number of intersections for a given line
	unsigned int* m_pnUniquesPerLine;				// Holds the number of unique intersections per line
	int** m_ppnDetSignTable;						// Determinant sign table
	double** m_ppdIntersectionY;					// Polygon and line intersection point y coordinates
	double** m_ppdIntersectionX;					// Polygon and line intersection point x coordinates
	
	CPolygonClip(){};								// Default constructor - do not use

private:
	bool m_bIntersectionFlag;
	bool m_bDetermCalcFlag;
	double TurboDeterm(double Elem11, double Elem12, double Elem13,
					   double Elem21, double Elem22, double Elem23);
	unsigned int m_nNumVerticies;			// Number of polygon verticies
	unsigned int m_nNumLines;				// Number of lines

	// Temp arrays to hold spanning verticies 
	double dTempVertex[MAX_NUM_VERTICIES][MAX_NUM_VERTICIES];
	double dTempVertexPrior[MAX_NUM_VERTICIES][MAX_NUM_VERTICIES];
	double dVertex[MAX_NUM_VERTICIES][MAX_NUM_VERTICIES];
	double dVertexPrior[MAX_NUM_VERTICIES][MAX_NUM_VERTICIES];
};

#endif // !defined(AFX_POLYGONCLIP_H__3410F6D8_11EC_11D7_8CED_00C0F0172654__INCLUDED_)

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 Common Development and Distribution License (CDDL)

Share

About the Author

73Zeppelin
Other
Anonymous Proxy Anonymous Proxy
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.1411023.1 | Last Updated 29 Mar 2003
Article Copyright 2003 by 73Zeppelin
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid