Changeset 725869


Ignore:
Timestamp:
May 21, 2008, 9:24:54 AM (17 years ago)
Author:
Frederik Heber <heber@…>
Children:
33c05d
Parents:
e9c14d
Message:

new header file for the vector class, new operators +=,*=,*,+

Location:
molecuilder/src
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/molecules.hpp

    re9c14d r725869  
    2222#include "helpers.hpp"
    2323#include "stackclass.hpp"
     24#include "vector.hpp"
    2425
    2526class atom;
     
    119120#define RDET2(a0,a1,a2,a3) ((a0)*(a3)-(a1)*(a2))                      //!< hard-coded determinant of a 2x2 matrix
    120121
    121 /** Single vector.
    122  * basically, just a x[3] but with helpful functions
    123  */
    124 class vector {   
    125   public:
    126     double x[NDIM];
    127 
    128   vector();
    129   ~vector();
    130 
    131   double Distance(const vector *y) const;
    132   double PeriodicDistance(const vector *y, const double *cell_size) const;
    133   double ScalarProduct(const vector *y) const;
    134   double Projection(const vector *y) const;
    135   double Norm() const ;
    136   double Angle(vector *y) const;
    137 
    138   void AddVector(const vector *y);
    139   void SubtractVector(const vector *y);
    140   void CopyVector(const vector *y);
    141   void RotateVector(const vector *y, const double alpha);
    142   void Zero();
    143   void Normalize();
    144   void Translate(const vector *x);
    145   void Mirror(const vector *x);
    146   void Scale(double **factor);
    147   void Scale(double *factor);
    148   void Scale(double factor);
    149   void MatrixMultiplication(double *M);
    150   void InverseMatrixMultiplication(double *M);
    151   void KeepPeriodic(ofstream *out, double *matrix);
    152   void LinearCombinationOfVectors(const vector *x1, const vector *x2, const vector *x3, double *factors);
    153  
    154   bool GetOneNormalVector(const vector *x1);
    155   bool MakeNormalVector(const vector *y1);
    156   bool MakeNormalVector(const vector *y1, const vector *y2);
    157   bool MakeNormalVector(const vector *x1, const vector *x2, const vector *x3);
    158   bool SolveSystem(vector *x1, vector *x2, vector *y, double alpha, double beta, double c);
    159         bool LSQdistance(vector **vectors, int dim);
    160 
    161   void AskPosition(double *cell_size, bool check);
    162   bool Output(ofstream *out) const;
    163 };
    164 
    165 ofstream& operator<<(ofstream& ost, vector& m);
    166122
    167123/** Parameter structure for least square minimsation.
     
    300256  /// Find atoms.
    301257  atom * FindAtom(int Nr) const;
    302   atom * AskAtom(char *text);
     258  atom * AskAtom(string text);
    303259
    304260  /// Count and change present atoms' coordination.
     
    306262  void CountElements();
    307263  void CalculateOrbitals(class config &configuration);
     264  bool CenterInBox(ofstream *out, vector *BoxLengths);
    308265  void CenterEdge(ofstream *out, vector *max);
    309266  void CenterOrigin(ofstream *out, vector *max);
     
    335292  void ResetAllAtomNumbers();
    336293  int CountCyclicBonds(ofstream *out);
    337   char * GetColor(enum Shading color);
     294  string GetColor(enum Shading color);
    338295
    339296  molecule *CopyMolecule();
     
    500457  void Load(char *filename, periodentafel *periode, molecule *mol);
    501458  void LoadOld(char *filename, periodentafel *periode, molecule *mol);
    502   void RetrieveConfigPathAndName(char *filename);
     459  void RetrieveConfigPathAndName(char * filename);
    503460  bool Save(ofstream *file, periodentafel *periode, molecule *mol) const;
    504461  void Edit(molecule *mol);
    505462  bool GetIsAngstroem() const;
    506463  char *GetDefaultPath() const;
    507   void config::SetDefaultPath(const char *path);
     464  void SetDefaultPath(const char *path);
    508465};
    509466
  • molecuilder/src/vector.cpp

    re9c14d r725869  
    182182};
    183183
     184/** Sums vector \a to this lhs component-wise.
     185 * \param a base vector
     186 * \param b vector components to add
     187 * \return lhs + a
     188 */
     189vector& operator+=(vector& a, const vector& b)
     190{
     191  a.AddVector(&b);
     192  return a;
     193};
     194/** factor each component of \a a times a double \a m.
     195 * \param a base vector
     196 * \param m factor
     197 * \return lhs.x[i] * m
     198 */
     199vector& operator*=(vector& a, const double m)
     200{
     201  a.Scale(m);
     202  return a;
     203};
     204
     205/** Sums two vectors \a  and \b component-wise.
     206 * \param a first vector
     207 * \param b second vector
     208 * \return a + b
     209 */
     210vector& operator+(const vector& a, const vector& b)
     211{
     212  vector *x = new vector;
     213  x->CopyVector(&a);
     214  x->AddVector(&b);
     215  return *x;
     216};
     217
     218/** Factors given vector \a a times \a m.
     219 * \param a vector
     220 * \param m factor
     221 * \return a + b
     222 */
     223vector& operator*(const vector& a, const double m)
     224{
     225  vector *x = new vector;
     226  x->CopyVector(&a);
     227  x->Scale(m);
     228  return *x;
     229};
     230
    184231/** Prints a 3dim vector.
    185232 * prints no end of line.
     
    213260{
    214261  for (int i=0;i<NDIM;i++)
    215     this->x[i] *= (*factor)[i];
     262    x[i] *= (*factor)[i];
    216263};
    217264
     
    219266{
    220267  for (int i=0;i<NDIM;i++)
    221     this->x[i] *= *factor;
     268    x[i] *= *factor;
    222269};
    223270
     
    225272{
    226273  for (int i=0;i<NDIM;i++)
    227     this->x[i] *= factor;
     274    x[i] *= factor;
    228275};
    229276
Note: See TracChangeset for help on using the changeset viewer.