This commit is contained in:
watrabi
2025-09-18 17:55:52 -04:00
commit 977f1ff4b8
15030 changed files with 17324420 additions and 0 deletions
+147
View File
@@ -0,0 +1,147 @@
#include "../../sg.h"
//#include <o_model.h>
#pragma argsused
short create_box_np(lpLISTH listh, sgFloat *par)
{
/*
VLD vld;
if ( !o_create_box(par) ) return 0;
init_vld(&vld);
if ( !add_np_mem(&vld,npwg,TNPB)) return 0;
*listh = vld.listh;
return 1;
*/
init_listh(listh);
return 1;
}
BOOL o_create_box(sgFloat *par)
{
sgFloat rx = par[0], ry = par[1], rz = par[2];
lpNPW np;
short i,j;
int nov=8,noe=12,nof=6,noc=6;
short bv[]={0, 1, 1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 7};
short ev[]={0, 2, 4, 5, 3, 6, 4, 7, 8, 6, 8, 7, 8};
short fp[]={0, 1, 3, 2, 1, 4, 1, 5, 3, 2, 6, 4, 5};
short ep[]={0, 4, 8, 9, 6, 11, -2, 12,-10, -5,-12, -7, -8};
short fm[]={0, 2, 1, 3, 4, 2, 5, 4, 5, 6, 3, 6, 6};
short em[]={0, 3, 1, 2, 5, -1, 7, -4, -6, 10, -3, -9,-11};
short fe[]={0, 1, -1, 2, 5, 7, 10};
//
if ( fabs(rx) <= eps_n ) rx += 10*eps_d;
if ( fabs(ry) <= eps_n ) ry += 10*eps_d;
if ( fabs(rz) <= eps_n ) rz += 10*eps_d;
/*
//
if (fabs(rx) <= eps_n && ry >eps_n && rz > eps_n ||
fabs(ry) <= eps_n && rx >eps_n && rz > eps_n ||
fabs(rz) <= eps_n && rx >eps_n && ry > eps_n) {
box2(rx, ry, rz);
return TRUE;
} else if (rx <= eps_n || ry <= eps_n || rz <= eps_n) {
handler_err(ERR_BAD_PARAMETER);
return FALSE;
}
*/
np = npwg;
//
np->v[1].y = 0.0;
np->v[1].z = 0.0;
np->v[2].y = 0.0;
np->v[2].z = rz;
np->v[3].y = ry;
np->v[3].z = rz;
np->v[4].y = ry;
np->v[4].z = 0.0;
j = nov/2+1;
for (i = 1; i <= nov/2; i++) {
np->v[i ].x = 0.0;
np->v[j ].y = np->v[i].y;
np->v[j ].z = np->v[i].z;
np->v[j++].x = rx;
}
np->nov = nov;
//
for (i = 1; i <= noe; i++) {
np->efr[i].bv = bv[i];
np->efr[i].ev = ev[i];
np->efc[i].fp = fp[i];
np->efc[i].ep = ep[i];
np->efc[i].fm = fm[i];
np->efc[i].em = em[i];
np->efr[i].el = ST_TD_CONSTR;
}
np->noe = noe;
//
for (i = 1; i <= nof; i++) {
np->f[i].fc = i;
np->f[i].fl = ST_FACE_PLANE;
np->c[i].fe = fe[i];
np->c[i].nc = 0;
}
np->nof = nof;
np->noc = noc;
np->ident = -32767;
np->type = TNPB;
return TRUE;
}
/*
void box2(sgFloat dx, sgFloat dy, sgFloat dz)
{
lpNPW np = npwg;
np->nov = np->noe = 4;
np->nof = np->noc = 2;
np->ident = -32767;
np->type = TNPB;
//
np->v[1].x = np->v[1].y = np->v[1].z = 0.0;
if (dx < eps_n) { np->v[2].x = 0.0; np->v[2].y = dy; }
else { np->v[2].x = dx; np->v[2].y = 0.0; }
np->v[2].z = 0.0;
np->v[3].x = dx;
np->v[3].y = dy;
np->v[3].z = dz;
np->v[4].x = 0.0;
if (dz < eps_n) { np->v[4].y = dy; np->v[4].z = 0.0; }
else { np->v[4].y = 0.0; np->v[4].z = dz; }
//
np->efr[1].bv = np->efr[4].ev = 1;
np->efr[1].ev = np->efr[2].bv = 2;
np->efr[2].ev = np->efr[3].bv = 3;
np->efr[3].ev = np->efr[4].bv = 4;
np->efc[1].ep = 2;
np->efc[2].ep = 3;
np->efc[3].ep = 4;
np->efc[4].ep = 1;
np->efc[1].em = -4;
np->efc[2].em = -1;
np->efc[3].em = -2;
np->efc[4].em = -3;
np->efc[1].fp = np->efc[2].fp = np->efc[3].fp = np->efc[4].fp = 1;
np->efc[1].fm = np->efc[2].fm = np->efc[3].fm = np->efc[4].fm = 2;
//
np->f[1].fc = 1;
np->f[2].fc = 2;
np->c[1].fe = 1;
np->c[2].fe =-1;
np->f[1].fl = np->f[2].fl = 0;
np->c[1].nc = np->c[2].nc = 0;
}
*/
+81
View File
@@ -0,0 +1,81 @@
#include "../../sg.h"
short create_cone_np(lpLISTH listh, sgFloat *par, BOOL constr)
{
sgFloat r1 = par[0]; //
sgFloat r2 = par[1]; //
sgFloat h = par[2]; //
int n = (int)par[3]; // -
short i, j;
sgFloat r,z,alfa,d_alfa;
MESHDD mdd;
MNODE node;
lpNPW np = NULL;
sgFloat k_i, step_i;
c_num_np = -32767;
init_vdim(&mdd.vdim,sizeof(node));
if ( !np_init_list(&c_list_str) ) goto err;
d_alfa = M_PI*2/n;
step_i = n/4.;
r = r1; z = 0;
for (j=0 ; j < 2 ; j++ ) {
for (i = 0, k_i=0.; i <= n ; i++) {
alfa = ( i != n ) ? (d_alfa*i) : 2*M_PI;
node.p.x = r*cos(alfa);
node.p.y = r*sin(alfa);
node.p.z = z;
node.num = (short)CONSTR_U;
if ( constr ) node.num |= (short)CONSTR_V;
else {
if ( i == (short)(k_i+0.5) ) {
node.num |= (short)COND_V;
k_i += step_i;
}
}
if ( !add_elem(&mdd.vdim,&node) ) {
free_vdim(&mdd.vdim);
return FALSE;
}
}
// if (j == 1) break;
r = r2; z = h;
}
mdd.n = n+1;
mdd.m = 2;
if(!(np_mesh4p(&c_list_str,&c_num_np,&mdd,0.))) goto err;
free_vdim(&mdd.vdim);
//
if ((np = creat_np_mem(TNPW,MAXNOV,MAXNOE,MAXNOC, MAXNOF,
MAXNOE)) == NULL) goto err1;
np_init((lpNP)np);
if ( r1 > eps_d ) {
np_face(np, r1, n, 0.,&c_num_np); //
np->f[1].fl = ST_FACE_PLANE;
if( np->nov > MAXNOV || np->noe > MAXNOE ) {
if( !sub_division( np ) ) goto err1;
} else if ( !np_put(np,&c_list_str) ) goto err1;
}
if ( r2 > eps_d ) {
np_face(np, r2, n, h, &c_num_np); //
np->f[1].fl = ST_FACE_PLANE;
if( np->nov > MAXNOV || np->noe > MAXNOE ) {
if( !sub_division( np ) ) goto err1;
} else if ( !np_put(np,&c_list_str) ) goto err1;
}
//
if ((c_num_np = np_end_of_put(&c_list_str,NP_FIRST,30,listh)) == 0) goto err1;
free_np_mem(&np);
return c_num_np;
err1:
free_np_mem(&np);
err:
free_vdim(&mdd.vdim);
np_end_of_put(&c_list_str,NP_CANCEL,0,NULL);
return 0;
}
+146
View File
@@ -0,0 +1,146 @@
#include "../../sg.h"
BOOL cyl_gru(lpNPW np);
short create_cyl_np(lpLISTH listh, sgFloat *par, BOOL constr)
{
sgFloat r = par[0];
sgFloat h = par[1];
int n = (int)par[2];
short i; //,gru;
sgFloat alfa, d_alfa;
NP_STR str;
VLD vld;
MESHDD mdd;
MNODE node;
lpNPW np = NULL;
sgFloat k_i, step_i;
c_num_np = -32767;
init_vdim(&mdd.vdim,sizeof(node));
if ( !np_init_list(&c_list_str) ) goto err;
d_alfa = 2 * M_PI / n;
step_i = n / 4.;
for (i = 0, k_i=0.; i < n+1 ; i++) {
alfa = ( i != n ) ? (d_alfa*i) : 2*M_PI;
node.p.x = r*cos(alfa);
node.p.y = r*sin(alfa);
node.p.z = 0;
node.num = (short)CONSTR_U;
if ( constr ) node.num |= CONSTR_V;
else {
if ( i == (short)(k_i+0.5) ) {
node.num |= COND_V;
k_i += step_i;
}
}
if ( !add_elem(&mdd.vdim,&node) ) goto err2;
}
for (i = 0 ; i < n+1 ; i++) {
alfa = ( i != n ) ? (d_alfa*i) : 2*M_PI;
node.p.x = r*cos(alfa);
node.p.y = r*sin(alfa);
node.p.z = h;
node.num = (short)CONSTR_U;
if ( !add_elem(&mdd.vdim,&node) ) {
err2:
free_vdim(&mdd.vdim);
return FALSE;
}
}
mdd.n = n+1;
mdd.m = 2;
if(!(np_mesh4p(&c_list_str,&c_num_np,&mdd,0.))) goto err;
free_vdim(&mdd.vdim);
if ( c_list_str.number_all == 1) {
init_vld(&vld);
read_elem(&c_list_str.vdim,0,&str);
if (!(read_np(&c_list_str.bnp,str.hnp,npwg))) goto err;
if ( !(cyl_gru(npwg)) ) goto err;
/* gru = 0;
for (i=1 ; i <= npwg->noe ; i++) { //
if (npwg->efc[i].fp < 0 || npwg->efc[i].fm < 0) gru++;
}
*/
add_np_mem(&vld,npwg,TNPB);
np_face(npwg, r, n, 0.,&c_num_np); //
for (i = 1 ; i <= npwg->noe ; i++) {
npwg->efc[i].fm = -i;
npwg->efc[i].em = -32767;
npwg->gru[i] = (float)M_PI/2.0f;
}
npwg->f[1].fl = ST_FACE_PLANE;
np_inv(npwg,NP_ALL);
add_np_mem(&vld,npwg,TNPB);
np_face(npwg, r, n, h, &c_num_np); //
for (i = 1 ; i <= npwg->noe ; i++) {
npwg->efc[i].fm = -i;
npwg->efc[i].em = -32767;
npwg->gru[i] = (float)M_PI*1.5f;
}
npwg->f[1].fl = ST_FACE_PLANE;
add_np_mem(&vld,npwg,TNPB);
*listh = vld.listh;
np_end_of_put(&c_list_str,NP_CANCEL,0,NULL);
c_num_np = 3;
goto end;
}
//
if ((np = creat_np_mem(TNPW,MAXNOV,MAXNOE,MAXNOC, MAXNOF,
MAXNOE)) == NULL) goto err1;
np_init((lpNP)np);
np_face(np, r, n, 0.,&c_num_np); //
np->f[1].fl = ST_FACE_PLANE;
if( np->nov > MAXNOV || np->noe > MAXNOE ){
if( !sub_division( np ) ) goto err1; }
else if ( !np_put(np,&c_list_str) ) goto err1;
np_face(np, r, n, h, &c_num_np); //
np->f[1].fl = ST_FACE_PLANE;
if( np->nov > MAXNOV || np->noe > MAXNOE ){
if( !sub_division( np ) ) goto err1; }
else if ( !np_put(np,&c_list_str) ) goto err1;
//
if ((c_num_np = np_end_of_put(&c_list_str,NP_FIRST,30,listh)) == 0) goto err1;
free_np_mem(&np);
goto end;
err1:
free_np_mem(&np);
err:
free_vdim(&mdd.vdim);
np_end_of_put(&c_list_str,NP_CANCEL,0,NULL);
c_num_np = 0;
end:
return c_num_np;
}
BOOL cyl_gru(lpNPW np)
{
short i;
for (i = 1 ; i <= np->noe ; i++) {
if (np->efc[i].ep != 0 && np->efc[i].em != 0) continue;
np->gru[i] = (float)M_PI*1.5f;
if (np->efc[i].em == 0) {
np->efc[i].fm = -i;
if (np->v[np->efr[i].bv].z == 0) np->efc[i].em = -32766;
else np->efc[i].em = -32765;
} else {
np->efc[i].fp = -i;
if (np->v[np->efr[i].bv].z == 0) np->efc[i].ep = -32766;
else np->efc[i].ep = -32765;
}
}
return TRUE;
}
@@ -0,0 +1,65 @@
#include "../../sg.h"
short create_elipsoid_np(lpLISTH listh, sgFloat *par)
{
sgFloat ra = par[0], rb = par[1], rc=par[2];
int n = (int)par[3], m = (int)par[4];
int i, j;
sgFloat d_alpha, d_beta, beta, alpha;
MNODE node;
MESHDD mdd;
NP_STR_LIST list_str;
short num_np = -32767;
short mask;
sgFloat step_j, step_i, k_i, k_j;
init_vdim(&mdd.vdim,sizeof(node));
m+=2;
step_j = (m-1)/2.;
step_i = n/4.;
d_alpha = 2 * M_PI / n;
d_beta = M_PI / (m-1);
for ( j = 0, k_j=0.; j < m; j++ ){
if ( j == (short)(k_j+0.5) ) {
mask = COND_U;
k_j += step_j;
}
else mask = 0;
beta = ( j == m-1 ) ? ( M_PI ) : ( d_beta*j );
for (i = 0, k_i=0.; i <= n ; i++){
alpha = ( i == 0 ) ? ( 2*M_PI ) : ( d_alpha*(n-i) );
node.p.x = ra*sin(beta)*cos(alpha);
node.p.y = rb*sin(beta)*sin(alpha);
node.p.z = rc*cos(beta);
node.num = mask;
if ( i == (short)(k_i+0.5) ) {
node.num |= COND_V;
k_i += step_i;
}
if ( !add_elem(&mdd.vdim,&node) ) {
free_vdim(&mdd.vdim);
return FALSE;
}
}
}
mdd.m = m;
mdd.n = n + 1;
if ( !np_init_list(&list_str) ) goto err;
if(!(np_mesh4p(&list_str,&num_np,&mdd,0.))) goto err;
free_vdim(&mdd.vdim);
//
if ( !(num_np = np_end_of_put(&list_str,NP_FIRST,100,listh)) ) goto err;
goto end;
err:
free_vdim(&mdd.vdim);
np_end_of_put(&list_str,NP_CANCEL,0,listh);
num_np = 0;
end:
return num_np;
}
+153
View File
@@ -0,0 +1,153 @@
#include "../../sg.h"
short create_primitive_np(BREPKIND kind,lpLISTH listh, sgFloat *par)
{
short num = 0;
switch (kind) {
case BOX:
num = create_box_np(listh, par);
break;
case SPHERE:
num = create_sph_np(listh, par);
break;
case CYL:
num = create_cyl_np(listh, par, FALSE);
break;
case CONE:
num = create_cone_np(listh, par, FALSE);
break;
case TOR:
num = create_tor_np(listh, par);
break;
case PRISM:
num = create_cyl_np(listh, par, TRUE);
break;
case PYRAMID:
num = create_cone_np(listh, par, TRUE);
break;
case ELIPSOID:
num = create_elipsoid_np(listh, par);
break;
case SPHERIC_BAND:
num = create_spheric_band_np(listh, par);
break;
default:
handler_err(ERR_NUM_PRIMITIVE);
break;
}
return num;
}
hOBJ create_primitive_obj(BREPKIND kind, sgFloat *par)
{
hOBJ hbrep = NULL;
lpOBJ brep;
lpGEO_BREP lpgeobrep;
lpCSG csg;
WORD size;
LNP lnp;
D_POINT minP, maxP;
sgFloat c;
memset(&lnp,0,sizeof(lnp));
lnp.kind = kind;
switch (kind) {
case BOX:
if ( !(lnp.num_np = create_box_np(&lnp.listh, par))) return NULL;
// lnp.num_np = 0;
size = sizeof(sgFloat)*3;
minP.x = minP.y = minP.z = 0.;
maxP.x = par[0]; maxP.y = par[1]; maxP.z = par[2];
break;
case SPHERE:
if ( !(lnp.num_np = create_sph_np(&lnp.listh, par))) return NULL;
size = sizeof(sgFloat)*3;
minP.x = minP.y = minP.z = - par[0];
maxP.x = maxP.y = maxP.z = par[0];
break;
case CYL:
if ( !(lnp.num_np = create_cyl_np(&lnp.listh, par, FALSE))) return NULL;
size = sizeof(sgFloat)*3;
minP.x = minP.y = - par[0]; minP.z = 0.;
maxP.x = maxP.y = par[0]; maxP.z = par[1];
break;
case CONE:
if ( !(lnp.num_np = create_cone_np(&lnp.listh, par, FALSE))) return NULL;
size = sizeof(sgFloat)*4;
minP.x = minP.y = - max(par[0],par[1]); minP.z = 0;
maxP.x = maxP.y = max(par[0],par[1]); maxP.z = par[2];
break;
case TOR:
if ( !(lnp.num_np = create_tor_np(&lnp.listh, par))) return NULL;
size = sizeof(sgFloat)*4;
minP.x = minP.y = - (par[0] + par[1]); minP.z = - par[1];
maxP.x = maxP.y = par[0] + par[1]; maxP.z = par[1];
break;
case PRISM:
if ( !(lnp.num_np = create_cyl_np(&lnp.listh, par, TRUE))) return NULL;
size = sizeof(sgFloat)*3;
minP.x = minP.y = - par[0]; minP.z = 0.;
maxP.x = maxP.y = par[0]; maxP.z = par[1];
break;
case PYRAMID:
if ( !(lnp.num_np = create_cone_np(&lnp.listh, par, TRUE))) return NULL;
size = sizeof(sgFloat)*4;
minP.x = minP.y = - max(par[0],par[1]); minP.z = 0;
maxP.x = maxP.y = max(par[0],par[1]); maxP.z = par[2];
break;
case ELIPSOID:
if ( !(lnp.num_np = create_elipsoid_np(&lnp.listh, par))) return NULL;
size = sizeof(sgFloat)*5;
minP.x = - par[0];
maxP.x = par[0];
minP.y = - par[1];
maxP.y = par[1];
minP.z = - par[2];
maxP.z = par[2];
break;
case SPHERIC_BAND:
if ( !(lnp.num_np = create_spheric_band_np(&lnp.listh, par))) return NULL;
size = sizeof(sgFloat)*5;
if (par[1] * par[2] <= eps_n) c = par[0];
else {
c = min(fabs(par[1]), fabs(par[2]));
c = par[0] * sqrt(1 - c * c);
}
minP.x = - c;
maxP.x = c;
minP.y = - c;
maxP.y = c;
minP.z = par[0] * par[1];
maxP.z = par[0] * par[2];
break;
default:
return FALSE;
}
//
if ( (lnp.hcsg = SGMalloc(size+2) ) == NULL ) goto err;
csg = (lpCSG)lnp.hcsg;
csg->size = size;
memcpy(csg->data,par,size);
if ( ( hbrep = o_alloc(OBREP)) == NULL) goto err;
brep = (lpOBJ)hbrep;
lpgeobrep = (lpGEO_BREP)brep->geo_data;
o_hcunit(lpgeobrep->matr);
lpgeobrep->min = minP;
lpgeobrep->max = maxP;
lpgeobrep->type = BODY;
lpgeobrep->ident_np = -32767 + lnp.num_np;
if ( !put_np_brep(&lnp,&lpgeobrep->num) ) goto err;
return hbrep;
err:
free_item_list(&lnp.listh);
if ( lnp.hcsg ) SGFree(lnp.hcsg);
if ( hbrep ) o_free(hbrep,NULL);
return NULL;
}
+190
View File
@@ -0,0 +1,190 @@
#include "../../sg.h"
static BOOL create_spheric_band( lpMESHDD g, sgFloat r,
sgFloat c1, sgFloat c2, sgFloat, short );
static hOBJ create_my_arc(sgFloat coef1, sgFloat coef2, sgFloat r );
static BOOL rotate_point( lpMESHDD g, lpD_POINT p,
short NUM_REV_POINTS, sgFloat, short );
short create_spheric_band_np( lpLISTH listh, sgFloat *par ){
sgFloat r = par[0]; //
sgFloat coeff1 = par[1]; //
sgFloat coeff2 = par[2];
sgFloat toll = par[3]; //
int n_merd = (int)par[4]; //-
BOOL zu = TRUE;//par[5]; //
MESHDD mdd;
lpNPW np = NULL;
c_num_np = -32767;
if ( !np_init_list(&c_list_str) ) return FALSE;
if ( !create_spheric_band(&mdd, r, coeff1, coeff2, toll, n_merd ) ) goto err0;
if (!(np_mesh4p(&c_list_str,&c_num_np,&mdd,0.))) goto err1;
if( zu ){
if ((np = creat_np_mem(TNPW,MAXNOV,MAXNOE,MAXNOC, MAXNOF, MAXNOE)) == NULL) goto err1;
np_init((lpNP)np);
//
if( fabs(coeff2) != 1 ){
np->ident = c_num_np++;
put_top_bottom( np, &mdd );
if( np->nov > MAXNOV || np->noe > MAXNOE ){
if( !sub_division( np ) ) goto err2;
}
else{
if( !np_cplane( np ) ) goto err2;
if( !np_put( np, &c_list_str ) ) goto err2;
}
}
if( fabs(coeff1) != 1 ){
//
np->ident = c_num_np++;
put_bottom_bottom_skin( np, &mdd );
if( np->nov > MAXNOV || np->noe > MAXNOE ){
if( !sub_division( np ) ) goto err2;
}
else{
if ( !np_cplane( np ) ) goto err2;
if ( !np_put( np, &c_list_str ) ) goto err2;
}
}
free_np_mem(&np);
}
free_vdim(&mdd.vdim);
//
if ((c_num_np = np_end_of_put(&c_list_str,NP_FIRST,30,listh)) == 0) goto err1;
return c_num_np;
err2:
free_np_mem(&np);
err1:
free_vdim(&mdd.vdim);
err0:
np_end_of_put(&c_list_str,NP_CANCEL,0,NULL);
return FALSE;
}
static BOOL create_spheric_band( lpMESHDD g, sgFloat r, sgFloat c1,
sgFloat c2, sgFloat toll, short n_merd ){
short NUM_REV_POINTS;
int num_elem;
int mask;
sgFloat fi=2*M_PI, t;
lpMNODE node;
VDIM vdim_band;
hOBJ hobj;
//
if( (hobj = create_my_arc( c1, c2, r )) == NULL ) return FALSE;
init_vdim(&g->vdim,sizeof(MNODE));
NUM_REV_POINTS = ( fabs(fi) >= 2*M_PI ) ?
( n_merd ) : ((short)(fabs(fi)/(2*M_PI)*n_merd));
if ( NUM_REV_POINTS == 0 ) NUM_REV_POINTS = 1;
//
init_vdim(&vdim_band, sizeof(MNODE));
t = c_h_tolerance;
c_h_tolerance = toll;
if (!apr_path( &vdim_band, hobj )) goto err1;
c_h_tolerance = t;
g->n = NUM_REV_POINTS + 1;
g->m = (short)vdim_band.num_elem;
if (!begin_rw(&vdim_band, 0)) goto err1;
for (num_elem = 0; num_elem < vdim_band.num_elem; num_elem++) {
if ((node = (lpMNODE)get_next_elem(&vdim_band)) == NULL) goto err2;
//
mask = 0;
if (!(node->num & AP_CONSTR)) mask = CONSTR_U;
else if (node->num & AP_SOPR || node->num & AP_COND) mask = COND_U;
//
if( !rotate_point( g, &node->p, NUM_REV_POINTS, fi, mask ) ) goto err2;
}
o_free( hobj, NULL );
end_rw(&vdim_band);
free_vdim(&vdim_band);
return TRUE;
err2:
end_rw(&vdim_band);
err1:
o_free( hobj, NULL );
free_vdim(&vdim_band);
free_vdim(&g->vdim);
return FALSE;
}
static hOBJ create_my_arc(sgFloat coef1, sgFloat coef2, sgFloat r )
{
GEO_ARC arc;
sgFloat fi_b, fi_e;
hOBJ hobj;
lpOBJ obj;
arc.vc.x = 0.;//
arc.vc.y = 0.;
arc.vc.z = 0.;
arc.r = r; //
arc.n.x = 0; //
arc.n.y =-1;
arc.n.z = 0;
fi_b=acos(fabs(coef1));
if( coef1 >= 0 ) fi_b += M_PI/2;
else fi_b = M_PI*3/2 - fi_b;
arc.vb.x=r*cos(fi_b);//
arc.vb.y=0;
arc.vb.z=r*sin(fi_b);
fi_e=acos(fabs(coef2));
if( coef2 >= 0 ) fi_e += M_PI/2;
else fi_e = M_PI*3/2 - fi_e;
arc.ve.x=r*cos(fi_e);//
arc.ve.y=0;
arc.ve.z=r*sin(fi_e);
arc.angle=-(fi_b-fi_e);
calc_arc_ab(&arc);
if((hobj = o_alloc(OARC)) == NULL)
return NULL;
obj = (lpOBJ)hobj;
memcpy(obj->geo_data, &arc, sizeof(arc));
return hobj;// '
}
static BOOL rotate_point( lpMESHDD g, lpD_POINT p,
short NUM_REV_POINTS, sgFloat fi, short mask ){
short j;
sgFloat d_fi, f, R, z;
MNODE node;
sgFloat step_j, k_j;
step_j = sg_m_num_meridians/4.;
d_fi = fi / NUM_REV_POINTS;
z = p->z;
R = sqrt( p->x*p->x + p->y*p->y );
for ( j = 0, k_j=0.; j <= NUM_REV_POINTS; j++ ){
f = ( j == NUM_REV_POINTS ) ? ( fi ) : ( d_fi*j );
p->x = R*cos( f );
p->y = R*sin( f );
p->z = z;
node.p = *p;
node.num = mask;
if( j == (short)(k_j+0.5) ){
node.num |= COND_V;
k_j += step_j;
}
if( !add_elem(&g->vdim, &node ) ) return FALSE;
}
return TRUE;
}
+65
View File
@@ -0,0 +1,65 @@
#include "../../sg.h"
short create_sph_np(lpLISTH listh, sgFloat *par)
{
sgFloat r = par[0];
short n = (short)par[1];
int m = (int)par[2];
short i, j;
sgFloat d_alpha, d_beta, beta, alpha;
MNODE node;
MESHDD mdd;
NP_STR_LIST list_str;
short num_np = -32767;
short mask;
sgFloat step_j, step_i, k_i, k_j;
init_vdim(&mdd.vdim,sizeof(node));
m+=2;
step_j = (m-1)/2.;
step_i = n/4.;
d_alpha = 2 * M_PI / n;
d_beta = M_PI / (m-1);
for ( j = 0, k_j=0.; j < m; j++ ){
if ( j == (short)(k_j+0.5) ) {
mask = COND_U;
k_j += step_j;
}
else mask = 0;
beta = ( j == m-1 ) ? ( M_PI ) : ( d_beta*j );
for (i = 0, k_i=0.; i <= n ; i++){
alpha = ( i == 0 ) ? ( 2*M_PI ) : ( d_alpha*(n-i) );
node.p.x = r*sin(beta)*cos(alpha);
node.p.y = r*sin(beta)*sin(alpha);
node.p.z = r*cos(beta);
node.num = mask;
if ( i == (short)(k_i+0.5) ) {
node.num |= COND_V;
k_i += step_i;
}
if ( !add_elem(&mdd.vdim,&node) ) {
free_vdim(&mdd.vdim);
return FALSE;
}
}
}
mdd.m = m;
mdd.n = n + 1;
if ( !np_init_list(&list_str) ) goto err;
if(!(np_mesh4p(&list_str,&num_np,&mdd,0.))) goto err;
free_vdim(&mdd.vdim);
//
if ( !(num_np = np_end_of_put(&list_str,NP_FIRST,100,listh)) ) goto err;
goto end;
err:
free_vdim(&mdd.vdim);
np_end_of_put(&list_str,NP_CANCEL,0,listh);
num_np = 0;
end:
return num_np;
}
@@ -0,0 +1,68 @@
#include "../../sg.h"
/*
short create_spheric_band_np(lpLISTH listh, sgFloat *par)
{
//
sgFloat r = par[0];
short n = par[4];
int m = par[4];
short i, j;
sgFloat d_alpha, d_beta, beta, alpha;
MNODE node;
MESHDD mdd;
NP_STR_LIST list_str;
short num_np = -32767;
short mask;
sgFloat step_j, step_i, k_i, k_j;
init_vdim(&mdd.vdim,sizeof(node));
m+=2;
step_j = (m-1)/2.;
step_i = n/4.;
d_alpha = 2 * M_PI / n;
d_beta = M_PI / (m-1);
for ( j = 0, k_j=0.; j < m; j++ ){
if ( j == (short)(k_j+0.5) ) {
mask = COND_U;
k_j += step_j;
}
else mask = 0;
beta = ( j == m-1 ) ? ( M_PI ) : ( d_beta*j );
for (i = 0, k_i=0.; i <= n ; i++){
alpha = ( i == 0 ) ? ( 2*M_PI ) : ( d_alpha*(n-i) );
node.p.x = r*sin(beta)*cos(alpha);
node.p.y = r*sin(beta)*sin(alpha);
node.p.z = r*cos(beta);
node.num = mask;
if ( i == (short)(k_i+0.5) ) {
node.num |= COND_V;
k_i += step_i;
}
if ( !add_elem(&mdd.vdim,&node) ) {
free_vdim(&mdd.vdim);
return FALSE;
}
}
}
mdd.m = m;
mdd.n = n + 1;
if ( !np_init_list(&list_str) ) goto err;
if(!(np_mesh4p(&list_str,&num_np,&mdd,0.))) goto err;
free_vdim(&mdd.vdim);
//
if ( !(num_np = np_end_of_put(&list_str,NP_FIRST,100,listh)) ) goto err;
goto end;
err:
free_vdim(&mdd.vdim);
np_end_of_put(&list_str,NP_CANCEL,0,listh);
num_np = 0;
end:
return num_np;
}
*/
+64
View File
@@ -0,0 +1,64 @@
#include "../../sg.h"
short create_tor_np(lpLISTH listh, sgFloat *par)
{
sgFloat r_n = par[0], r_o = par[1];
short n_n = (short)(par[2]), n_o = (short)(par[3]);
short i, j;
sgFloat d_alpha, d_beta, alpha, beta, fi;
MNODE node;
MESHDD mdd;
NP_STR_LIST list_str;
short num_np = -32767;
short mask;
sgFloat step_j, step_i, k_i, k_j;
init_vdim(&mdd.vdim,sizeof(node));
fi = ( r_n > r_o ) ? (0) : ( acos(r_n/r_o) ) ;
d_alpha = 2 * M_PI / n_n;
d_beta = 2 *(M_PI-fi) / n_o;
step_j = n_n/4.;
step_i = n_o/4.;
for (i = 0, k_i=0.; i < n_o+1; i++ ){
beta = ( i == n_o ) ? ( M_PI + fi ) : ( M_PI - fi - d_beta*i );
if ( i == (short)(k_i+0.5) ) {
mask = COND_U;
k_i += step_i;
}
else mask = 0;
for ( j = 0, k_j=0.; j < n_n+1; j++ ){
alpha = ( j == n_n ) ? ( 0 ) : ( 2*M_PI - d_alpha*j );
node.p.x = (r_n + r_o*cos(beta))*cos(alpha);
node.p.y = (r_n + r_o*cos(beta))*sin(alpha);
node.p.z = r_o*sin(beta);
node.num = mask;
if ( j == (short)(k_j+0.5) ) {
node.num |= COND_V;
k_j += step_j;
}
if ( !add_elem(&mdd.vdim,&node) ) {
free_vdim(&mdd.vdim);
return FALSE;
}
}
}
mdd.m = n_o + 1;
mdd.n = n_n + 1;
if ( !np_init_list(&list_str) ) goto err;
if(!(np_mesh4p(&list_str,&num_np,&mdd,0.))) goto err;
free_vdim(&mdd.vdim);
//
if ( !(num_np = np_end_of_put(&list_str,NP_FIRST,100,listh)) ) goto err;
goto end;
err:
free_vdim(&mdd.vdim);
np_end_of_put(&list_str,NP_CANCEL,0,listh);
num_np = 0;
end:
return num_np;
}