Introduction

This article presents two classes and a set of utility functions for computational geometry. C3Point is a 3D counterpart to CPoint and CPolygon encapsulates a set of C3Point's and provides general polygon handling functions. The classes have been mildly optimised for speed. The classes were originally written for use in discretising 2D surfaces into element networks and for calculating properties of the resultant elements. Care must be taken when using some of the functions such as the curvature and area functions to ensure that the results returned by the functions are consistent with your needs and definitions.

The classes make use of a typedef REAL that is either double or float depending on whether USING_DOUBLE or USING_FLOAT has been defined in geometry.h. Obviously using template classes would have been neater, but these classes were developed to get a job done, not to be the epitome of structured programming. A number of conversion functions have been provided:

Share

About the Author

Chris is the Co-founder, Administrator, Architect, Chief Editor and Shameless Hack who wrote and runs The Code Project. He's been programming since 1988 while pretending to be, in various guises, an astrophysicist, mathematician, physicist, hydrologist, geomorphologist, defence intelligence researcher and then, when all that got a bit rough on the nerves, a web developer. He is a Microsoft Visual C++ MVP both globally and for Canada locally.

His programming experience includes C/C++, C#, SQL, MFC, ASP, ASP.NET, and far, far too much FORTRAN. He has worked on PocketPCs, AIX mainframes, Sun workstations, and a CRAY YMP C90 behemoth but finds notebooks take up less desk space.

He dodges, he weaves, and he never gets enough sleep. He is kind to small animals.

Chris was born and bred in Australia but splits his time between Toronto and Melbourne, depending on the weather. For relaxation he is into road cycling, snowboarding, rock climbing, and storm chasing.

Comments and Discussions

That depends on how you define the "centre". Also, negative or positive is only relative. If you're polygon extends over an axis then you may get negative coords. If not then maybe it's a bug. Have you stepped through the code to see what's happening?

Pity. Is there no way you can consider such an implementation by using an average of the vertices and nudging the point by a distance and angle until it falls inside or something? It would be nice to have something support via this class if possible.

I'm playing with 3D triangle-polygons and I would like to have a function that determines if they intersect.
I hoped this class could do that, but when I looked at the code it's only using the x and y in C3Point, so it doesn't.

Has anybody developed code using these classes to determine the point coordinate of the intersection of two line segments, not just whether they intersect? Unless I am missing something, this capability is not implemented. If somebody has done so, I would appreciate a posting.

That's exactly what I was looking for.
I used MacMartin's X-Ray algorithm and some own math code stuff before but your collection is just the best I've seen so far.
Many thanks for that great job you did!

Try one in www.3djockey.com
Recently I have completed code for Constrained Delaunay Triangulation(CDT).
The code posted in www.3djockey.com is one I made quite long time ago.
The code may have bugs but still works quite well for Delaunay Triangulation.
Later when I have time, I will post codes for CDT, which I am using now for my own application.

ysAhn:
How do you do .
I am a gis student from Taiyuan of China.
How I can get the source code of Delaunay Triangulation to learn?
I cann't open the www.3djockey.com web site
Can you email to me . Thanks very much .
My email :zqf2099@sina.com ;

ysahn:Thanks very much for your email .And the web site you afford
is very good. I will go there frequently.
Now I am going to do some map generalization using Constrained Delaunay trianglation ,I want to do some simple examples,but my VC++ is poor ,so I must study some source code to do it ,So I am sincerely expected for your help, thanks very much!