Ejemplo n.º 1
0
void PlanetWidget::mouseReleaseEvent (QMouseEvent*) {
	if (!mouseMoving) {
		pointSelected(conjugate(rotation_to_default(planetHandler->planet())) * activeRenderer->to_coordinates(vector(mousePosition)));
	}
	mouseMoving = false;
}
Ejemplo n.º 2
0
/*!
    Rotates \a vector with this quaternion to produce a new vector
    in 3D space.  The following code:

    \code
    QVector3D result = q.rotatedVector(vector);
    \endcode

    is equivalent to the following:

    \code
    QVector3D result = (q * QQuaternion(0, vector) * q.conjugate()).vector();
    \endcode
*/
QVector3D QQuaternion::rotatedVector(const QVector3D& vector) const
{
    return (*this * QQuaternion(0, vector) * conjugate()).vector();
}
Ejemplo n.º 3
0
glm::vec4 quat::operator *(const glm::vec4& other) const
{
    auto result = *this * quat(other) * conjugate(*this);

    return glm::vec4(result.x, result.y, result.z, 1.0f);
}
Ejemplo n.º 4
0
 // Optimized invert for unit quaternions
 void
 Quaternion::invertForUnit ()
 {
   conjugate ();
 }
Ejemplo n.º 5
0
    Quaternion Quaternion::inverse() const
    {
         return conjugate() / length2();
	}
Ejemplo n.º 6
0
static int quaternion_conjugate(lua_State* L)
{
	LuaStack stack(L);
	stack.push_quaternion(conjugate(stack.get_quaternion(1)));
	return 1;
}
void
yypower(void)
{
	int n;

	p2 = pop();
	p1 = pop();

	// both base and exponent are rational numbers?

	if (isrational(p1) && isrational(p2)) {
		push(p1);
		push(p2);
		qpow();
		return;
	}

	// both base and exponent are either rational or double?

	if (isnum(p1) && isnum(p2)) {
		push(p1);
		push(p2);
		dpow();
		return;
	}

	if (istensor(p1)) {
		power_tensor();
		return;
	}

	if (p1 == symbol(E) && car(p2) == symbol(LOG)) {
		push(cadr(p2));
		return;
	}

	if (p1 == symbol(E) && isdouble(p2)) {
		push_double(exp(p2->u.d));
		return;
	}

	//	1 ^ a		->	1

	//	a ^ 0		->	1

	if (equal(p1, one) || iszero(p2)) {
		push(one);
		return;
	}

	//	a ^ 1		->	a

	if (equal(p2, one)) {
		push(p1);
		return;
	}

	//	(a * b) ^ c	->	(a ^ c) * (b ^ c)

	if (car(p1) == symbol(MULTIPLY)) {
		p1 = cdr(p1);
		push(car(p1));
		push(p2);
		power();
		p1 = cdr(p1);
		while (iscons(p1)) {
			push(car(p1));
			push(p2);
			power();
			multiply();
			p1 = cdr(p1);
		}
		return;
	}

	//	(a ^ b) ^ c	->	a ^ (b * c)

	if (car(p1) == symbol(POWER)) {
		push(cadr(p1));
		push(caddr(p1));
		push(p2);
		multiply();
		power();
		return;
	}

	//	(a + b) ^ n	->	(a + b) * (a + b) ...

	if (expanding && isadd(p1) && isnum(p2)) {
		push(p2);
		n = pop_integer();
        // this && n != 0x80000000 added by DDC
        // as it's not always the case that 0x80000000
        // is negative
		if (n > 1 && n != 0x80000000) {
			power_sum(n);
			return;
		}
	}

	//	sin(x) ^ 2n -> (1 - cos(x) ^ 2) ^ n

	if (trigmode == 1 && car(p1) == symbol(SIN) && iseveninteger(p2)) {
		push_integer(1);
		push(cadr(p1));
		cosine();
		push_integer(2);
		power();
		subtract();
		push(p2);
		push_rational(1, 2);
		multiply();
		power();
		return;
	}

	//	cos(x) ^ 2n -> (1 - sin(x) ^ 2) ^ n

	if (trigmode == 2 && car(p1) == symbol(COS) && iseveninteger(p2)) {
		push_integer(1);
		push(cadr(p1));
		sine();
		push_integer(2);
		power();
		subtract();
		push(p2);
		push_rational(1, 2);
		multiply();
		power();
		return;
	}

	// complex number? (just number, not expression)

	if (iscomplexnumber(p1)) {

		// integer power?

		// n will be negative here, positive n already handled

		if (isinteger(p2)) {

			//               /        \  n
			//         -n   |  a - ib  |
			// (a + ib)   = | -------- |
			//              |   2   2  |
			//               \ a + b  /

			push(p1);
			conjugate();
			p3 = pop();
			push(p3);
			push(p3);
			push(p1);
			multiply();
			divide();
			push(p2);
			negate();
			power();
			return;
		}

		// noninteger or floating power?

		if (isnum(p2)) {

#if 1			// use polar form
			push(p1);
			mag();
			push(p2);
			power();
			push_integer(-1);
			push(p1);
			arg();
			push(p2);
			multiply();
			push(symbol(PI));
			divide();
			power();
			multiply();

#else			// use exponential form
			push(p1);
			mag();
			push(p2);
			power();
			push(symbol(E));
			push(p1);
			arg();
			push(p2);
			multiply();
			push(imaginaryunit);
			multiply();
			power();
			multiply();
#endif
			return;
		}
	}

	if (simplify_polar())
		return;

	push_symbol(POWER);
	push(p1);
	push(p2);
	list(3);
}
Ejemplo n.º 8
0
Archivo: quat.hpp Proyecto: maseek/HP
	Vec3<A> rotate( const Vec3<A>& vec, const Quat<A>& quat )
	{
		auto rotated = conjugate( quat ) * Quat < A > {vec.x, vec.y, vec.z, 1.0f} *quat;
		return Vec3 < A > {rotated.x, rotated.y, rotated.z};
	};
 void quaternion_t::inverse()
 {
     conjugate();
     *this /= norm();
 }
