Not Yet Answered # 3D vectors

Moschops 683 StuXYZ 731 jonsca 1,059 Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...

0

```
class vector {
manipulateInCartesian (&vectorType);
manipulateInSpherical (&vectorType);
manipulateInCylindrical (&vectorType);
vectorType add (vectorType, vectorType);
vectorType multiplyByScalar (scalarVal, vectorType);
vectorType dotProduct (vectorType, vectorType);
vectorType crossProduct (vectorType, vectorType);
};
```

Don't forget to implement the functions and define a vectorType.

*Edited 5 Years Ago by Moschops*: n/a

0

The obvious approach most Vector3D classes use it to represent the data in one form and convert from input in another form into it (e.g. leave the vector in cartesian for and convert from spherical and cylindrical input). Depending on the problem that is a viable solution [not always].

Then it is a matter of doing one thing at a time. I would actually recommend writing the output first, that greatly helps with debugging, so you have a class like this:

```
class Vector3D
{
private:
double x,y,z; // This can be done in many ways,but I have chosen discrete
// values. [you can use an array, etc]
public:
Vector3D(); // Default constructor [e.g. set x,y,z to zero]
Vector3D(const Vector3D&); // ALWAYS write a copy constructor
Vector3D& operator=(const Vector3D&); // ALWAYS write an assignment operator
~Vector3D() {} // Destructor
void write(std::ostream&) const; // Write should be constant
};
// This is implemented in the standard way
std::ostream& operator<<(std::ostream& OutStream,const Vector3D& A)
{
A.write(OutStream);
return OutStream;
}
```

Then all you have to write is a simple write method and the constructors/copy constructors and you can star doing stuff with your class. Initially, the vector 0,0,0 is a bit boring, so you start to increase the scope, e.g. an constructor that takes three values, test that and build up the class.

After a bit you add this:

```
class Vector3D
{
// stuff....
public:
// stuff...
Vector3D& operator+=(const Vector3D&);
Vector3D operator+(const Vector3D&,const Vector3D&) const;
// then to multiply by a scalar
Vector3D& operator*=(const double);
// etc...
};
```

If you actually want to change the manipulation set e.g. for some problems use spherical coordinates and others to use something else, then the best way to do that

is to have a base Vector3D and then inherit them into a SphericalVec etc.

When you have some more code and get confused/stuck etc. post your code and we can see if we can help.

*Edited 5 Years Ago by StuXYZ*: n/a

0

Do you know how to do all of the transformations from a mathematical standpoint (i.e., pencil and paper)? If not, first start with a good reference book or Wikipedia article and figure out the mechanics of it.

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

When I execute this progammatically, I get a table with row heights much larger than when I do this manually.

Note : Sel is the Word.Selection object and the Clipboard contains an Excel Table.

```
public void AddClipboard()
{
Sel.PasteExcelTable(false,false, false);
var t = Sel.Tables[Sel.Tables.Count];
t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
}
```

the function that I created to find the ...