5 #ifndef _SPICA_VECTOR3D_DETAIL_H_
6 #define _SPICA_VECTOR3D_DETAIL_H_
32 if (sscanf(str.c_str(),
"%lf %lf %lf", &x ,&y, &z) == 3 ||
33 sscanf(str.c_str(),
"%lf, %lf, %lf", &x, &y, &z) == 3) {
37 }
else if (sscanf(str.c_str(),
"%lf", &x) == 1) {
42 FatalError(
"Cannot parse string \"%s\" for Vector3d", str.c_str());
68 Vector3_<T>::operator+=(
const Vector3_<T>& v) {
77 Vector3_<T>::operator+=(
double x) {
86 Vector3_<T>::operator-=(
const Vector3_<T>& v) {
93 Vector3_<T>::operator-=(
double x) {
100 Vector3_<T>::operator-()
const {
101 return { -x_, -y_, -z_ };
125 Assertion(v.x_ != 0 && v.y_ != 0 && v.z_ != 0,
"Zero division");
135 Assertion(s != 0.0,
"Zero division");
136 return this->operator*=(1.0 / s);
141 Assertion(i >= 0 && i <= 2,
"Index out of bounds!!");
142 if (i == 0)
return x_;
143 if (i == 1)
return y_;
148 bool Vector3_<T>::operator==(
const Vector3_<T>& v)
const {
149 return (this->x_ == v.x_ && this->y_ == v.y_ && this->z_ == v.z_);
153 bool Vector3_<T>::operator!=(
const Vector3_<T>& v)
const {
154 return !this->operator==(v);
158 T Vector3_<T>::dot(
const Vector3_<T>& v)
const {
159 return this->x_ * v.x_ + this->y_ * v.y_ + this->z_ * v.z_;
163 T Vector3_<T>::dot(
const Vector3_<T>& v1,
164 const Vector3_<T>& v2) {
170 Vector3_<T>::cross(
const Vector3_<T>& v)
const {
171 T x = this->y_ * v.z_ - this->z_ * v.y_;
172 T y = this->z_ * v.x_ - this->x_ * v.z_;
173 T z = this->x_ * v.y_ - this->y_ * v.x_;
179 Vector3_<T>::cross(
const Vector3_<T>& v1,
180 const Vector3_<T>& v2) {
185 double Vector3_<T>::norm()
const {
186 return ::sqrt(this->squaredNorm());
190 double Vector3_<T>::squaredNorm()
const {
191 return this->dot(*
this);
196 Vector3_<T>::normalized()
const {
197 Vector3_<T> ret = *
this;
204 Vector3_<T>::normalize(
const Vector3_<T>& v) {
205 return v.normalized();
210 Vector3_<T>::multiply(
const Vector3_<T>& v)
const {
216 Vector3_<T>::minimum(
const Vector3_<T>& v1,
217 const Vector3_<T>& v2) {
218 T x = std::min(v1.x_, v2.x_);
219 T y = std::min(v1.y_, v2.y_);
220 T z = std::min(v1.z_, v2.z_);
226 Vector3_<T>::maximum(
const Vector3_<T>& v1,
227 const Vector3_<T>& v2) {
228 T x = std::max(v1.x(), v2.x());
229 T y = std::max(v1.y(), v2.y());
230 T z = std::max(v1.z(), v2.z());
235 T Vector3_<T>::get(
int d)
const {
236 Assertion(0 <= d && d <= 2,
"Dimension must be between 0 and 2");
237 if (d == 0)
return x_;
238 if (d == 1)
return y_;
239 if (d == 2)
return z_;
244 std::string Vector3_<T>::toString()
const {
245 std::stringstream ss;
247 ss << std::setprecision(8);
248 ss <<
"(" << x_ <<
", " << y_ <<
", " << z_ <<
")";
249 return std::move(ss.str());
341 std::ostream& operator<<(std::ostream& os,
347 #endif // _SPICA_VECTOR3D_DETAIL_H_
Vector3_()
The Vector3d constructor.
Definition: vector3d_detail.h:16
Three-dimensional vector.
Definition: core.hpp:56
Vector3_ & operator/=(const Vector3_ &v)
Element-wise division.
Definition: vector3d_detail.h:124
virtual ~Vector3_()
The Vector3d destructor.
Definition: vector3d_detail.h:54
Vector3_ & operator*=(const Vector3_ &v)
Element-wise multiplication.
Definition: vector3d_detail.h:106