Skip to content

Commit

Permalink
Standardize operator& as the regressive product
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyong committed Oct 6, 2019
1 parent 4a81807 commit 0e29568
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 157 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ float construct_plane(point<float> p)
return engine.compute<scalar<float>>([](auto p)
{
// Contract a cga point back onto itself
// Note that p here contains no actual data! It is just the type that represents a CGA point
// with internal tags that refer to the values contained in the outer scope p (we locally
// shadow the variable name for brevity)
return p >> p;
});
}
Expand Down Expand Up @@ -117,7 +120,7 @@ auto plane = engine.compute<gal::pga::plane<float>>([](auto p1, auto p2, auto p3
// operator^ := Exterior (aka wedge) product
// operator~ := Reversion
// operator! := (Poincare) Dual
// operator| := Join
// operator& := Regressive product (point meet, plane join)
// operator+ := Vector space addition
// operator- := Vector space subtraction
// operator>> := Left Contraction
Expand All @@ -126,9 +129,9 @@ auto plane = engine.compute<gal::pga::plane<float>>([](auto p1, auto p2, auto p3
// Operations that are permitted are chosen because they respect associativity
// in the way you would expect.

// Here we just use the join operator to construct a plane which passes through
// Here we just use the regressive product to construct a plane which passes through
// the three points.
return p1 | p2 | p3;
return p1 & p2 & p3;
});

// The results have now been computed and placed into the constructed plane which
Expand Down
41 changes: 3 additions & 38 deletions src/cga.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,7 @@ namespace cga
// The CGA is a graded algebra with 32 basis elements
using algebra = ga::algebra<metric>;

// Left contraction
// NOTE: We choose this operator because like the left contraction, >> is right associative
template <typename... I, typename... J>
[[nodiscard]] constexpr auto operator>>(::gal::multivector<void, I...> lhs, ::gal::multivector<void, J...> rhs) noexcept
{
return ::gal::detail::product<algebra::contract>(lhs, rhs);
}

template <typename... I, typename... J>
[[nodiscard]] constexpr auto operator^(::gal::multivector<void, I...> lhs, ::gal::multivector<void, J...> rhs) noexcept
{
return ::gal::detail::product<algebra::exterior>(lhs, rhs);
}

template <typename... I, typename... J>
[[nodiscard]] constexpr auto operator*(::gal::multivector<void, I...> lhs, ::gal::multivector<void, J...> rhs) noexcept
{
return ::gal::detail::product<algebra::geometric>(lhs, rhs);
}

template <typename V, typename T>
[[nodiscard]] constexpr auto conjugate(V action, T subject) noexcept
{
return action * subject * ~action;
}

template <typename... I>
[[nodiscard]] constexpr auto operator!(multivector<void, I...> input) noexcept
{
return dual<metric>(input);
}

template <typename M1, typename M2>
[[nodiscard]] constexpr auto operator|(M1 lhs, M2 rhs) noexcept
{
return !(!lhs ^ !rhs);
}
GAL_OPERATORS(algebra)

template <int X, int Y, int Z>
using point_t = multivector<void,
Expand All @@ -61,7 +25,6 @@ namespace cga
term<element<0b1000>, monomial<one_half>, monomial<rational<-(X * X + Y * Y + Z * Z), 2>>>,
term<element<0b10000>, monomial<one_half>, monomial<rational<X * X + Y * Y + Z * Z, 2>>>>;

// TODO: provide representations for points, planes, spheres, flats, etc.
template <typename T = float>
struct alignas(16) point
{
Expand Down Expand Up @@ -126,5 +89,7 @@ namespace cga
return {x, y, z};
}
};

// TODO: provide representations for planes, spheres, flats, etc.
} // namespace cga
} // namespace gal
34 changes: 3 additions & 31 deletions src/ega.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,7 @@ namespace ega

using algebra = ga::algebra<metric>;

// Left contraction
// NOTE: We choose this operator because like the left contraction, >> is right associative
template <typename... I, typename... J>
[[nodiscard]] constexpr auto operator>>(::gal::multivector<void, I...> lhs, ::gal::multivector<void, J...> rhs) noexcept
{
return detail::product<algebra::contract>(lhs, rhs);
}

template <typename... I, typename... J>
[[nodiscard]] constexpr auto operator^(::gal::multivector<void, I...> lhs, ::gal::multivector<void, J...> rhs) noexcept
{
return detail::product<algebra::exterior>(lhs, rhs);
}

template <typename... I, typename... J>
[[nodiscard]] constexpr auto operator*(::gal::multivector<void, I...> lhs, ::gal::multivector<void, J...> rhs) noexcept
{
return detail::product<algebra::geometric>(lhs, rhs);
}

template <typename V, typename T>
[[nodiscard]] constexpr auto conjugate(V versor, T value) noexcept
{
return versor * value * ~versor;
}

template <typename... I>
[[nodiscard]] constexpr auto operator!(multivector<void, I...> input) noexcept
{
return dual<metric>(input);
}
GAL_OPERATORS(algebra)

template <size_t ID>
using t = term<element<0>, monomial<one, generator<tag<ID>>>>;
Expand Down Expand Up @@ -83,5 +53,7 @@ namespace ega
F y;
F z;
};
// TODO: this file isn't as standardized as the other geometries due to the restrictions in R3
// and lack of use
} // namespace ega
} // namespace gal
35 changes: 35 additions & 0 deletions src/ga.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace ga
{
template <typename... T>
using term_t = term<T...>;
using metric_t = Metric;

struct contract
{
Expand Down Expand Up @@ -369,4 +370,38 @@ struct scalar
return {engine.template evaluate<T>(s_e)};
}
};