quaternion reciprocal(quaternion m)
{
  quaternion out;
  out = rmult(1/norm2(m),conjugate(m));
  return out;
}
Ejemplo n.º 11
0
// Inverse
Quaternion Quaternion::inverse()
{
	return conjugate().scalar(1/norm());
}
Ejemplo n.º 12
0
real do_ewald(t_inputrec *ir,
              rvec x[],        rvec f[],
              real chargeA[],  real chargeB[],
              rvec box,
              t_commrec *cr,   int natoms,
              matrix lrvir,    real ewaldcoeff,
              real lambda,     real *dvdlambda,
              struct gmx_ewald_tab_t *et)
{
    real     factor     = -1.0/(4*ewaldcoeff*ewaldcoeff);
    real     scaleRecip = 4.0*M_PI/(box[XX]*box[YY]*box[ZZ])*ONE_4PI_EPS0/ir->epsilon_r; /* 1/(Vol*e0) */
    real    *charge, energy_AB[2], energy;
    rvec     lll;
    int      lowiy, lowiz, ix, iy, iz, n, q;
    real     tmp, cs, ss, ak, akv, mx, my, mz, m2, scale;
    gmx_bool bFreeEnergy;

    if (cr != NULL)
    {
        if (PAR(cr))
        {
            gmx_fatal(FARGS, "No parallel Ewald. Use PME instead.\n");
        }
    }


    if (!et->eir) /* allocate if we need to */
    {
        snew(et->eir, et->kmax);
        for (n = 0; n < et->kmax; n++)
        {
            snew(et->eir[n], natoms);
        }
        snew(et->tab_xy, natoms);
        snew(et->tab_qxyz, natoms);
    }

    bFreeEnergy = (ir->efep != efepNO);

    clear_mat(lrvir);

    calc_lll(box, lll);
    tabulateStructureFactors(natoms, x, et->kmax, et->eir, lll);

