Hello,
Im in a bit of pickle haha, hoping someone can help.
Heres the scenario:
A straight line connects two coordinates (3, 7) and (8, 12) call them (x1, y1) and (x2, y2).
I have an assignment where I need to write a program that calculates the:
Directional factor k = __
Midpoint x coordinate = __
Midpoint y coordinate = __
Straight length is = __
Point (3,7) polar coordinate: r = __ and theta = __
Point (8, 12) polar coordinate: r = __ and theta = __.
The calculations for each are as follows:
Directional factor - (y2-y1)/(x2-x1).
Midpoint x/y - ((x1+x2)/2, (y1+y2)/2).
Straight length - square root of (x1-x2)^2 + (y1-y2)^2)
Polar coordinates r = square root of (x^2 + y^2), theta = arctan(y/x)
Ive barely started on it, but I can see getting problems now with the math part on the last parts and thought maybe someone smarter than I can help me out and I could simply study the code to understand it/learn it better..
I am a beginner at this so please dont judge too hard :D code attached of what I have so far..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#include <iostream>
#include <iomanip>
#include <cmath>
#include <math.h>
using namespace std;
int main () {
int x1 = 3, y1 = 7, x2 = 8, y2 = 12, k, vx, vy, length, polar1, polar2, theta1, theta2;
k = (y2-y1)/(x2-x1);
vx = ((x1+x2)/2);
vy = ((y1+y2)/2);
cout <<"The directional factor k is " <<k <<endl;
cout <<"Midpoint x coordinate is " <<vx <<endl;
cout <<"Midpoint y coordinate is " <<vy <<endl;
cout <<"Straight length is " <<length <<endl;
cout <<"Point (3, 7) polar coordinate: r = " <<polar1 <<"theta = " <<theta1 <<endl;
cout <<"Point (8, 12) polar coordinate: r = " <<polar2 <<"theta = " <<theta2 <<endl;
return 0;
}
|