#define GAL_OPERATORS(Algebra) \
template <typename... I, typename... J> \
[[nodiscard]] constexpr auto operator>>(::gal::multivector<void, I...> lhs, ::gal::multivector<void, J...> rhs) noexcept \
{\
return ::gal::detail::product<Algebra::contract>(lhs, rhs);\
}\
template <typename... I, typename... J>\
[[nodiscard]] constexpr auto operator^(::gal::multivector<void, I...> lhs, ::gal::multivector<void, J...> rhs) noexcept\
{\
return ::gal::detail::product<Algebra::exterior>(lhs, rhs);\
}\
template <typename... I, typename... J>\
[[nodiscard]] constexpr auto operator*(multivector<void, I...> lhs, multivector<void, J...> rhs) noexcept\
{\
return detail::product<Algebra::geometric>(lhs, rhs);\
}\
template <typename V, typename T>\
[[nodiscard]] constexpr auto conjugate(V action, T subject) noexcept\
{\
return action * subject * ~action;\
}\
template <typename... I>\
[[nodiscard]] constexpr auto operator!(multivector<void, I...> input) noexcept\
{\
return dual<Algebra::metric_t>(input);\
}\
template <typename M1, typename M2>\
[[nodiscard]] constexpr auto operator&(M1 lhs, M2 rhs) noexcept\
{\
return !(!lhs ^ !rhs);\
}


} // namespace gal
93 changes: 55 additions & 38 deletions src/pga.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,7 @@ namespace pga
// The PGA is a graded algebra with 16 basis elements
using algebra = ga::algebra<metric>;

// Left contraction
// NOTE: We choose this operator because like the left contraction, >> is right associative
template <typename... I, typename... J>
[[nodiscard]] constexpr auto operator>>(multivector<void, I...> lhs, multivector<void, J...> rhs) noexcept
{
return detail::product<algebra::contract>(lhs, rhs);
}

template <typename... I, typename... J>
[[nodiscard]] constexpr auto operator^(multivector<void, I...> lhs, multivector<void, J...> rhs) noexcept
{
return detail::product<algebra::exterior>(lhs, rhs);
}

template <typename... I, typename... J>
[[nodiscard]] constexpr auto operator*(multivector<void, I...> lhs, multivector<void, J...> rhs) noexcept
{
return detail::product<algebra::geometric>(lhs, rhs);
}

template <typename V, typename T>
[[nodiscard]] constexpr auto conjugate(V action, T subject) noexcept
{
return action * subject * ~action;
}

template <typename... I>
[[nodiscard]] constexpr auto operator!(multivector<void, I...> input) noexcept
{
return dual<metric>(input);
}

template <typename M1, typename M2>
[[nodiscard]] constexpr auto operator|(M1 lhs, M2 rhs) noexcept
{
return !(!lhs ^ !rhs);
}
GAL_OPERATORS(algebra)

using e = multivector<void, term<element<0>, monomial<one>>>;
using e0 = multivector<void, term<element<0b1>, monomial<one>>>;
Expand All @@ -76,6 +40,7 @@ namespace pga
struct alignas(16) plane
{
using value_t = T;
constexpr static size_t size = 4;

template <size_t ID>
using type = multivector<void,
Expand Down Expand Up @@ -124,6 +89,7 @@ namespace pga
struct alignas(16) point
{
using value_t = T;
constexpr static size_t size = 3;

template <size_t ID>
using type = multivector<void,
Expand Down Expand Up @@ -174,6 +140,57 @@ namespace pga
}
};

// TODO: directions
// Lines in P^3 are defined using Plücker coordinates: https://en.wikipedia.org/wiki/Plücker_coordinates
template <typename T>
struct line
{

};

template <typename T>
struct alignas(16) direction
{
using value_t = T;
constexpr static size_t size = 3;

template <size_t ID>
using type = multivector<void,
term<element<0b111>, monomial<minus_one, generator<tag<ID, 2>>>>, // -z
term<element<0b1011>, monomial<one, generator<tag<ID, 1>>>>, // y
term<element<0b1101>, monomial<minus_one, generator<tag<ID, 0>>>>>; // -x

T x;
T y;
T z;

[[nodiscard]] constexpr const T& operator[](size_t index) const noexcept
{
return *(reinterpret_cast<const T*>(this) + index);
}

[[nodiscard]] constexpr T& operator[](size_t index) noexcept
{
return *(reinterpret_cast<T*>(this) + index);
}

template <typename Engine, typename... I>
[[nodiscard]] constexpr static direction<T> convert(Engine& engine, multivector<void, I...> mv) noexcept
{
auto x_e = -extract<0b1101>(mv);
auto y_e = extract<0b1011>(mv);
auto z_e = -extract<0b111>(mv);

auto&& [x, y, z] = engine.template evaluate_terms<T>(x_e, y_e, z_e);

return {x, y, z};
}
};

// Produces a rotor
template <typename T>
[[nodiscard]] constexpr auto exp(T theta, T x, T y, T z)
{

}
} // namespace pga
} // namespace gal
Loading

0 comments on commit 0e29568

Please sign in to comment.