    for (q = 0; q < (bFreeEnergy ? 2 : 1); q++)
    {
        if (!bFreeEnergy)
        {
            charge = chargeA;
            scale  = 1.0;
        }
        else if (q == 0)
        {
            charge = chargeA;
            scale  = 1.0 - lambda;
        }
        else
        {
            charge = chargeB;
            scale  = lambda;
        }
        lowiy        = 0;
        lowiz        = 1;
        energy_AB[q] = 0;
        for (ix = 0; ix < et->nx; ix++)
        {
            mx = ix*lll[XX];
            for (iy = lowiy; iy < et->ny; iy++)
            {
                my = iy*lll[YY];
                if (iy >= 0)
                {
                    for (n = 0; n < natoms; n++)
                    {
                        et->tab_xy[n] = cmul(et->eir[ix][n][XX], et->eir[iy][n][YY]);
                    }
                }
                else
                {
                    for (n = 0; n < natoms; n++)
                    {
                        et->tab_xy[n] = cmul(et->eir[ix][n][XX], conjugate(et->eir[-iy][n][YY]));
                    }
                }
                for (iz = lowiz; iz < et->nz; iz++)
                {
                    mz  = iz*lll[ZZ];
                    m2  = mx*mx+my*my+mz*mz;
                    ak  = exp(m2*factor)/m2;
                    akv = 2.0*ak*(1.0/m2-factor);
                    if (iz >= 0)
                    {
                        for (n = 0; n < natoms; n++)
                        {
                            et->tab_qxyz[n] = rcmul(charge[n], cmul(et->tab_xy[n],
                                                                    et->eir[iz][n][ZZ]));
                        }
                    }
                    else
                    {
                        for (n = 0; n < natoms; n++)
                        {
                            et->tab_qxyz[n] = rcmul(charge[n], cmul(et->tab_xy[n],
                                                                    conjugate(et->eir[-iz][n][ZZ])));
                        }
                    }

                    cs = ss = 0;
                    for (n = 0; n < natoms; n++)
                    {
                        cs += et->tab_qxyz[n].re;
                        ss += et->tab_qxyz[n].im;
                    }
                    energy_AB[q]  += ak*(cs*cs+ss*ss);
                    tmp            = scale*akv*(cs*cs+ss*ss);
                    lrvir[XX][XX] -= tmp*mx*mx;
                    lrvir[XX][YY] -= tmp*mx*my;
                    lrvir[XX][ZZ] -= tmp*mx*mz;
                    lrvir[YY][YY] -= tmp*my*my;
                    lrvir[YY][ZZ] -= tmp*my*mz;
                    lrvir[ZZ][ZZ] -= tmp*mz*mz;
                    for (n = 0; n < natoms; n++)
                    {
                        /*tmp=scale*ak*(cs*tab_qxyz[n].im-ss*tab_qxyz[n].re);*/
                        tmp       = scale*ak*(cs*et->tab_qxyz[n].im-ss*et->tab_qxyz[n].re);
                        f[n][XX] += tmp*mx*2*scaleRecip;
                        f[n][YY] += tmp*my*2*scaleRecip;
                        f[n][ZZ] += tmp*mz*2*scaleRecip;
#if 0
                        f[n][XX] += tmp*mx;
                        f[n][YY] += tmp*my;
                        f[n][ZZ] += tmp*mz;
#endif
                    }
                    lowiz = 1-et->nz;
                }
                lowiy = 1-et->ny;
            }
        }
    }

    if (!bFreeEnergy)
    {
        energy = energy_AB[0];
    }
    else
    {
        energy      = (1.0 - lambda)*energy_AB[0] + lambda*energy_AB[1];
        *dvdlambda += scaleRecip*(energy_AB[1] - energy_AB[0]);
    }

    lrvir[XX][XX] = -0.5*scaleRecip*(lrvir[XX][XX]+energy);
    lrvir[XX][YY] = -0.5*scaleRecip*(lrvir[XX][YY]);
    lrvir[XX][ZZ] = -0.5*scaleRecip*(lrvir[XX][ZZ]);
    lrvir[YY][YY] = -0.5*scaleRecip*(lrvir[YY][YY]+energy);
    lrvir[YY][ZZ] = -0.5*scaleRecip*(lrvir[YY][ZZ]);
    lrvir[ZZ][ZZ] = -0.5*scaleRecip*(lrvir[ZZ][ZZ]+energy);

    lrvir[YY][XX] = lrvir[XX][YY];
    lrvir[ZZ][XX] = lrvir[XX][ZZ];
    lrvir[ZZ][YY] = lrvir[YY][ZZ];

