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

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!

The stuff does work. The problem with your code is that the order of points is significant. I believe that you tried to create a square - however you actually created a "bow-tie" shape. Therefore your test point is outside the polygon. Rearranging the order of declaration as follows shows the expected result:

When I first joined our company three and a half years ago one of the first things I wrote was a library (called the Geometric Model) for describing shapes and coordinate frames in 2 or 3 dimensions (for our Pharos acoustic tracking system), modelled loosly on the object hierarchy of OpenGL and Direct3D.

Since it is intended to describe shapes rather than for computational geometry, the focus is different, although the domain is the same.

We planned from day 1 to include 3D rendered displays so you could follow an ROV around the seabed in real-time alongside the more conventional 2D Chart Displays, but apart from a few demos we still haven't released that bit...and even the 2D stuff hasn't been stretched yet (we haven't included a shape editor yet).

Still, it's a pretty interesting area to work in (I never did think I'd find a use for matrices, but I was wrong...)

We used to rely on an X-Window 2D graphics engine written in Fortran that only worked on AIX's and Suns. Finally I spat the dummy and sat down to write a decent 3D version. We needed to view landscapes with overlays of wetness, erosion, vegetation etc and then view the results of rainfall and erosion simulations. It was such a buzz to get it done and be able to do flyovers of the hillslopes in fully shaded 3D.

It was also great proving that my C++ code on my $2,000 PC was faster at running the simulations and displaying the final results than their $15,000 workstations

Chris Maunder wrote:We used to rely on an X-Window 2D graphics engine written in Fortran that only worked on AIX's and Suns. Finally I spat the dummy and sat down to write a decent 3D version. We needed to view landscapes with overlays of wetness, erosion, vegetation etc and then view the results of rainfall and erosion simulations. It was such a buzz to get it done and be able to do flyovers of the hillslopes in fully shaded 3D.

Although I'm anything but a mathematician, I found this stuff fascinating when I first came across it (heck, I even re-learned matrix maths for it )...so I can imagine!

Chris Maunder wrote:It was also great proving that my C++ code on my $2,000 PC was faster at running the simulations and displaying the final results than their $15,000 workstations

Oh I bet it was! I'm sure there were a few red faces when you showed them the final result...