void Compute_Rotation_Transform (TRANSFORM *transform, const VECTOR vector) { register DBL cosx, cosy, cosz, sinx, siny, sinz; MATRIX Matrix; VECTOR Radian_Vector; VScale (Radian_Vector, vector, M_PI_180); MIdentity (transform->matrix); cosx = cos (Radian_Vector[X]); sinx = sin (Radian_Vector[X]); cosy = cos (Radian_Vector[Y]); siny = sin (Radian_Vector[Y]); cosz = cos (Radian_Vector[Z]); sinz = sin (Radian_Vector[Z]); (transform->matrix) [1][1] = cosx; (transform->matrix) [2][2] = cosx; (transform->matrix) [1][2] = sinx; (transform->matrix) [2][1] = 0.0 - sinx; MTranspose (transform->inverse, transform->matrix); MIdentity (Matrix); Matrix [0][0] = cosy; Matrix [2][2] = cosy; Matrix [0][2] = 0.0 - siny; Matrix [2][0] = siny; MTimesA (transform->matrix, Matrix); MTranspose (Matrix); MTimesB (Matrix, transform->inverse); MIdentity (Matrix); Matrix [0][0] = cosz; Matrix [1][1] = cosz; Matrix [0][1] = sinz; Matrix [1][0] = 0.0 - sinz; MTimesA (transform->matrix, Matrix); MTranspose (Matrix); MTimesB (Matrix, transform->inverse); }
void Compute_Axis_Rotation_Transform (TRANSFORM *transform, const VECTOR AxisVect, DBL angle) { DBL cosx, sinx; VECTOR V1; VNormalize(V1, AxisVect); MIdentity(transform->matrix); cosx = cos(angle); sinx = sin(angle); transform->matrix[0][0] = V1[X] * V1[X] + cosx * (1.0 - V1[X] * V1[X]); transform->matrix[0][1] = V1[X] * V1[Y] * (1.0 - cosx) + V1[Z] * sinx; transform->matrix[0][2] = V1[X] * V1[Z] * (1.0 - cosx) - V1[Y] * sinx; transform->matrix[1][0] = V1[X] * V1[Y] * (1.0 - cosx) - V1[Z] * sinx; transform->matrix[1][1] = V1[Y] * V1[Y] + cosx * (1.0 - V1[Y] * V1[Y]); transform->matrix[1][2] = V1[Y] * V1[Z] * (1.0 - cosx) + V1[X] * sinx; transform->matrix[2][0] = V1[X] * V1[Z] * (1.0 - cosx) + V1[Y] * sinx; transform->matrix[2][1] = V1[Y] * V1[Z] * (1.0 - cosx) - V1[X] * sinx; transform->matrix[2][2] = V1[Z] * V1[Z] + cosx * (1.0 - V1[Z] * V1[Z]); MTranspose(transform->inverse, transform->matrix); }
static void Transform_Quadric(OBJECT *Object, TRANSFORM *Trans) { QUADRIC *Quadric=(QUADRIC *)Object; MATRIX Quadric_Matrix, Transform_Transposed; Quadric_To_Matrix (Quadric, Quadric_Matrix); MTimesB (Trans->inverse, Quadric_Matrix); MTranspose (Transform_Transposed, Trans->inverse); MTimesA (Quadric_Matrix, Transform_Transposed); Matrix_To_Quadric (Quadric_Matrix, Quadric); Recompute_BBox(&Object->BBox, Trans); }
bool clickIntersection(AAContext* aaContext, POINT point, float *intersectionM) { UserData *userData = (UserData*) aaContext->userData; float rayDir[4]; float viewDir[4]; RECT rect; MMatrix P; MMatrix iP; ScreenToClient(aaContext->hWnd, &point); GetClientRect(aaContext->hWnd, &rect); viewDir[0] = 2.0f*point.x / (float) (rect.right-rect.left)-1.0f; viewDir[1] = 2.0f*(1.0f-point.y / (float )(rect.bottom-rect.top))-1.0f; viewDir[2] = 1.0f; viewDir[3] = 1.0f; MViewRotation(&iP, userData->eye); MTranspose(&P, &iP); MMap(rayDir, &P, viewDir); return IntersectSphere(userData->sphere, rayDir, userData->eye, intersectionM); }
// Posterior distribution for "theta" void beta_gp(int *n, int *r, int *T, int *rT, int *p, double *prior_mu, double *prior_sig, double *Qeta, double *X, double *o, int *constant, double *betap) { int t, l, i, n1, p1, r1, T1, col; n1 =*n; p1 =*p; r1 =*r; T1 =*T; col =*constant; double *del, *chi, *ot1, *X1, *tX1, *out, *tX1QX1, *tX1Qo, *det, *mu, *I; del = (double *) malloc((size_t)((p1*p1)*sizeof(double))); chi = (double *) malloc((size_t)((p1*col)*sizeof(double))); ot1 = (double *) malloc((size_t)((n1*col)*sizeof(double))); X1 = (double *) malloc((size_t)((n1*p1)*sizeof(double))); tX1 = (double *) malloc((size_t)((n1*p1)*sizeof(double))); out = (double *) malloc((size_t)((n1*p1)*sizeof(double))); tX1QX1 = (double *) malloc((size_t)((p1*p1)*sizeof(double))); tX1Qo = (double *) malloc((size_t)((p1*col)*sizeof(double))); det = (double *) malloc((size_t)((col)*sizeof(double))); mu = (double *) malloc((size_t)((p1*col)*sizeof(double))); I = (double *) malloc((size_t)((p1*p1)*sizeof(double))); for(i=0; i<p1*p1; i++){ del[i] = 0.0; } for(i=0; i<p1; i++){ chi[i] = 0.0; } for(l=0; l<r1; l++){ for(t=0; t<T1; t++){ extract_X(t, l, n, r, T, p, X, X1); // n x p MTranspose(X1, p, n, tX1); // p x n MProd(X1, p, n, Qeta, n, out); // n x p MProd(out, p, n, tX1, p, tX1QX1); // pxp MAdd(del, p, p, tX1QX1, del); // pxp extract_alt2(l, t, n, rT, T, o, ot1); // n x 1 MProd(ot1, constant, n, Qeta, n, out); // n x 1 MProd(out, constant, n, tX1, p, tX1Qo); // p x 1 MAdd(chi, p, constant, tX1Qo, chi); // p x 1 } } IdentityM(p, I); for(i=0; i<p1*p1; i++){ del[i] = del[i] + I[i]*(1.0/prior_sig[0]); } free(I); for(i=0; i<p1; i++){ chi[i] = chi[i] + prior_mu[0]/prior_sig[0]; } MInv(del, del, p, det); MProd(chi, constant, p, del, p, mu); // p x 1 mvrnormal(constant, mu, del, p, betap); free(del); free(chi); free(ot1); free(X1); free(tX1); free(out); free(tX1QX1); free(tX1Qo); free(det); free(mu); return; }