+/*
+ * 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.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
inline double I_xx(struct Inertia s)
{
+ if (s.mass <= 0.) return 0.;
return (s.sxx - s.sx*s.sx/s.mass)/s.mass;
}
inline double I_xy(struct Inertia s)
{
+ if (s.mass <= 0.) return 0.;
return (s.sxy - s.sx*s.sy/s.mass)/s.mass;
}
inline double I_yy(struct Inertia s)
{
+ if (s.mass <= 0.) return 0.;
return (s.syy - s.sy*s.sy/s.mass)/s.mass;
}
inline double I_rad(struct Inertia s)
{
- return sqrt(I_xx(s)+I_yy(s));
+ double ixx = I_xx(s), iyy = I_yy(s);
+ if (ixx+iyy <= 0.) return 0.;
+ return sqrt(ixx+iyy);
}
inline double I_det(struct Inertia s)
{
- if (s.mass == 0.) return 0.;
double ixx = I_xx(s), iyy = I_yy(s), ixy = I_xy(s);
+ if (s.mass <= 0.) return 0.;
+ if (ixx+iyy <= 0.) return 0.;
return 4*(ixx*iyy-ixy*ixy)/(ixx+iyy)/(ixx+iyy);
}