Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
vector.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file numeric/kinematic_closure/vector.cc
11 /// @author Kale Kundert
12 
13 // Unit Headers
14 #include <numeric/types.hh>
16 
17 // C++ Headers
18 #include <cmath>
19 #include <iostream>
20 
21 namespace numeric {
22 namespace kinematic_closure {
23 
24 // Vector Arithmetic Functions
25 
26 Real dot (Coordinate const &a, Coordinate const &b) { // {{{1
27  return a[1]*b[1] + a[2]*b[2] + a[3]*b[3];
28 }
29 
30 Coordinate cross (Coordinate const &a, Coordinate const &b) { // {{{1
31  Coordinate result (3);
32 
33  result[1] = a[2]*b[3] - a[3]*b[2];
34  result[2] = a[3]*b[1] - a[1]*b[3];
35  result[3] = a[1]*b[2] - a[2]*b[1];
36 
37  return result;
38 }
39 
40 Coordinate norm (Coordinate const &a) { // {{{1
41  Coordinate result (3);
42 
43  Real magnitude = sqrt(
44  a[1]*a[1] + a[2]*a[2] + a[3]*a[3]);
45 
46  result[1] = a[1] / magnitude;
47  result[2] = a[2] / magnitude;
48  result[3] = a[3] / magnitude;
49 
50  return result;
51 }
52 // }}}1
53 
54 // Overloaded Operators
55 
56 std::ostream& operator << (std::ostream &out, ParameterList const &x) { // {{{1
57  for ( Size i = 1; i <= x.size(); i++ ) {
58  std::string prefix = (i == 1) ? "[" : " ";
59  std::string suffix = (i == x.size()) ? "]" : ",";
60 
61  out << prefix << x[i] << suffix;
62  }
63  return out;
64 }
65 
66 std::ostream& operator << (std::ostream &out, ParameterMatrix const &xx) { // {{{1
67  for ( Size i = 1; i <= xx.size(); i++ ) {
68  std::string prefix = (i == 1) ? "[" : " ";
69  std::string suffix = (i == xx.size()) ? "]" : ",";
70 
71  out << prefix << xx[i] << suffix << std::endl;
72  }
73  return out;
74 }
75 
76 Coordinate operator + (Coordinate const &a, Coordinate const &b) { // {{{1
77  Coordinate result (3);
78 
79  result[1] = a[1] + b[1];
80  result[2] = a[2] + b[2];
81  result[3] = a[3] + b[3];
82 
83  return result;
84 }
85 
86 Coordinate operator - (Coordinate const &a, Coordinate const &b) { // {{{1
87  Coordinate result (3);
88 
89  result[1] = a[1] - b[1];
90  result[2] = a[2] - b[2];
91  result[3] = a[3] - b[3];
92 
93  return result;
94 }
95 
96 Coordinate operator * (Coordinate const &a, Real const &k) { // {{{1
97  Coordinate result (3);
98 
99  result[1] = a[1] * k;
100  result[2] = a[2] * k;
101  result[3] = a[3] * k;
102 
103  return result;
104 }
105 
106 Coordinate operator * (Real const &k, Coordinate const &a) { // {{{1
107  Coordinate result (3);
108 
109  result[1] = k * a[1];
110  result[2] = k * a[2];
111  result[3] = k * a[3];
112 
113  return result;
114 }
115 
116 Coordinate operator / (Coordinate const &a, Real const &k) { // {{{1
117  Coordinate result (3);
118 
119  result[1] = a[1] / k;
120  result[2] = a[2] / k;
121  result[3] = a[3] / k;
122 
123  return result;
124 }
125 
126 Coordinate operator / (Real const &k, Coordinate const &a) { // {{{1
127  Coordinate result (3);
128 
129  result[1] = k / a[1];
130  result[2] = k / a[2];
131  result[3] = k / a[3];
132 
133  return result;
134 }
135 // }}}1
136 
137 } // end namespace kinematic_closure
138 } // end namespace numeric
Coordinate operator/(Coordinate const &a, Real const &k)
Definition: vector.cc:116
Coordinate norm(Coordinate const &a)
Definition: vector.cc:40
platform::Size Size
Definition: types.hh:42
Coordinate operator+(Coordinate const &a, Coordinate const &b)
Definition: vector.cc:76
Implement the primitive vector operations (again).
Coordinate operator*(Coordinate const &a, Real const &k)
Definition: vector.cc:96
def x
std::ostream & operator<<(std::ostream &out, ParameterList const &x)
Definition: vector.cc:56
Real dot(Coordinate const &a, Coordinate const &b)
Definition: vector.cc:26
std::vector with 1-based indexing
Definition: vector1.fwd.hh:44
rosetta project type declarations. Should be kept updated with core/types.hh. This exists because num...
double Real
Definition: types.hh:39
void cross(const utility::vector1< Real > &L, const utility::vector1< Real > &r0, utility::vector1< Real > &r)
Coordinate operator-(Coordinate const &a, Coordinate const &b)
Definition: vector.cc:86