![]() |
| | #1 |
| Registered User Join Date: May 2006
Posts: 894
| Vector class First, here's the code for the Vector class right now: Code: #ifndef VECTOR_H_INCLUDED
#define VECTOR_H_INCLUDED
#include <vector>
template < class T >
class Vector
{
public:
Vector(int n = 3);
Vector(const Vector< T >&);
// Not quite sure about the type it should return...
float Angle( ) const;
void Normalize( );
float Length( ) const;
Vector< T > VecProduct(const Vector< T >&) const;
T DotProduct(const Vector< T >&) const;
bool IsParallel(const Vector< T >&) const;
bool IsOrthogonal(const Vector< T >&) const;
bool operator == (const Vector< T >&) const;
bool operator != (const Vector< T >&) const;
Vector< T >& operator = (const Vector< T >&);
Vector< T >& operator += (const Vector< T >&);
Vector< T >& operator + (const Vector< T >&) const;
Vector< T >& operator -= (const Vector< T >&);
Vector< T >& operator - (const Vector< T >&) const;
Vector< T >& operator *= (const T&);
Vector< T >& operator * (const T&) const;
private:
};
#endif // VECTOR_H_INCLUDED
Also, the technical question is rather simple, in fact. What type should the Angle() function return ? I thought returning a T would be dangerous because if T happens to be 'int' then we lose precision (which is also a problem for Normalize() and Length()). Then I thought returning float would be correct because of its precision but I'm not 100% sure. Thanks a lot. |
| Desolation is offline | |
| | #2 |
| The superheterodyne. Join Date: Dec 2005 Location: Ireland
Posts: 2,215
| You have a choice in the second option - do you want to return degrees or radians? Either way I'd return a double of some description - I never liked the float type much. Make a method for each option. You might also want to consider returning a COORD, x and y values. There's no point in just working in polar coordinates. The other one, that I can say but not spell, is useful too. For the former question ... could be difficult to have the number of dimensions as a variable. Stick with fixing a static number of dimensions first.
__________________ I blag! |
| twomers is offline | |
| | #3 |
| Registered User Join Date: Jan 2005
Posts: 7,246
| In general, an std::vector is as efficient as any other similar dynamic memory solution. Since the size of your Vector will be dynamic, you will probably want to use dynamic memory. So, I would use std::vector. If you want to cap the size of your Vector at something small like 10, then a local array of that maximum might be an option to avoid dynamic allocation. |
| Daved is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|