Triangular geometry
Triangular geometry
Hallo everybody!
I need your help in the following problem:
I want to write a C++ programm for a 3D triangular geometry.It's my first time dealing with C++ and i find some difficulties. I found a code for a 2d triangular geometry so i need to make some changes for the 3d case. Can anybody help me with this??? I'm sending you the code i found.D
The code is:
/* ----------------------------------------------------------------------
2d triangle
------------------------------------------------------------------------- */
#include "stdlib.h"
#include "string.h"
#include "region_triangle.h"
#include "error.h"
using namespace LAMMPS_NS;
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
/* ---------------------------------------------------------------------- */
RegTriangle::RegTriangle(LAMMPS *lmp, int narg, char **arg) :
Region(lmp, narg, arg)
{
options(narg-8,&arg[8]);
x1 = xscale*atof(arg[2]);
y1 = yscale*atof(arg[3]);
x2 = xscale*atof(arg[4]);
y2 = yscale*atof(arg[5]);
x3 = xscale*atof(arg[6]);
y3 = yscale*atof(arg[7]);
// extent of 2d triangle
extent_xlo = MIN(x1,x2);
extent_xlo = MIN(extent_xlo,x3);
extent_xhi = MAX(x1,x2);
extent_xhi = MAX(extent_xhi,x3);
extent_ylo = MIN(y1,y2);
extent_ylo = MIN(extent_ylo,y3);
extent_yhi = MAX(y1,y2);
extent_yhi = MAX(extent_yhi,y3);
extent_zlo = -0.5;
extent_zhi = 0.5;
}
/* ---------------------------------------------------------------------- */
int RegTriangle::match(double x, double y, double z)
{
double side1 = (x-x1)*(y2-y1) - (y-y1)*(x2-x1);
double side2 = (x-x2)*(y3-y2) - (y-y2)*(x3-x2);
double side3 = (x-x3)*(y1-y3) - (y-y3)*(x1-x3);
int inside;
if (side1 > 0.0 && side2 > 0.0 && side3 > 0.0) inside = 1;
else inside = 0;
return !(inside ^ interior); // 1 if same, 0 if different
}
Thank u very much in advance. Waiting for your reply.
28 Mar 08, 10:05PM
What exactly do you want in 3D?
The 2d code you've given seems to be mostly concerned with seeing if one triangle matches another.
28 Mar 08, 10:25PM
Dear sharma,
Thank u very much for your answer. I want to write a code which will draw a 3D triangular region by giving the point's coordinates as input.Thanks in advance for your answer.D
28 Mar 08, 10:57PM
What platform are you working on.
When you say draw, I assume you want something to appear on the screen. I assume also that when you're talking about 3D you mean you want to draw something like a pyramid, with 4 or perhaps 5 corners.
Next are you trying to make a solid shape, or just the outline. Once you're decided how you're going to display this stuff, then putting the data together is fairly simple. As a start consider http://www.codersource.net/mfc_tutorial_Part3.html
Login