[gatest] Implement and use multi-vector reverse

This gives the resultant point the correct sign.  Though the projective
divide would take care of the sign, this makes reading the point a
little less confusing (still need to sort out automatic blade reversals
for the likes of e31).
This commit is contained in:
Bill Currie 2023-05-24 18:25:47 +09:00
parent 42b0608e65
commit b9cff7aae0
3 changed files with 20 additions and 1 deletions

View file

@ -89,7 +89,7 @@ main ()
MultiVector *origin = [alg group:3 values:origin_vals];
MultiVector *line = [plane1 wedge:plane2];
MultiVector *point = [[line dot:origin] product:line];
MultiVector *point = [[line dot:origin] product:[line reverse]];
printf ("plane1:%@\nplane2:%@\nline:%@\norigin:%@\n", plane1, plane2, line, origin);
printf ("point:%@\n", point);

View file

@ -23,6 +23,7 @@
-(MultiVector *) wedge:(MultiVector *) rhs;
-(MultiVector *) dot:(MultiVector *) rhs;
-(MultiVector *) dual;
-(MultiVector *) reverse;
@end
#endif//__multivector_h

View file

@ -198,4 +198,22 @@ static MultiVector *new_mv (Algebra *algebra, BasisLayout *layout)
}
return dual;
}
-(MultiVector *) reverse
{
MultiVector *reverse = new_mv (algebra, nil);
for (int i = 0; i < num_components; i++) {
if (!components[i]) {
continue;
}
double c = components[i];
BasisBlade *b = [layout bladeAt:i];
int g = [b grade];
unsigned mask = [b mask];
double s = g & 2 ? -1 : 1;//FIXME do in BasisBlade?
int ind = [layout bladeIndex:mask];
reverse.components[ind] += s * c;
}
return reverse;
}
@end