23 #ifndef BASE_DATA_TYPE_H 24 #define BASE_DATA_TYPE_H 27 #include "SimTKcommon.h" 28 #include "SimTKmath.h" 29 #include "scalar_functions.h" 42 template <
int N,
class T>
51 for (
int i = 0; i < N; ++i)
57 for (
int i = 0; i < N; ++i)
64 for (
int i = 0; i < N; ++i)
71 for (
int i = 0; i < N; ++i)
76 explicit SVec<N, T>(
const SimTK::Vec<N, S> &source)
78 for (
int i = 0; i < N; ++i)
95 T &operator[](
int index)
97 assert(index >= 0 && index < N);
101 const T &operator[](
int index)
const 103 assert(index >= 0 && index < N);
107 bool nonzero(
void)
const 109 for (
int i = 0; i < N; ++i)
118 for (
int i = 0; i < N; ++i)
119 res = res && (v[i] == b[i]);
126 for (
int i = 0; i < N; ++i)
127 res = res || (v[i] != b[i]);
134 for (
int i = 0; i < N; ++i)
146 for (
int i = 0; i < N; ++i)
160 for (
int i = 0; i < N; ++i)
174 for (
int i = 0; i < N; ++i)
188 for (
int i = 0; i < N; ++i)
197 for (
int i = 0; i < N; ++i)
198 negative.v[i] = -v[i];
213 for (
int i = 0; i < N; ++i)
227 for (
int i = 0; i < N; ++i)
235 for (
int i = 0; i < N; ++i)
236 componentwise_product[i] = v[i] * w.v[i];
237 return componentwise_product;
242 for (
int i = 0; i < N; ++i)
256 for (
int i = 0; i < N; ++i)
264 for (
int i = 0; i < N; ++i)
265 componentwise_divide[i] = v[i] / w.v[i];
266 return componentwise_divide;
270 template <
int N,
class T>
271 std::ostream &operator<<(std::ostream &out, const SVec<N, T> &v)
274 for (
int i = 1; i < N; ++i)
280 template <
int N,
class T>
281 std::istream &operator>>(std::istream &in, SVec<N, T> &v)
284 for (
int i = 1; i < N; ++i)
290 using Vec2i = SVec<2, int>;
291 using Vec3i = SVec<3, int>;
294 using Vec2u = SVec<2, size_t>;
295 using Vec3u = SVec<3, size_t>;
298 using Real = SimTK::Real;
303 using SimTK::Infinity;
304 using SimTK::TinyReal;
305 constexpr
size_t MaxSize_t = std::numeric_limits<size_t>::max();
308 using Vec2d = SimTK::Vec2;
309 using Vec3d = SimTK::Vec3;
312 using Mat2d = SimTK::Mat22;
313 using Mat3d = SimTK::Mat33;
315 using SymMat2d = SimTK::SymMat22;
316 using SymMat3d = SimTK::SymMat33;
319 template <
typename T>
322 static constexpr
int value = std::numeric_limits<int>::max();
327 static constexpr
int value = 0;
332 static constexpr
int value = 1;
337 static constexpr
int value = 1;
342 static constexpr
int value = 2;
347 static constexpr
int value = 2;
352 static constexpr
int value = 3;
359 const bool positiveDirection =
true;
360 const bool negativeDirection =
false;
363 template <
typename VecType>
367 VecType first, second;
370 BaseBoundingBox() : first(VecType(0)), second(VecType(0)), dimension_(VecType(0).size()){};
371 BaseBoundingBox(
const VecType &lower_bound,
const VecType &upper_bound)
372 : first(lower_bound), second(upper_bound),
373 dimension_(lower_bound.size()){};
375 bool checkContain(
const VecType &point)
377 bool is_contain =
true;
378 for (
int i = 0; i < dimension_; ++i)
380 if (point[i] < first[i] || point[i] > second[i])
393 return bb1.first == bb2.first && bb1.second == bb2.second ? true :
false;
396 template <
class BoundingBoxType>
397 BoundingBoxType getIntersectionOfBoundingBoxes(
const BoundingBoxType &bb1,
const BoundingBoxType &bb2)
400 int dimension = bb1.dimension_;
402 BoundingBoxType bb(bb1);
404 for (
int i = 0; i < dimension; ++i)
405 if (bb2.first[i] > bb1.second[i] || bb2.second[i] < bb1.first[i])
406 std::runtime_error(
"getIntersectionOfBoundingBoxes: no overlap!");
408 for (
int i = 0; i < dimension; ++i)
411 if (bb1.first[i] < bb2.first[i] && bb2.first[i] < bb1.second[i])
412 bb.first[i] = bb2.first[i];
414 if (bb1.second[i] > bb2.second[i] && bb2.second[i] > bb1.first[i])
415 bb.second[i] = bb2.second[i];
427 Real angle_, cosine_angle_, sine_angle_;
431 : angle_(angle), cosine_angle_(std::cos(angle)), sine_angle_(std::sin(angle)){};
437 return Vec2d(origin[0] * cosine_angle_ - origin[1] * sine_angle_,
438 origin[1] * cosine_angle_ + origin[0] * sine_angle_);
443 return Vec2d(target[0] * cosine_angle_ + target[1] * sine_angle_,
444 target[1] * cosine_angle_ - target[0] * sine_angle_);
461 explicit Transform2d(
const Vec2d &translation) : rotation_(
Rotation2d(0)), translation_(translation){};
463 : rotation_(rotation), translation_(translation){};
497 #endif // BASE_DATA_TYPE_H Definition: base_data_type.h:43
Rotation Coordinate transform (around the origin) in 2D with an angle.
Definition: base_data_type.h:425
Vec2d xformFrameVecToBase(const Vec2d &origin)
Definition: base_data_type.h:435
Vec2d xformBaseVecToFrame(const Vec2d &target)
Definition: base_data_type.h:441
Definition: base_data_type.h:364
Definition: base_data_type.h:320
Definition: solid_body_supplementary.cpp:9