celestia/src/celmath/ellipsoid.h

65 lines
1.5 KiB
C
Raw Permalink Normal View History

2002-02-09 14:39:05 -07:00
// ellipsoid.h
//
// Copyright (C) 2002-2008, Chris Laurel <claurel@shatters.net>
2002-02-09 14:39:05 -07:00
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
#pragma once
2002-02-09 14:39:05 -07:00
#include <Eigen/Core>
2002-02-09 14:39:05 -07:00
2019-05-16 15:51:11 -06:00
namespace celmath
{
template<class T>
class Ellipsoid
2002-02-09 14:39:05 -07:00
{
public:
/*! Default Ellipsoid constructor. Create a unit sphere centered
* at the origin.
*/
Ellipsoid() :
center(Eigen::Matrix<T, 3, 1>::Zero()),
axes(Eigen::Matrix<T, 3, 1>::Ones())
{
}
/*! Created an ellipsoid with the specified semiaxes, centered
* at the origin.
*/
Ellipsoid(const Eigen::Matrix<T, 3, 1>& _axes) :
center(Eigen::Matrix<T, 3, 1>::Zero()),
axes(_axes)
{
}
/*! Create an ellipsoid with the specified center and semiaxes.
*/
Ellipsoid(const Eigen::Matrix<T, 3, 1>& _center,
const Eigen::Matrix<T, 3, 1>& _axes) :
center(_center),
axes(_axes)
{
}
/*! Test whether the point p lies inside the ellipsoid.
*/
bool contains(const Eigen::Matrix<T, 3, 1>& p) const
{
Eigen::Matrix<T, 3, 1> v = p - center;
v = v.cwise() / axes;
return v * v <= static_cast<T>(1);
}
2002-02-09 14:39:05 -07:00
public:
Eigen::Matrix<T, 3, 1> center;
Eigen::Matrix<T, 3, 1> axes;
2002-02-09 14:39:05 -07:00
};
using Ellipsoidf = Ellipsoid<float>;
using Ellipsoidd = Ellipsoid<double>;
2020-03-29 01:35:03 -06:00
} // namespace celmath