您的位置:首页 > 编程语言

关于几何关系的代码说明

2007-09-11 14:20 239 查看
关于几何关系的代码说明

很多朋友需要这方面的资料,尤其是代码。我在陆续挖掘和整理的过程中,推翻了自己的开源的设想,形成了一个库——cgal32.dll(win32版,标准C库)。

一、这是基于几个原因:

1、库中个别地方代码采用了非商业开源的代码。我没有权利去公开它们。

2、只有不开源,我写的库大家才能免费使用。免除大家在道德和法律上面临的风险。

3、我做了大量工作,使自己本身免除道德和法律上的风险。

4、我声明我个人拥有这些库(编译后)的版权。今后任何个人和公司可以免费使用库,但不能声明拥有版权(或其他权利,包括出售库本身的权利)。我拥有库的源代码90%以上的版权。

二、关于cgal32.dll:

1、cgal32.dll与CGAL开源项目(www.cgal.org)没有任何关系,我也没看过和下载过它们的代码。

2、我使用ANSI C构建cgal32.dll库,以使其适应跨平台的需要。虽然目前只有WIN32版本,但以后会出LINUX等版本。

3、cgal32.dll主要完成空间几何的定义和运算。空间几何包括:点(点集)、线(多线)、面、体和面片。运算包括:Union、Difference、XOR、Intersection。

4、我的目标是把cgal32发展成为具有巨大潜力的解决人们在空间几何领域的诸多问题。

5、目前功能简单,还不提供下载,请谅解。

三、附部分头文件:

/*=============================================================================
#ifndef _CGAL_H_INCLUDED
#define _CGAL_H_INCLUDED

#include <stdio.h>
#include <float.h>
#include <assert.h>
#include <memory.h>

#ifdef __cplusplus
#endif

#endif /* ndef _CGAL_H_INCLUDED */

/*=============================================================================
cgaldef.h
cheungmine - All rights reserved
Sep. 8, 2007
=============================================================================*/
#ifndef _CGALDEF_H_INCLUDED
#define _CGALDEF_H_INCLUDED

#ifndef CG_PI
#define CG_PI 3.1415926535897932384626433832795
#endif

#ifndef CG_HFPI
#define CG_HFPI 1.5707963267948966192313216916398
#endif

#ifndef CG_BIPI
#define CG_BIPI 6.283185307179586476925286766559
#endif

#ifndef TRUE
#define FALSE 0
#define TRUE 1
#endif

typedef int BOOL;
typedef unsigned char BYTE;
typedef unsigned int size_t;

/*=============================================================================
Opaque Struct Handles
=============================================================================*/
typedef struct _cg_polygon_t* cg_polygon;

typedef struct _cg_trilist_t* cg_trilist;
typedef struct _cg_trinet_t* cg_trinet;
typedef struct _cg_trifan_t* cg_trifan;
typedef struct _cg_tristrip_t* cg_tristrip;

typedef struct _cg_trilistZ_t* cg_trilistZ;
typedef struct _cg_trinetZ_t* cg_trinetZ;
typedef struct _cg_trifanZ_t* cg_trifanZ;
typedef struct _cg_tristripZ_t* cg_tristripZ;

typedef struct _cg_shape_t* cg_shape;

typedef struct _cg_arclist_t* cg_arclist;
typedef struct _cg_arclistZ_t* cg_arclistZ;

typedef struct _cg_object_t* cg_object;

typedef struct _cg_patch_t* cg_patch;
typedef struct _cg_patchZ_t* cg_patchZ;

typedef struct _cg_geometry_t* cg_geometry;

/*=============================================================================
Public Types
=============================================================================*/
/* shape type */
typedef enum
{
SHP_NULL = 0, /* Null type*/
SHP_POINT = 1, /* Point type*/
SHP_LINE = 2, /* Line type*/
SHP_POLYGON = 3 /* Polygon type*/
} CG_SHAPETYPE;

/* arc type */
typedef enum
{
ARC_LINE =1,
ARC_CIRCLE_P =2,
ARC_CIRCLE_C =3,
ARC_ELLIPSE =4,
ARC_SPLINE =10,
ARC_BEZIER =20
} CG_ARCTYPE;

/* 3D Object Types - standard object primitives */
typedef enum
{
OBJ_BOX = 1,
OBJ_CONE = 2,
OBJ_SPERE = 3,
OBJ_HEMISPHERE = 4,
OBJ_GEOSPHERE = 5,
OBJ_CYLINDER = 6,
OBJ_TUBE = 7,
OBJ_TORUS = 8,
OBJ_PYRMID = 9,
OBJ_PLANE = 10
} CG_OBJECTTYPE;

/* extended object primitives */
typedef enum
{
OBJEX_ELLIPSOID = 16,
OBJEX_OVAL = 17,
OBJEX_HEDRA = 18,
OBJEX_CHAMFERBOX = 19,
OBJEX_CHAMFERCYL = 20,
OBJEX_SPINDLE = 21,
OBJEX_GENGON = 22,
OBJEX_PRISM = 23,
OBJEX_HOSE = 24,
OBJEX_L_EXT = 25,
OBJEX_C_EXT = 26,
OBJEX_CAPSULE = 27,
OBJEX_TORUSKNOT = 28,
OBJEX_OILTANK = 29,
OBJEX_RINGWAVE = 30,
OBJ_TEAPOT = 31
} CG_OBJECTTYPE_EX;

