### Engineering Mechanics: Statics, Coding Project Using Single Force Systems.

Hello all.

I was assigned a project that requires me to write a code that solves a mechanical engineering problem. The problem asks you determine a single force equivalent for four wind forces. I have provided an image of the problem below with a dropbox link. Hopefully that is okay.

I am aware that this website is for people who need help with code or computer science projects. I have tried this problem on my own, but I am still having trouble with it, much less, writing a code for it.

One answer I got was ∑My = 5102.5 lb*ft and ∑Mx = 1271 lb*ft. I think this is correct as the single force equivalent system, but I need a code in the event that different values/parameters are used for this problem. Please help with using C++. Thank you so much.

https://www.dropbox.com/s/b4zrn40pr36b30y/Engineering%20Mechanics%20Project.png?dl=0
it should just be the summation of the vectors. Note that c++ thinks 'vector' is an array like container, not a math term, and this can lead to confusion if you are new to the language.
regardless, this is like high-school stuff:
break each vector into its x,y,z components and add x to x, y to y, z to z as described here:

or much more useful, once you see the pictures in the above: https://opentextbc.ca/algebratrigonometryopenstax/chapter/vectors/

once you can do it on paper, then the code for it will be trivial; c++ already has trig functions and you don't need much more than that. Note that C++ works in radians (almost all programming languages do).
Last edited on
It isn't just the sum of vectors. They aren't applied at the same point so you will need the equivalent point of action as well, by balancing moments of force.
Last edited on
∑My is OK, but I think that your ∑Mx should be 1190 lb*ft, not 1271 lb*ft.
(Working: 5 x 105 + 3 x 160 + 5.5 x 50 - 1 x 90 )

Anyway, try this. The data corresponds to that in your example, but it's more general because the force vectors don't have to be parallel. Units are those that you supply forces and distances in. (Time you switched to S.I. units).

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566`` ``````#include #include #include using namespace std; //============== Geometry Stuff ======================================== struct Point{ double x, y, z; }; Point operator + ( Point p , Point q ) { return { p.x + q.x, p.y + q.y, p.z + q.z }; } Point operator - ( Point p , Point q ) { return { p.x - q.x, p.y - q.y, p.z - q.z }; } Point operator * ( double r, Point p ) { return { r * p.x, r * p.y, r * p.z }; } Point operator / ( Point p , double r ) { return { p.x / r, p.y / r, p.z / r }; } double dot ( Point p , Point q ) { return p.x * q.x + p.y * q.y + p.z * q.z ; } Point cross ( Point p , Point q ) { return { p.y * q.z - p.z * q.y, p.z * q.x - p.x * q.z, p.x * q.y - p.y * q.x }; } double normsq ( Point p ) { return dot( p, p ); } double abs ( Point p ) { return sqrt( normsq( p ) ); } ostream &operator << ( ostream &out, const Point &p ) { return out << p.x << '\t' << p.y << '\t' << p.z; } istream &operator >> ( istream &in , Point &p ) { return in >> p.x >> p.y >> p.z; } //====================================================================== void forceSystem( const vector &f, const vector &x, Point &F, Point &M, Point &X ) { const double SMALL = 1.0e-30; Point centroid; F = M = centroid = Point{ 0, 0, 0 }; for ( int i = 0; i < f.size(); i++ ) { F = F + f[i]; M = M + cross( x[i], f[i] ); centroid = centroid + x[i]; } centroid = centroid / f.size(); // Find point on resultant line of action that is closest to centroid (arbitrary choice) if ( abs( F ) < SMALL ) { cout << "Net force is zero\n"; X = Point{ 0, 0, 0 }; } else { X = ( cross( F, M ) - dot( F, centroid ) * F ) / normsq( F ); } } //====================================================================== int main() { // Data is that of your example; note the x, y, z directions and origin vector f = { { 0, 0, -90 }, { 0, 0, -105 }, { 0, 0, -160 }, { 0, 0, -50 } }; vector x = { { 12, 1, 0 }, { 5.5, -5, 0 }, { 14.5, -3, 0 }, { 22.5, -5.5, 0 } }; Point F, M, X; forceSystem( f, x, F, M, X ); cout << "Net force = " << F << '\n' << "Net moment = " << M << '\n' << "\nEquivalent force system is\n" << "force " << F << '\n' << "acting at " << X << '\n' << "(or any point on a line parallel to F passing through that point)"; }``````

 ```Net force = 0 0 -405 Net moment = 1190 5102.5 0 Equivalent force system is force 0 0 -405 acting at 12.5988 -2.93827 0 (or any point on a line parallel to F passing through that point)```

Last edited on
@OP
It would be interesting to know what textbook you are using. Maybe there is another purpose but this calculation to analyse a statically indeterminate frame is unusual.

