Skip to content

Commit

Permalink
fixed normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
gravitino committed Mar 11, 2015
1 parent c55f482 commit 89d5ffb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 86 deletions.
55 changes: 2 additions & 53 deletions blending.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,6 @@

int main () {

/*
dualquat<double> Q (0, 0, 0, 0, 0, 0, 0, 0); Q=Q.exp(); Q.print();
dualquat<double> T (1, 0, 0, 0, 0, 1, 1, 1); T=T.N(); T.print();
auto A = T^Q; A.print();
std::cout << A.lognorm() << std::endl;
auto B = T^T^Q; B.print();
std::cout << B.lognorm() << std::endl;
auto C = T^T^T^Q; B.print();
std::cout << C.lognorm() << std::endl;
auto D = T^T^T^T^Q; D.print();
std::cout << D.lognorm() << std::endl;
*/

/*
dualquat<double> Q (0, M_PI, M_PI, M_PI, 0, 0, 0, 0); Q=Q.exp(); Q.print();
dualquat<double> T (1, 0, 0, 0, 0, 0, 0, 0); T=T.N(); T.print();
auto A = T^Q; A.print();
std::cout << A.lognorm() << std::endl;
auto B = T^Q^Q; B.print();
std::cout << B.lognorm() << std::endl;
auto C = T^Q^Q^Q; B.print();
std::cout << C.lognorm() << std::endl;
auto D = T^Q^Q^Q^Q; D.print();
std::cout << D.lognorm() << std::endl;
*/

/*
dualquat<double> Q (0, M_PI, M_PI, M_PI, 0, 0, 0, 0); Q=Q.exp(); Q.print();
dualquat<double> T (1, 0, 0, 0, 0, 1, 1, 1); T=T.N(); T.print();
auto A = T^Q; A.print();
std::cout << A.lognorm() << std::endl;
auto B = T^T^Q^Q; B.print();
std::cout << B.lognorm() << std::endl;
auto C = T^T^T^Q^Q^Q; B.print();
std::cout << C.lognorm() << std::endl;
auto D = T^T^T^T^Q^Q^Q^Q; D.print();
std::cout << D.lognorm() << std::endl;
*/

using namespace average;

std::mt19937 engine;
Expand All @@ -68,7 +17,7 @@ int main () {
std::vector<quat<double>> quats;

for (size_t i = 0; i < N; i++)
quats.push_back( q0^quat<double>(1+dist(engine), dist(engine),
quats.push_back( q0*quat<double>(1+dist(engine), dist(engine),
dist(engine), dist(engine)).N());

QLA(quats).print();
Expand All @@ -87,7 +36,7 @@ int main () {
std::vector<dualquat<double>> Quats;

for (size_t i = 0; i < N; i++)
Quats.push_back(Q0^dualquat<double>(1+dist(engine), dist(engine),
Quats.push_back(Q0*dualquat<double>(1+dist(engine), dist(engine),
dist(engine), dist(engine),
dist(engine), dist(engine),
dist(engine), dist(engine)).N());
Expand Down
50 changes: 25 additions & 25 deletions dualquat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ struct quat {
return *this;
}

quat<value_t> operator^(const quat<value_t>& other) const {
quat<value_t> operator*(const quat<value_t>& other) const {
return quat<value_t>(w*other.w-x*other.x-y*other.y-z*other.z,
w*other.x+other.w*x+y*other.z-z*other.y,
w*other.y+other.w*y+z*other.x-x*other.z,
w*other.z+other.w*z+x*other.y-y*other.x);
}

quat<value_t>& operator^=(const quat<value_t>& other) {
*this = (*this)^other;
quat<value_t>& operator*=(const quat<value_t>& other) {
*this = (*this)*other;
return *this;
}

Expand Down Expand Up @@ -102,7 +102,7 @@ struct quat {
size_t i = 1;

while (pow.dot(pow) > eps) {
pow ^= (*this)/i++;
pow *= (*this)/i++;
sum += pow;
}

Expand Down Expand Up @@ -144,7 +144,7 @@ struct quat {
}

value_t logdist (const quat<value_t>& other) const {
const auto& difference = ((*this)^(other.C())).log();
const auto& difference = ((*this)*(other.C())).log();
return difference.dot(difference);
}

Expand Down Expand Up @@ -219,18 +219,18 @@ struct dualquat {
}

// TODO: expand this
dualquat<value_t> operator^(const dualquat<value_t>& other) const {
dualquat<value_t> operator*(const dualquat<value_t>& other) const {

const auto& a = real();
const auto& A = dual();
const auto& b = other.real();
const auto& B = other.dual();

return dualquat<value_t>(a^b, (a^B)+(A^b));
return dualquat<value_t>(a*b, (a*B)+(A*b));
}

dualquat<value_t>& operator^=(const dualquat<value_t>& other) {
*this = (*this)^other;
dualquat<value_t>& operator*=(const dualquat<value_t>& other) {
*this = (*this)*other;
return *this;
}

Expand All @@ -254,12 +254,12 @@ struct dualquat {
const value_t qQ = w*W+x*X+y*Y+z*Z;
const value_t invqq = 1.0/qq;
const value_t invsq = 1.0/std::sqrt(qq);
const value_t alpha = qQ*invqq*invqq;
const value_t alpha = qQ*invqq*invsq;

return dualquat<value_t>(w*invsq, x*invsq,
y*invsq, z*invsq,
W*invqq-w*alpha, X*invqq-x*alpha,
Y*invqq-y*alpha, Z*invqq-z*alpha);
W*invsq-w*alpha, X*invsq-x*alpha,
Y*invsq-y*alpha, Z*invsq-z*alpha);
}

dualquat<value_t> C() const {
Expand Down Expand Up @@ -322,7 +322,7 @@ struct dualquat {
size_t i = 1;

while (pow.dot(pow) > eps) {
pow ^= (*this)/i++;
pow *= (*this)/i++;
sum += pow;
}

Expand Down Expand Up @@ -372,13 +372,13 @@ struct dualquat {

value_t kinnorm () const {
const auto& Omega = real().log();
const auto& Veloc = dual()^real().C();
const auto& Veloc = dual()*real().C();
return Omega.dot(Omega)+Veloc.dot(Veloc);
}

value_t kilnorm () const {
const auto& Omega = real().log();
const auto& Veloc = dual()^real().C();
const auto& Veloc = dual()*real().C();
return Omega.dot(Omega)+2*Veloc.dot(Omega);
}

Expand All @@ -395,7 +395,7 @@ struct dualquat {
}

value_t logdist (const dualquat<value_t>& other) const {
const auto& difference = ((*this)^(other.C())).log();
const auto& difference = ((*this)*(other.C())).log();
return difference.dot(difference);
}

Expand Down Expand Up @@ -432,7 +432,7 @@ quat<value_t> QIA (const std::vector<quat<value_t>>& quats) {
auto logmean = [&]() {
quat<value_t> avg(0, 0, 0, 0);
for (size_t i = 0; i < quats.size(); i++)
avg += (b.C()^quats[i]).log();
avg += (b.C()*quats[i]).log();
return avg/quats.size();
};

Expand All @@ -441,7 +441,7 @@ quat<value_t> QIA (const std::vector<quat<value_t>>& quats) {

for(;;){

b ^= x.exp();
b *= x.exp();
auto xnew = logmean();

const auto newnorm = xnew.dot(xnew);
Expand Down Expand Up @@ -482,7 +482,7 @@ quat<value_t> QIB (const std::vector<quat<value_t>>& quats,
auto logmean = [&]() {
quat<value_t> avg(0, 0, 0, 0);
for (size_t i = 0; i < quats.size(); i++)
avg += ((b.C())^quats[i]).log()*weights[i];
avg += ((b.C())*quats[i]).log()*weights[i];
return avg;
};

Expand All @@ -491,7 +491,7 @@ quat<value_t> QIB (const std::vector<quat<value_t>>& quats,

for(;;){

b ^= x.exp();
b *= x.exp();
auto xnew = logmean();

const auto newnorm = xnew.dot(xnew);
Expand All @@ -514,7 +514,7 @@ dualquat<value_t> DLA (const std::vector<dualquat<value_t>>& quats) {
for (size_t i = 0; i < quats.size(); i++)
result += quats[i];

return (result/quats.size()).N();
return (result).N();
}

template <class value_t>
Expand All @@ -525,7 +525,7 @@ dualquat<value_t> DIA (const std::vector<dualquat<value_t>>& quats) {
auto logmean = [&]() {
dualquat<value_t> avg(0, 0, 0, 0, 0, 0, 0, 0);
for (size_t i = 0; i < quats.size(); i++)
avg += (b.C()^quats[i]).log();
avg += (b.C()*quats[i]).log();
return avg/quats.size();
};

Expand All @@ -534,7 +534,7 @@ dualquat<value_t> DIA (const std::vector<dualquat<value_t>>& quats) {

for(;;){

b ^= x.numexp();
b *= x.numexp();
auto xnew = logmean();

const auto newnorm = xnew.dot(xnew);
Expand Down Expand Up @@ -577,7 +577,7 @@ dualquat<value_t> DIB (const std::vector<dualquat<value_t>>& quats,
auto logmean = [&]() {
dualquat<value_t> avg(0, 0, 0, 0, 0, 0, 0, 0);
for (size_t i = 0; i < quats.size(); i++)
avg += ((b.C())^quats[i]).log()*weights[i];
avg += ((b.C())*quats[i]).log()*weights[i];
return avg;
};

Expand All @@ -586,7 +586,7 @@ dualquat<value_t> DIB (const std::vector<dualquat<value_t>>& quats,

for(;;){

b ^= x.numexp();
b *= x.numexp();
auto xnew = logmean();

const auto newnorm = xnew.dot(xnew);
Expand Down
16 changes: 8 additions & 8 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,28 @@ int main () {
}

// check left inverse
R = (Q.I()^Q)-quat<double>();
R = (Q.I()*Q)-quat<double>();
if (R.dot(R) > THRESHOLD) {
std::cout << "left inverse" << R.dot(R) << std::endl;
R.print();
}

// check right inverse
R = (Q^Q.I())-quat<double>();
R = (Q*Q.I())-quat<double>();
if (R.dot(R) > THRESHOLD) {
std::cout << "right inverse" << R.dot(R) << std::endl;
R.print();
}

// check left conjugate inverse
R = (Q.C()^Q)-quat<double>();
R = (Q.C()*Q)-quat<double>();
if (R.dot(R) > THRESHOLD) {
std::cout << "left conjugate inverse" << R.dot(R) << std::endl;
R.print();
}

// check right conjugate inverse
R = (Q^Q.C())-quat<double>();
R = (Q*Q.C())-quat<double>();
if (R.dot(R) > THRESHOLD) {
std::cout << "right conjugate inverse" << R.dot(R) << std::endl;
R.print();
Expand Down Expand Up @@ -93,28 +93,28 @@ int main () {
}

// check left inverse
R = (Q.I()^Q)-dualquat<double>();
R = (Q.I()*Q)-dualquat<double>();
if (R.dot(R) > THRESHOLD) {
std::cout << "left inverse" << R.dot(R) << std::endl;
R.print();
}

// check right inverse
R = (Q^Q.I())-dualquat<double>();
R = (Q*Q.I())-dualquat<double>();
if (R.dot(R) > THRESHOLD) {
std::cout << "right inverse" << R.dot(R) << std::endl;
R.print();
}

// check left conjugate inverse
R = (Q.C()^Q)-dualquat<double>();
R = (Q.C()*Q)-dualquat<double>();
if (R.dot(R) > THRESHOLD) {
std::cout << "left conjugate inverse" << R.dot(R) << std::endl;
R.print();
}

// check right conjugate inverse
R = (Q^Q.C())-dualquat<double>();
R = (Q*Q.C())-dualquat<double>();
if (R.dot(R) > THRESHOLD) {
std::cout << "right conjugate inverse" << R.dot(R) << std::endl;
R.print();
Expand Down

0 comments on commit 89d5ffb

Please sign in to comment.