    energy *= scaleRecip;

    return energy;
}
Ejemplo n.º 13
0
//
//  Find the complex roots of a complex polynomial       Poly
//  The order is                                         Maxpow
//  The result will be in the array                      Root
//
void HighPrecisionComplexPolynom::Polyrootc(cln::cl_N* Poly, int Maxpow, cln::cl_N* Root) {
  
  int  ord, pow, fnd, pov, maxp;

  cln::cl_N poly[1+Maxpow], polc[1+Maxpow], coef[1+Maxpow], coen[1+Maxpow];


  // Put coefficients in an array

  for(pow = 0; pow < Maxpow+1; pow++) { 
    poly[pow] = As(cln::cl_N)(Poly[pow]);
    coef[pow] = As(cln::cl_N)(Poly[pow]); 
  }

  for(pow = 0; pow < Maxpow+1; pow++) {
    polc[pow] = As(cln::cl_N)(complex(ZERO,ZERO));
  }

  polc[0] = As(cln::cl_N)(complex(ONE,ZERO));
  fnd = -1;

  // Loop for finding all roots

  for(ord = 0; ord < Maxpow; ord++) {
    fnd++;
    pov = Maxpow-fnd;

    if(fnd < Maxpow) {
      if(LogLevel>4) {
	printf(" root number: %d\n",fnd+1);
      }

      if((ord%2 == 1) && (Maxpow%2 == 0) && (false)) {
	Root[fnd] = As(cln::cl_N)(conjugate(Root[fnd-1]));
 	cln::cl_N val0 = EvalPoly(poly, Maxpow, Root[fnd]);
	
 	if(LogLevel>3) {
 	  printf("root = %f +i*%f\n", double_approx(realpart(Root[fnd])), double_approx(imagpart(Root[fnd])));
 	  printf("value at root: %f +i*%f\n", double_approx(realpart(val0)), double_approx(imagpart(val0))); 
 	}
      }
      else {
	Root[fnd] = Lasolv(poly,pov, complex(ONE,ONE), 150);
      }

      for(pow = Maxpow; pow > 0; pow--) {
	polc[pow] = polc[pow-1]-Root[fnd]*polc[pow];
      }

      polc[0] = -Root[fnd]*polc[pow];

      // Divide the polynomial by the root

      maxp = Maxpow-fnd-1;
      coen[maxp] = coef[maxp+1];

      for(pow = maxp-1; pow > -1; pow--) {
	coen[pow] = coef[pow+1]+Root[fnd]*coen[pow+1];
      }

      for(pow = 0; pow < maxp+1; pow++) {
	coef[pow] = coen[pow];
	poly[pow] = coef[pow]; 
      } 
    }

    else {
      break;
    }
  }

// Compare input with product of root factors

  for(pow = 0; pow < Maxpow+1; pow++) {
    polc[pow] = Poly[pow]-poly[0]*polc[pow];
  }

  if(LogLevel>4) {
    printf("control polynomial should be close to zero:\n");

    for(pow = 0; pow < Maxpow+1; pow++) {
      printf("  x^{%d}\n",pow);
      printf("%1.15f +i*%1.15f\n",double_approx(realpart(polc[pow])), double_approx(imagpart(polc[pow])));
    } 
  }
}
Ejemplo n.º 14
0
//
//  Find a root of a complex polynomial by Laguerre iteration.
//
//  The polynomial is                                    Poly
//  The order is                                         Maxpow
//
//  The precision:                                       Digit
cln::cl_N HighPrecisionComplexPolynom::Lasolv(cln::cl_N* Poly, int Maxpow, cln::cl_N root, int itemax) {
   int  pow, ite;
   
   root = complex(ZERO,ZERO);
   
   cln::cl_F angl, small = As(cln::cl_F)(expt(cln::cl_float(0.1,clnDIGIT),DIGIT/2));

   cln::cl_N dif1[Maxpow], dif2[Maxpow-1];
   cln::cl_N val0, val, val1, val2, denp, denm, las1, las2, sqrv;
   //   cln::cl_N root;
    for(pow = 0; pow < Maxpow; pow++)
    dif1[pow] = (pow+1)*Poly[pow+1];

    for(pow = 0; pow < Maxpow-1; pow++)
    dif2[pow] = (pow+1)*dif1[pow+1];

// The maximal allowed number of iterations is set here;
// this can be chosen larger, but 100 usually suffices

//   root = As(cln::cl_N)(complex(ZERO,ZERO));
   val0 = EvalPoly(Poly,Maxpow,root);

// Iteration

    for(ite = 0; ite < itemax; ite++)
     { 
       val = val0;
       val1 = EvalPoly(dif1,Maxpow-1,root);
       val2 = EvalPoly(dif2,Maxpow-2,root);

       sqrv = (Maxpow-1)*((Maxpow-1)*val1*val1-Maxpow*val0*val2);
       angl = HALF*cln::cl_float(phase(sqrv),clnDIGIT);
       sqrv = sqrt(abs(sqrv))*complex(cos(angl),sin(angl));
       denp = val1+sqrv;
       denm = val1-sqrv;

        if(denp == complex(ZERO,ZERO))
        root = root-Maxpow*val0/denm;

        else
         {  if(denm == complex(ZERO,ZERO))
            root = root-Maxpow*val0/denp;

            else
             { las1 = -Maxpow*val0/denp;
               las2 = -Maxpow*val0/denm;

                if(realpart(las1*conjugate(las1)) <
                   realpart(las2*conjugate(las2)))
                root = root+las1;

                else
                root = root+las2; } }

//  Look whether the root is good enough

       val0 = EvalPoly(Poly,Maxpow,root);

        if(abs(val0) == ZERO || (abs(val0) < small) && abs(val0/val) > 0.7) {
            if(LogLevel>4) { 
	       printf("Laguerre iterations: %d\n", ite);
               printf("root = %f +i* %f\n", double_approx(realpart(root)), double_approx(imagpart(root)));
               printf("value at root: %f +i* %f\n", double_approx(realpart(val0)), double_approx(imagpart(val0))); 
	    }

           break; 
	} 
    }

    if(ite >= itemax) {
      printf("Laguerre iteration did not converge\n");
      exit(5);
    }

   return root;

}
Ejemplo n.º 15
0
 t4 = magE*t2;
 t3 = tan(t4);
 t5 = t3*t3;
 t6 = t5+1.0;
 t7 = 1.0/(magN*magN);
 t8 = OP_l_18_c_18_r_*t2*t6;
 t15 = OP_l_17_c_18_r_*magE*t6*t7;
 t9 = t8-t15;
 t10 = t2*t6*t9;
 t11 = OP_l_18_c_17_r_*t2*t6;
 t16 = OP_l_17_c_17_r_*magE*t6*t7;
 t12 = t11-t16;
 t17 = magE*t6*t7*t12;
 t13 = R_DECL+t10-t17;
 t14 = 1.0/t13;
 t18 = conjugate(magE);
 t19 = conjugate(magN);
 t21 = 1.0/t19;
 t22 = t18*t21;
 t20 = tan(t22);
 t23 = t20*t20;
 t24 = t23+1.0;
 Kfusion[0] = t14*(OP_l_1_c_18_r_*t2*t6-OP_l_1_c_17_r_*magE*t6*t7);
 Kfusion[1] = t14*(OP_l_2_c_18_r_*t2*t6-OP_l_2_c_17_r_*magE*t6*t7);
 Kfusion[2] = t14*(OP_l_3_c_18_r_*t2*t6-OP_l_3_c_17_r_*magE*t6*t7);
 Kfusion[3] = t14*(OP_l_4_c_18_r_*t2*t6-OP_l_4_c_17_r_*magE*t6*t7);
 Kfusion[4] = t14*(OP_l_5_c_18_r_*t2*t6-OP_l_5_c_17_r_*magE*t6*t7);
 Kfusion[5] = t14*(OP_l_6_c_18_r_*t2*t6-OP_l_6_c_17_r_*magE*t6*t7);
 Kfusion[6] = t14*(OP_l_7_c_18_r_*t2*t6-OP_l_7_c_17_r_*magE*t6*t7);
 Kfusion[7] = t14*(OP_l_8_c_18_r_*t2*t6-OP_l_8_c_17_r_*magE*t6*t7);
 Kfusion[8] = t14*(OP_l_9_c_18_r_*t2*t6-OP_l_9_c_17_r_*magE*t6*t7);