Anyway - same-same another way:
 ``1234567891011121314151617181920212223242526`` ``````#include int main() { double P{0}, x{0}, y{0}; double sigma_P{0}, sigma_Mx{0}, sigma_My{0}; while(1) { std::cout << "P x y: "; std::cin >> P >> x >> y; sigma_P += P; sigma_Mx += P * y; sigma_My += P * x; std::cout << "Single equivalent force: " << sigma_P << '\n' << " Sigma M about X axis: " << sigma_Mx << '\n' << " Sigma M about Y axis: " << sigma_My << '\n' << " X location: " << sigma_My/sigma_P << '\n' << " Y location: " << sigma_Mx/sigma_P << '\n'; } return 0; }``````

 ```P x y: 90 12 1 Single equivalent force: 90 Sigma M about X axis: 90 Sigma M about Y axis: 1080 X location: 12 Y location: 1 P x y: 105 5.5 -5 Single equivalent force: 195 Sigma M about X axis: -435 Sigma M about Y axis: 1657.5 X location: 8.5 Y location: -2.23077 P x y: 160 14.5 -3 Single equivalent force: 355 Sigma M about X axis: -915 Sigma M about Y axis: 3977.5 X location: 11.2042 Y location: -2.57746 P x y: 50 22.5 -5.5 Single equivalent force: 405 Sigma M about X axis: -1190 Sigma M about Y axis: 5102.5 X location: 12.5988 Y location: -2.93827 P x y: ```
Last edited on
Hello all. Thank you for the help. My apologies for the delayed response.

To give a background summary, my professor created this problem on a whim, therefore, I have little to no knowledge on how to code something like this. Though, I am learning a little bit.

I am still a little confused with the given codes. I tried to run both separately.

@againtry, is the code you provided separate from the one @lastchance created? I tried to use it on its own and I wouldn't receive the same output.

For example, when I input the same values (50 22.5 -5.5 for P x y), it would give me completely different answers. I also noticed that sigma_P was defined on its own, without further input from the problem I provided. Do I need vectors so that the code recognizes it?

Also, what if I wanted to create a code that asked the user to input different values for the problem? For example, the user can input different forces, distances, and based on that, the program gives the user a single equivalent force and its location on the plan. (This part isn't necessary, but I was just curious).

So far, everything is making sense to me besides the coding and formatting part. Please let me know if @againtry's code is supposed to work on its own, and if it is, please help me fix it so that our outputs are the same.

Thank you again.

The code input I received and edited from @againtry:

 ``1234567891011121314151617181920212223242526272829303132`` ``````#include int main() { //Code works for the info provided from Part A (2D Plane) double P{0}, x{0}, y{0}; double sigma_P{0}, sigma_Mx{0}, sigma_My{0}; while(1) { //Requires the user to input a vertical force and its x-y distance in order to calculate the resultant (single equivalent force), and its location on the plane std:: cout << "\nPlease input a force (P), x-distance (x), and y-distance (y)"; std::cout << "\n\nIn this format, P, x, y: "; std::cin >> P >> x >> y; //Calculates the single force equivalent (resultant) sigma_P += P; //Calculates the sigma_Mx += P * y; sigma_My += P * x; std::cout << "\nSingle equivalent force: " << sigma_P << " lb" << '\n' << "\nSigma M about X axis: " << sigma_Mx << " lb*ft" << '\n' << "Sigma M about Y axis: " << sigma_My << " lb*ft" << '\n' << "\nX location: " << sigma_My/sigma_P << " ft" << '\n' << "Y location: " << sigma_Mx/sigma_P << " ft" << '\n'; } return 0; }``````

Output for P x y: 50 22.5 -5.5
 ```Please input a force (P), x-distance (x), and y-distance (y) In this format, P, x, y: 50 22.5 5.5 Single equivalent force: 50 lb Sigma M about X axis: 275 lb*ft Sigma M about Y axis: 1125 lb*ft X location: 22.5 ft Y location: 5.5 ft```

As you can see, it gives me a single equiv. force of 50lb instead of 405lb as it should be, and an X and Y location equal to the X and Y location I input. I clearly need to add further info to the code so that it calculates this value properly. How exactly do I do that, and where do I place it?
Last edited on
Also, for further info, the textbook my professor bases off of is "Engineering Mechanics: Statics Modeling and Analyzing Systems in Equilibrium."

Again, this project was created by him, on his own, and I question how to even start coding it. Please help. Thanks.
@allisonOs
Thanks for the title of the book.

Both programs do the job and the principle is the same. However they are completely separate.

As far as mine is concerned it accumulates the various components and displays the intermediate answers as you progressively go through the data. You need to (manually) input the data for all loads in order to get 405lb. The continuous while loop is the key to my approach.

@lastchance is doing exactly the same except the complete list of loading data is hard-coded. It is similar to reading a data file.
Hello,

Thank you so much for your help. I see now what I was doing wrong.

I had a question earlier, but after re-analyzing the code, and practicing on my own, I answered it myself.

Thank you again! Have a great rest of your day.
Topic archived. No new replies allowed.