/* Patch type */
typedef enum
{
PAT_TRILIST = 1,
PAT_TRINET = 2,
PAT_TRIFAN = 3,
PAT_TRISTRIP = 4
} CG_PATCHTYPE;

/* 3D Patch type */
typedef enum
{
PAT_TRILISTZ = 5,
PAT_TRINETZ = 6,
PAT_TRIFANZ = 7,
PAT_TRISTRIPZ = 8
} CG_PATCHZTYPE;

/* Geometry type */
typedef enum
{
GT_NULL = 0,
GT_SHAPE = 1,
GT_VERTEX = 2,
GT_VERTEXZ = 3,
GT_POLYLINE = 4,
GT_POLYLINEZ = 5,
GT_POLYGON = 6,
GT_ARCLIST = 7, /* Compound arc line */
GT_ARCLISTZ = 8, /* Compound arc with z */
GT_PATCH = 9,
GT_PATCHZ = 10,
GT_OBJECT = 11 /* Object */
} CG_GEOMETRYTYPE;

/*=============================================================================
Enum Constants
=============================================================================*/
typedef enum /* Set operation type */
{
CG_DIFF, /* Difference */
CG_INT, /* Intersection */
CG_XOR, /* Exclusive or */
CG_UNION /* Union */
} CG_OPCLIP;

typedef enum /* relationships */
{
REL_CONTAIN = 0, /* TRUE if the primary shape wholly contains the secondary shape */
REL_CROSS = 1, /* TRUE if the intersection of the interiors is a lower dimension than the maximum dimension of the two shapes */
REL_DISJOINT = 2, /* TRUE if the intersection of two shapes is empty */
REL_EQUAL = 3, /* TRUE if the two supplied shapes are identical */
REL_OVERLAP = 4, /* TRUE if the intersection of two shapes results in an object of the same geometric dimension */
REL_TOUCH = 5, /* TRUE if the two supplied shapes share a common boundary */
REL_WITHIN = 6 /* TRUE if primary_shape is wholly contained within secondary_shape */
} CG_RELATION;

/*=============================================================================
Public Struct Types
=============================================================================*/
/* Vertex structure */
typedef struct
{
union{
struct{ double x, y; };
double _v[2];
};
} cg_vertex_t, cg_point_t;

/* Line structure */
typedef struct
{
union{
struct{ double x1, y1, x2, y2; };
struct{ cg_point_t start, end; };
cg_point_t _p[2];
double _v[4];
};
} cg_edge_t, cg_line_t;

/* Vertex list structure */
typedef struct
{
int num_vertices; /* Number of vertices in list */
cg_vertex_t *vertex; /* Vertex array pointer */
} cg_vertexlist_t, cg_pointlist_t, cg_polyline_t;

/* rectangle type*/
typedef struct
{
union{
struct{
union{
struct{ double min_x, min_y; };
cg_vertex_t _min;
};
union{
struct{ double max_x, max_y; };
cg_vertex_t _max;
};
};
double _v[4];
};
} cg_rect_t;

/* 3D rect - box type*/
typedef struct
{
union{
struct{
union{
struct{ double min_x, min_y, max_x, max_y; };
cg_rect_t _rc;
};
double min_z, max_z;
};
double _v[6];
};
} cg_rectZ_t, cg_box_t;

/* circleCR struct */
typedef struct
{
union{
struct{ double xp, yp; };
cg_vertex_t _cp;
};
double r;
} cg_circle_t;

/* Point structure */
typedef struct
{
union{
struct{
union{
struct{ double x, y; };
cg_vertex_t _p;
};
double z;
};
double _v[3];
};
} cg_vector_t, cg_pointZ_t, cg_vertexZ_t;

/* 3D Vertex list structure */
typedef struct
{
int num_vertices; /* Number of vertices */
cg_vector_t *vertex; /* Vertex array */
} cg_vectorlist_t, cg_pointlistZ_t, cg_vertexlistZ_t;

/* Triangle struct */
typedef struct
{
union{
struct{ cg_vertex_t v0, v1, v2; };
cg_vertex_t _v[3];
};
} cg_tri_t;

/* 3D Triangle struct */
typedef struct
{
union{
struct{ cg_vector_t v0, v1, v2; };
cg_vector_t _v[3];
};
cg_vector_t n; /* Normal vector */
} cg_triZ_t;

/* triangle vertex index struct */
typedef struct
{
union{
struct{ int i0, i1, i2; };
int _vi[3];
};
} cg_triindex_t;

/* BLOB struct */
typedef struct
{
BYTE* chunk;
size_t size;
} cg_blob_t;

/*============================================================================*/
#endif /* ndef _CGALDEF_H_INCLUDED */
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: