Finding Three Dimensional Force Vector

I was looking for a way to a find three dimensional force vector. I currently in high school taking physics and thought is would be cool if I created a program that would be able to do this. The only bad part is that I'm not sure how to begin. I'm a beginner in c++ so I want to learn how it is done.

Thanks <3
Are you asking for calculating a force vector or for some representation of that vector? The former is up to you, one possibility for the latter is the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

enum dimension_t
{
  x = 0,
  y = 1,
  z = 2,
  d = 3
};

int main()
{
  double force[d] = { 0.1, 0.2, 0.3 };
  
  std::cout << force[x] << std::endl;
  std::cout << force[y] << std::endl;
  std::cout << force[z] << std::endl;
}


Last edited on
you can use structure:
1
2
3
4
5
struct typeVector3D{
    double x;
    double y;
    double z;
} Vector3D, *pVector3D;

In this way you can declare a 'Vector3D' or 'pVector3D' variable:
1
2
3
4
5
6
7
Vector3D force; //'force' is a variable of type Vector3D with components 'x','y','z'
pVector3D p_force; //'p_force' is a pointer of Vector3D
//You can access to the member of the struct 'Vector3D' with the '.'
force.x= 4.3;  // assigning 4.3 to the 'x' of 'force'

//also, you can declare an array of 'Vector3D' in the same way a standard array;
Vector3D forces[4];    //declared an array of 4 'Vector3D' 
Last edited on
Topic archived. No new replies allowed.