static int orient_find_neighbor(int *utag, int ublk1 ,int ublk2, int mat[3][3]) { int ublk_match; int ibnd; int ibnd_match; int mat_temp1[3][3]; int mat_temp2[3][3]; BndMapping_t *ubnd; ubnd = umap[ublk1].bnd; ublk_match = -1; ibnd_match = -1; for (ibnd = 0; ibnd < umap[ublk1].nbnd; ibnd++) { if ((ubnd[ibnd].orientation[0] != 0) && (utag[ubnd[ibnd].iblk] == 0)) { ublk_match = ubnd[ibnd].iblk; ibnd_match = ibnd; if (ublk_match == ublk2) break; } } if (ublk_match >= 0) { utag[ublk_match] = 1; MAT_ZERO(mat_temp1); MAT_ZERO(mat_temp2); MAT_EXPAND(mat_temp1,ubnd[ibnd_match].orientation); MAT_X_MAT(mat_temp2,mat_temp1,mat); MAT_COPY(mat,mat_temp2); } return(ublk_match); }
static int orient_getmatrix(BndMapping_t *ubnd1, int ublk1, BndMapping_t *ubnd2, int ublk2, int mat[3][3]) { int flag = 0; int ideg1, ideg2; int jdeg1, jdeg2; int kdeg1, kdeg2; int maxflg1, maxflg2; int offt; int offn; int side; side = 0; ideg1 = 1; jdeg1 = 1; kdeg1 = 1; ideg2 = 1; jdeg2 = 1; kdeg2 = 1; if (ubnd1->imax != ubnd1->imin) ideg1 = 0; if (ubnd1->jmax != ubnd1->jmin) jdeg1 = 0; if (ubnd1->kmax != ubnd1->kmin) kdeg1 = 0; if (ubnd2->imax != ubnd2->imin) ideg2 = 0; if (ubnd2->jmax != ubnd2->jmin) jdeg2 = 0; if (ubnd2->kmax != ubnd2->kmin) kdeg2 = 0; side = 3 - (ideg1 + jdeg1 + kdeg1); if ((ndims == 2) && (side == 1)) { flag = 1; MAT_ZERO(mat); offt = 1; if ((ubnd1->ndx[1] - ubnd1->ndx[0]) < 0) offt *= -1 ; if ((ubnd2->ndx[1] - ubnd2->ndx[0]) < 0) offt *= -1 ; maxflg1 = 0; maxflg2 = 0; if ((ideg1) && (ubnd1->imax == umap[ublk1].imax)) maxflg1 = 1; if ((jdeg1) && (ubnd1->jmax == umap[ublk1].jmax)) maxflg1 = 1; if ((ideg2) && (ubnd2->imax == umap[ublk2].imax)) maxflg2 = 1; if ((jdeg2) && (ubnd2->jmax == umap[ublk2].jmax)) maxflg2 = 1; offn = 1; if (maxflg1 == maxflg2) offn = -1; mat[0][0] = offn * ideg1 * ideg2 + offt * ( 1 - ideg1 ) * ( 1 - ideg2 ); mat[0][1] = offn * jdeg1 * ideg2 + offt * ( 1 - jdeg1 ) * ( 1 - ideg2 ); mat[1][0] = offn * ideg1 * jdeg2 + offt * ( 1 - ideg1 ) * ( 1 - jdeg2 ); mat[1][1] = offn * jdeg1 * jdeg2 + offt * ( 1 - jdeg1 ) * ( 1 - jdeg2 ); mat[2][2] = 1; } else if ((ndims == 3) && (side == 2)) { flag = 1; MAT_ZERO(mat); MAT_IDENT(mat); } return(flag); }
int bn_mat_scale_about_pt(mat_t mat, const point_t pt, const double scale) { mat_t xlate; mat_t s; mat_t tmp; MAT_IDN(xlate); MAT_DELTAS_VEC_NEG(xlate, pt); MAT_IDN(s); if (ZERO(scale)) { MAT_ZERO(mat); return -1; /* ERROR */ } s[15] = 1 / scale; bn_mat_mul(tmp, s, xlate); MAT_DELTAS_VEC(xlate, pt); bn_mat_mul(mat, xlate, tmp); return 0; /* OK */ }
/** * Returns - * -1 failure * 0 OK. *r points to nmgregion that holds this tessellation. */ int rt_hyp_tess(struct nmgregion **r, struct model *m, struct rt_db_internal *ip, const struct rt_tess_tol *ttol, const struct bn_tol *tol) { fastf_t c, dtol, f, mag_a, mag_h, ntol, r1, r2, r3, cprime; fastf_t **ellipses = NULL; fastf_t theta_new; int *pts_dbl, face, i, j, nseg; int jj, nell; mat_t invRoS; mat_t SoR; struct rt_hyp_internal *iip; struct hyp_specific *xip; struct rt_pt_node *pos_a, *pos_b, *pts_a, *pts_b; struct shell *s; struct faceuse **outfaceuses = NULL; struct faceuse *fu_top; struct loopuse *lu; struct edgeuse *eu; struct vertex *vertp[3]; struct vertex ***vells = (struct vertex ***)NULL; vect_t A, Au, B, Bu, Hu, V; struct bu_ptbl vert_tab; MAT_ZERO(invRoS); MAT_ZERO(SoR); RT_CK_DB_INTERNAL(ip); iip = (struct rt_hyp_internal *)ip->idb_ptr; RT_HYP_CK_MAGIC(iip); xip = hyp_internal_to_specific(iip); /* * make sure hyp description is valid */ /* compute |A| |H| */ mag_a = MAGSQ(xip->hyp_Au); /* should already be unit vector */ mag_h = MAGNITUDE(xip->hyp_H); c = xip->hyp_c; cprime = c / mag_h; r1 = xip->hyp_r1; r2 = xip->hyp_r2; r3 = r1 / c; /* Check for |H| > 0, |A| == 1, r1 > 0, r2 > 0, c > 0 */ if (NEAR_ZERO(mag_h, RT_LEN_TOL) || !NEAR_EQUAL(mag_a, 1.0, RT_LEN_TOL) || r1 <= 0.0 || r2 <= 0.0 || c <= 0.) { return 1; /* BAD */ } /* Check for A.H == 0 */ f = VDOT(xip->hyp_Au, xip->hyp_H) / mag_h; if (! NEAR_ZERO(f, RT_DOT_TOL)) { return 1; /* BAD */ } /* make unit vectors in A, H, and HxA directions */ VMOVE(Hu, xip->hyp_H); VUNITIZE(Hu); VMOVE(Au, xip->hyp_Au); VCROSS(Bu, Hu, Au); dtol = primitive_get_absolute_tolerance(ttol, 2.0 * r2); /* To ensure normal tolerance, remain below this angle */ if (ttol->norm > 0.0) ntol = ttol->norm; else /* tolerate everything */ ntol = M_PI; /* * build hyp from 2 hyperbolas */ /* calculate major axis hyperbola */ BU_ALLOC(pts_a, struct rt_pt_node); /* set base, center, and top points */ pos_a = pts_a; VSET(pos_a->p, sqrt((mag_h*mag_h) * (c*c) + (r1*r1)), 0, -mag_h); BU_ALLOC(pos_a->next, struct rt_pt_node); pos_a = pos_a->next; VSET(pos_a->p, r1, 0, 0); BU_ALLOC(pos_a->next, struct rt_pt_node); pos_a = pos_a->next; VSET(pos_a->p, sqrt((mag_h*mag_h) * (c*c) + (r1*r1)), 0, mag_h); pos_a->next = NULL; /* refine hyp according to tolerances */ i = 1; { point_t p0, p1, p2; fastf_t mm, len, dist, ang0, ang2; vect_t v01, v02; /* vectors from p0->p1 and p0->p2 */ vect_t nLine, nHyp; struct rt_pt_node *add; while (i) { pos_a = pts_a; i = 0; while (pos_a->next) { VMOVE(p0, pos_a->p); VMOVE(p2, pos_a->next->p); /* either X or Y will be zero; so adding handles either case */ mm = (p2[Z] - p0[Z]) / ((p2[X]+p2[Y]) - (p0[X]+p0[Y])); if (!ZERO(p0[X])) { p1[X] = fabs(mm*c*r1) / sqrt(mm*mm*c*c - 1.0); p1[Y] = 0.0; p1[Z] = sqrt(p1[X]*p1[X] - r1*r1) / c; } else { p1[X] = 0.0; p1[Y] = fabs(mm*r2*r2*c) / sqrt(mm*mm*r2*r2*c*c - r1*r1); p1[Z] = (r3/r2) * sqrt(p1[Y]*p1[Y] - r2*r2); } if (p0[Z] + p2[Z] < 0) p1[Z] = -p1[Z]; VSUB2(v01, p1, p0); VSUB2(v02, p2, p0); VUNITIZE(v02); len = VDOT(v01, v02); VSCALE(v02, v02, len); VSUB2(nLine, v01, v02); dist = MAGNITUDE(nLine); VUNITIZE(nLine); VSET(nHyp, p0[X] / (r1*r1), p0[Y] / (r2*r2), p0[Z] / (r3*r3)); VUNITIZE(nHyp); ang0 = fabs(acos(VDOT(nLine, nHyp))); VSET(nHyp, p2[X] / (r1*r1), p2[Y] / (r2*r2), p2[Z] / (r3*r3)); VUNITIZE(nHyp); ang2 = fabs(acos(VDOT(nLine, nHyp))); if (dist > dtol || ang0 > ntol || ang2 > ntol) { /* split segment */ BU_ALLOC(add, struct rt_pt_node); VMOVE(add->p, p1); add->next = pos_a->next; pos_a->next = add; pos_a = pos_a->next; i = 1; } pos_a = pos_a->next; } } } /* calculate minor axis hyperbola */ BU_ALLOC(pts_b, struct rt_pt_node); pos_a = pts_a; pos_b = pts_b; i = 0; while (pos_a) { pos_b->p[Z] = pos_a->p[Z]; pos_b->p[X] = 0; pos_b->p[Y] = r2 * sqrt(pos_b->p[Z] * pos_b->p[Z]/(r3*r3) + 1.0); pos_a = pos_a->next; if (pos_a) { BU_ALLOC(pos_b->next, struct rt_pt_node); pos_b = pos_b->next; } else { pos_b->next = NULL; } i++; }