# Changeset 1020

Ignore:
Timestamp:
07/24/20 21:44:10 (3 months ago)
Message:

Added double Pt3D::minComponent() and maxComponent()

Location:
cpp/frams/util
Files:
2 edited

Unmodified
Added
Removed
• ## cpp/frams/util/3d.cpp

 r375 // This file is a part of Framsticks SDK.  http://www.framsticks.com/ // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski. // Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski. // See LICENSE.txt for details. #include #include "3d.h" #include // std::min(), std::max() Pt3D operator+(const Pt3D &p1, const Pt3D &p2) { return Pt3D(p1.x + p2.x, p1.y + p2.y, p1.z + p2.z); } double Pt3D::operator()() const { double q = x*x + y*y + z*z; double q = x * x + y * y + z * z; if (q < 0) { if (report_errors) logPrintf("Pt3D", "operator()", LOG_ERROR, "sqrt(%g): domain error", q); return 0; } return sqrt(q); double dy = y - p.y; double dz = z - p.z; return sqrt(dx*dx + dy*dy + dz*dz); return sqrt(dx * dx + dy * dy + dz * dz); } { double s = sin(k), c = cos(k); double t = c*x - s*y; y = s*x + c*y; double t = c * x - s * y; y = s * x + c * y; x = t; } void rotate2D(double s, double c, double &x, double &y) { double t = c*x - s*y; y = s*x + c*y; double t = c * x - s * y; y = s * x + c * y; x = t; } } double Pt3D::minComponent() const { return std::min(x, std::min(y, z)); } double Pt3D::maxComponent() const { return std::max(x, std::max(y, z)); } void Pt3D::vectorProduct(const Pt3D& a, const Pt3D& b) { x = a.y*b.z - a.z*b.y; y = a.z*b.x - a.x*b.z; z = a.x*b.y - a.y*b.x; x = a.y * b.z - a.z * b.y; y = a.z * b.x - a.x * b.z; z = a.x * b.y - a.y * b.x; } double d2(double x, double y) { double q = x*x + y*y; double q = x * x + y * y; if (q < 0) { if (Pt3D::report_errors) logPrintf("", "d2()", LOG_ERROR, "sqrt(%g): domain error", q); return 0; } return sqrt(q); void Orient::transform(Pt3D& target, const Pt3D &s) const { target.x = s.x*x.x + s.y*y.x + s.z*z.x; target.y = s.x*x.y + s.y*y.y + s.z*z.y; target.z = s.x*x.z + s.y*y.z + s.z*z.z; target.x = s.x * x.x + s.y * y.x + s.z * z.x; target.y = s.x * x.y + s.y * y.y + s.z * z.y; target.z = s.x * x.z + s.y * y.z + s.z * z.z; } void Orient::revTransform(Pt3D& target, const Pt3D &s) const { target.x = s.x*x.x + s.y*x.y + s.z*x.z; target.y = s.x*y.x + s.y*y.y + s.z*y.z; target.z = s.x*z.x + s.y*z.y + s.z*z.z; target.x = s.x * x.x + s.y * x.y + s.z * x.z; target.y = s.x * y.x + s.y * y.y + s.z * y.z; target.z = s.x * z.x + s.y * z.y + s.z * z.z; }
• ## cpp/frams/util/3d.h

 r305 // This file is a part of Framsticks SDK.  http://www.framsticks.com/ // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski. // Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski. // See LICENSE.txt for details. Pt3D() {} ///< coords will be not initialized! Pt3D(const Pt3D &p) :x(p.x), y(p.y), z(p.z) {} ///< copy from another point bool    operator==(const Pt3D& p)       { return (x == p.x) && (y == p.y) && (z == p.z); } void    operator+=(const Pt3D& p)       { x += p.x; y += p.y; z += p.z; } void    operator-=(const Pt3D& p)       { x -= p.x; y -= p.y; z -= p.z; } void    operator*=(double d)    { x *= d; y *= d; z *= d; } Pt3D    operator*(const Pt3D &p) const { return Pt3D(y*p.z - z*p.y, z*p.x - x*p.z, x*p.y - y*p.x); } void    operator/=(double d)    { x /= d; y /= d; z /= d; } bool    operator==(const Pt3D& p) { return (x == p.x) && (y == p.y) && (z == p.z); } void    operator+=(const Pt3D& p) { x += p.x; y += p.y; z += p.z; } void    operator-=(const Pt3D& p) { x -= p.x; y -= p.y; z -= p.z; } void    operator*=(double d) { x *= d; y *= d; z *= d; } Pt3D    operator*(const Pt3D &p) const { return Pt3D(y * p.z - z * p.y, z * p.x - x * p.z, x * p.y - y * p.x); } void    operator/=(double d) { x /= d; y /= d; z /= d; } //Pt3D  operator+(const Pt3D& p) const {return Pt3D(x+p.x,y+p.y,z+p.z);} //Pt3D  operator-(const Pt3D& p) const {return Pt3D(x-p.x,y-p.y,z-p.z);} Pt3D    operator-() const { return Pt3D(-x, -y, -z); } Pt3D    operator*(double d) const { return Pt3D(x*d, y*d, z*d); } Pt3D    operator*(double d) const { return Pt3D(x * d, y * d, z * d); } Pt3D    operator/(double d) const { return Pt3D(x / d, y / d, z / d); } bool    allCoordsLowerThan(const Pt3D& p) const { return (x < p.x) && (y < p.y) && (zp.x) && (y > p.y) && (z > p.z); } bool    allCoordsLowerThan(const Pt3D& p) const { return (x < p.x) && (y < p.y) && (z < p.z); } bool    allCoordsHigherThan(const Pt3D& p) const { return (x > p.x) && (y > p.y) && (z > p.z); } void getMin(const Pt3D& p); void getMax(const Pt3D& p); double minComponent() const; double maxComponent() const; /** vector length = \f$\sqrt{x^2+y^2+z^2}\f$  */ double operator()() const; /** vector length = \f$\sqrt{x^2+y^2+z^2}\f$  */ double length() const { return operator()(); } double length2() const { return x*x + y*y + z*z; } double length2() const { return x * x + y * y + z * z; } double distanceTo(const Pt3D& p) const; double manhattanDistanceTo(const Pt3D& p) const; void getAngles(const Pt3D& X, const Pt3D& dir); void vectorProduct(const Pt3D& a, const Pt3D& b); Pt3D vectorProduct(const Pt3D& p) const { return (*this)*p; } Pt3D entrywiseProduct(const Pt3D &p) const { return Pt3D(x*p.x, y*p.y, z*p.z); } ///< also known as Hadamard product or Schur product double dotProduct(const Pt3D& p) const { return x*p.x + y*p.y + z*p.z; } Pt3D vectorProduct(const Pt3D& p) const { return (*this) * p; } Pt3D entrywiseProduct(const Pt3D &p) const { return Pt3D(x * p.x, y * p.y, z * p.z); } ///< also known as Hadamard product or Schur product double dotProduct(const Pt3D& p) const { return x * p.x + y * p.y + z * p.z; } bool normalize(); };
Note: See TracChangeset for help on using the changeset viewer.