Ejemplo n.º 16
0
/// Computes the inverse orientation represented by this quaternion in place
QUAT& QUAT::invert()
{
  conjugate();
  return *this;
}
Ejemplo n.º 17
0
 Quaternion<T> quat_conjugate(const Quaternion<T>& q)
 {
     return conjugate(q);
 }
Ejemplo n.º 18
0
/// Computes the inverse orientation of a quaternion
QUAT QUAT::invert(const QUAT& q)
{
  return conjugate(q);
}
Ejemplo n.º 19
0
t2 = magE*magE;
t3 = magN*magN;
t4 = t2+t3;
t5 = P[16][16]*t2;
t6 = P[17][17]*t3;
t7 = t2*t2;
t8 = R_DECL*t7;
t9 = t3*t3;
t10 = R_DECL*t9;
t11 = R_DECL*t2*t3*2.0;
t14 = P[16][17]*magE*magN;
t15 = P[17][16]*magE*magN;
t12 = t5+t6+t8+t10+t11-t14-t15;
t13 = 1.0/t12;
t16 = conjugate(magE);
t17 = conjugate(magN);
t18 = t16*t16;
t19 = t17*t17;
t20 = t18+t19;
t21 = 1.0/t20;
A0[0][0] = -t4*t13*(P[0][16]*magE-P[0][17]*magN);
A0[1][0] = -t4*t13*(P[1][16]*magE-P[1][17]*magN);
A0[2][0] = -t4*t13*(P[2][16]*magE-P[2][17]*magN);
A0[3][0] = -t4*t13*(P[3][16]*magE-P[3][17]*magN);
A0[4][0] = -t4*t13*(P[4][16]*magE-P[4][17]*magN);
A0[5][0] = -t4*t13*(P[5][16]*magE-P[5][17]*magN);
A0[6][0] = -t4*t13*(P[6][16]*magE-P[6][17]*magN);
A0[7][0] = -t4*t13*(P[7][16]*magE-P[7][17]*magN);
A0[8][0] = -t4*t13*(P[8][16]*magE-P[8][17]*magN);
A0[9][0] = -t4*t13*(P[9][16]*magE-P[9][17]*magN);
A0[10][0] = -t4*t13*(P[10][16]*magE-P[10][17]*magN);
Ejemplo n.º 20
0
/// Multiplies inv(q) by <b>this</b> and returns the result
QUAT QUAT::operator/(const QUAT& q) const
{
  return conjugate(q) * (*this);
}
Ejemplo n.º 21
0
inline vec3 rotate(const Quaternion& q, const vec3& v) {
	return vec3((q * Quaternion(vec4(v)) * conjugate(q)).val);
}
Ejemplo n.º 22
0
/// Negates the value of each of the x, y, and z coordinates in place
void QUAT::conjugate()
{
  *this = conjugate(*this);
}
Ejemplo n.º 23
0
Vector3f Quaternion::operator*(const Vector3f &vec) const
{
	Vector3f v = vec.normal();
	Quaternion quat = *this * (Quaternion(v.getX(), v.getY(), v.getZ(), 0.0) * conjugate());
	return Vector3f(quat.x, quat.y, quat.z);
}
Ejemplo n.º 24
0
AABB3d TransformSequence::compute_motion_segment_bbox(
    const AABB3d&       bbox,
    const Transformd&   from,
    const Transformd&   to) const
{
    //
    // Reference:
    //
    //   http://gruenschloss.org/motion-blur/motion-blur.pdf page 11.
    //

    // Parameters.
    const double MinLength = Pi / 2.0;
    const double RootEps = 1.0e-6;
    const double GrowEps = 1.0e-4;
    const size_t MaxIterations = 100;

    // Start with the bounding box at 'from'.
    const AABB3d from_bbox = from.to_parent(bbox);
    AABB3d motion_bbox = from_bbox;

    // Setup an interpolator between 'from' and 'to'.
    TransformInterpolatord interpolator;
    if (!interpolator.set_transforms(from, to))
        return motion_bbox;

    // Compute the scalings at 'from' and 'to'.
    const Vector3d s0 = interpolator.get_s0();
    const Vector3d s1 = interpolator.get_s1();

    // Compute the relative rotation between 'from' and 'to'.
    const Quaterniond q =
        interpolator.get_q1() * conjugate(interpolator.get_q0());

    // Transform the relative rotation to the axis-angle representation.
    Vector3d axis;
    double angle;
    q.extract_axis_angle(axis, angle);
    if (axis.z < 0.0)
        angle = -angle;

    // The following code only makes sense if there is a rotation component.
    if (angle == 0.0)
        return motion_bbox;

    // Compute the rotation required to align the rotation axis with the Z axis.
    const Vector3d Z(0.0, 0.0, 1.0);
    const Vector3d perp = cross(Z, axis);
    const double perp_norm = norm(perp);
    Transformd axis_to_z;
    if (perp_norm == 0.0)
        axis_to_z = Transformd::identity();
    else
    {
        const Vector3d v = perp / perp_norm;
        const double sin_a = clamp(perp_norm, -1.0, 1.0);
        const double cos_a = sqrt(1.0 - sin_a * sin_a);
        axis_to_z.set_local_to_parent(Matrix4d::make_rotation(v, cos_a, +sin_a));
        axis_to_z.set_parent_to_local(Matrix4d::make_rotation(v, cos_a, -sin_a));
    }

    // Build the linear scaling functions Sx(theta), Sy(theta) and Sz(theta).
    const LinearFunction sx(1.0, s1.x / s0.x, angle);
    const LinearFunction sy(1.0, s1.y / s0.y, angle);
    const LinearFunction sz(1.0, s1.z / s0.z, angle);

    // Consider each corner of the bounding box. Notice an important trick here:
    // we take advantage of the way AABB::compute_corner() works to only iterate
    // over the four corners at Z=min instead of over all eight corners since we
    // anyway transform the rotation to be aligned with the Z axis.
    for (size_t c = 0; c < 4; ++c)
    {
        // Compute the position of this corner at 'from'.
        const Vector3d corner = axis_to_z.point_to_local(from_bbox.compute_corner(c));
        const Vector2d corner2d(corner.x, corner.y);

        // Build the trajectory functions x(theta) and y(theta).
        const TrajectoryX tx(sx, sy, corner2d);
        const TrajectoryY ty(sx, sy, corner2d);

        // Find all the rotation angles at which this corner is an extremum and update the motion bounding box.
        RootHandler root_handler(tx, ty, sz, axis_to_z, corner, motion_bbox);
        find_multiple_roots_newton(
            Bind<TrajectoryX>(tx, &TrajectoryX::d),
            Bind<TrajectoryX>(tx, &TrajectoryX::dd),
            0.0, angle,
            MinLength,
            RootEps,
            MaxIterations,
            root_handler);
        find_multiple_roots_newton(
            Bind<TrajectoryY>(ty, &TrajectoryY::d),
            Bind<TrajectoryY>(ty, &TrajectoryY::dd),
            0.0, angle,
            MinLength,
            RootEps,
            MaxIterations,
            root_handler);
    }

    motion_bbox.robust_grow(GrowEps);

    return motion_bbox;
}
Ejemplo n.º 25
0
quat inverse(quat q) {
	return conjugate(q) / norm(q);
}
Ejemplo n.º 26
0
	static quat invert(quat &q) {

		return conjugate(q) / lengthSqr(q);

	}
Ejemplo n.º 27
0
glm::vec3 quat::operator *(const glm::vec3& other) const
{
    auto result = *this * quat(other) * conjugate(*this);

    return glm::vec3(result.x, result.y, result.z);
}
Ejemplo n.º 28
0
Quaternion Quaternion::inverse()
{
	return conjugate().divideByFloat(norm());	// conjugate() / norm();
}
Ejemplo n.º 29
0
	inline Vector3 transform(const Transform& transform, const Vector3& point)
	{
		return (conjugate(transform.orientation) * (transform.position - point)) / transform.scale;
	}
Ejemplo n.º 30
0
	// negate
	inline quat operator-(const quat &q) {
		return conjugate(q);
	}