-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMath Professional.cpp
248 lines (239 loc) · 10.2 KB
/
Math Professional.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
// Written by Rostisval Gogolauri /2017//
#include "stdafx.h"
#include <iostream>
#include <conio.h> // debug library//
#include <string>
#include <math.h>
#define PI 3.14159265
using namespace std;
int main()
{
int ink = 1;
float x0, x, y0, y, z0, z, c, k,x1,y1,z1; //coordinates * координаты//
system("Color 2"); // f0 - white and black change text and background color of console * цвета для фона, текста //
while (ink == 1) { // loop for inputing without exiting command line * Ввод след. без закрытия консоли //
cout << "Choise one statement which you need to solve (1-7)" << endl;
cout << " " << endl;
cout << "1: General equation of line Ax+By+C=0" << endl; //1: Загальне рівняня прямої
cout << "2: Equation of line using line segments x/a+y/b=1 " << endl; //2: Векторне рівняня прямої у відрізках//
cout << "3: Equation of line with angle coefficient y=kx+b" << endl; //3: Рівняня прямої з кутовим коефіціентом k//
cout << "4: Equation of line going through 2 points (x-x1)/(x2-x1)=(y-y1)/(y2-y1)" << endl; //4: Відстань від точки до прямої//
cout << "5: Normal equation of line x*cos(a)+y*sin(a)-p=0" << endl; //5: Нормальне рівнянян прямої//
cout << "6: Equation of line with parameters x=x1+a*(lambda)" << " y=y1+b*(lambda)" << endl; //6: Параметричне рівняня прямої//
cout << "7: Equation of line in the open space" << endl; //7: Рівняня прямої в просторі, що проходить через 2 точки//
cout << "8: Angle between plane and line (alpha)" << endl; //8: Кут мiж площин. i прямою//
cout << "9: Scalar equation of the plane ax+by+cz=d" << endl; //9: Скалярне рiвняня площини //
int caser;
cin >> caser;
switch (caser) {
case 1:cout << "(A,B,C are coefficients) A,B - vector coordinates. Give me A : ";
cin >> x; // x = A
cout << "Give me B: ";
cin >> y; // y = B
cout << "Give me C:";
cin >> c; // c = C
system("cls"); // clears the screen * Оч. скрин
if (y == 0) { cout << "Division by zero!!!!!!!!!!!!!"; }
else if (x == 0) {
if ((c / y) > 0) {
cout << "Equation of line : y=" << "+" << c / y;
}
else if ((c / y) < 0) {
cout << "Equation of line : y=" << c / y;
}
}
else {
if ((c / y) > 0) {
cout << "Equation of line : y=" << -x / y << "x" << "+" << c / y;
}
else if ((c / y) < 0) {
cout << "Equation of line : y=" << -x / y << "x" << c / y;
}
else {
cout << "Equation of line : y=" << 0;
}
}
break;
case 2:cout << "Input please 2 line segments a,b:";
cin >> x >> y; //x=a, y=b//
system("cls"); // clears the screen * Оч. скрин//
if (x == 0 || y == 0) {
cout << "division by zero!!!!!!!!!!!";
}
else {
if (y / x > 0) {
cout << "y=" << "-" << y / x << "x";
}
else if (y / x < 0) {
cout << "y=" << y / x << "x";
}
else {
cout << "y=" << 0;
}
}
break;
case 3:cout << "Give me tg(alpha) :";
cin >> k;
cout << "Give me b :";
cin >> c; // c = b;//
system("cls"); // clears the screen * Оч. скрин//
if (k == 0) { cout << "y=" << c; }
else if (k == 1) {
if (c >= 0) {
cout << "y=" << "x+" << c;
}
else if (c < 0) {
cout << "y=" << "x" << c;
}
}
else {
if (c >= 0) {
cout << "y=" << k << "x+" << c;
}
else if (c < 0) {
cout << "y=" << k << "x" << c;
}
}
break;
case 4:cout << "Give me coordinates of first point x1,y1 : ";
cin >> x0 >> y0;
cout << "Give me coordinates of second point x2,y2 : ";
cin >> x >> y;
system("cls"); // clears the screen * Оч. скрин//
if ((x - x0) == 0 || (y - y0) == 0) {
cout << "Division by zero!!!";
}
else if ((x - x0)*(y - y0) == 1) {
if ((x0 / (x - x0)*(y - y0) + y0) >= 0) {
cout << "y=" << 1 / (x - x0)*(y - y0) << "x+" << (x0 / (x - x0)*(y - y0) + y0);
}
else {
cout << "y=" << 1 / (x - x0)*(y - y0) << "x" << (x0 / (x - x0)*(y - y0) + y0);
}
}
else {
if ((x0 / (x - x0)*(y - y0) + y0) >= 0) {
cout << "y=" << 1 / (x - x0)*(y - y0) << "x+" << (x0 / (x - x0)*(y - y0) + y0);
}
else {
cout << "y=" << 1 / (x - x0)*(y - y0) << "x" << (x0 / (x - x0)*(y - y0) + y0);
}
//cout << "y=" << 1 / (x - x0)*(y - y0) << "x-" << (x0 / (x - x0)*(y - y0) + y0);//
}
break;
case 5:cout << "Give me alpha:";
cin >> k;// k=alpha//
cout << "Give me p - distance from (0;0) to line";
cin >> c;// c=p//
if (cos(k / 180.0 / PI) / sin(k / 180.0 / PI) > 0) { cout << "y=" << c / sin(k / 180.0 / PI) << "-" << cos(k / 180.0 / PI) / sin(k / 180.0 / PI) << "x"; }
else if (cos(k / 180.0 / PI) / sin(k / 180.0 / PI) < 0) { cout << "y=" << c / sin(k / 180.0 / PI) << cos(k / 180.0 / PI) / sin(k / 180.0 / PI) << "x"; }
else if (sin(k / 180.0 / PI) == 0) { cout << "division by zero!!! Tracepaser"; }
else { cout << "y=" << c / sin(k / 180.0 / PI); }
break;
case 6:cout << "Give me direction vector coordinates a,b:";
cin >> x0 >> y0; //x0,y0=a,b
cout << "Give me point(dot) coordinates x1,y1:";
cin >> x >> y;// x=x1, y=y1
system("cls"); // clears the screen * Оч. скрин//
if (x0 >= 0 && y >= 0) {
cout << "x=" << x << "+" << x0 << "*lambda(any number)" << endl;
cout << "y=" << y << "+" << y0 << "*lambda(any number)" << endl;
}
else if (x0 >= 0 && y < 0) {
cout << "x=" << x << "+" << x0 << "*lambda(any number)" << endl;
cout << "y=" << y << y0 << "*lambda(any number)" << endl;
}
else if (x0 < 0 && y >= 0) {
cout << "x=" << x << x0 << "*lambda(any number)" << endl;
cout << "y=" << y << "+" << y0 << "*lambda(any number)" << endl;
}
else if (x0 < 0 && y < 0) {
cout << "x=" << x << x0 << "*lambda(any number)" << endl;
cout << "y=" << y << y0 << "*lambda(any number)" << endl;
}
break;
case 7:cout << "Give me coordinates of the first point x,y,z:"; // <- must be handled//
cin >> x0 >> y0 >> z0;
cout << "Give me coordinates of the second point x,y,z:";
cin >> x >> y >> z;
system("cls"); // clears the screen * Оч. скрин//
if ((x - x0) == 0 || (y - y0) == 0 || (z - z0) == 0) {
cout << "Division by zero!!!";
}
else if ((x0 / (x - x0)) >= 0 && (y0 / (y - y0)) >= 0 && (z0 / (z - z0)) >= 0) {
cout << 1 / (x - x0) << "x-" << x0 / (x - x0) << "=" << 1 / (y - y0) << "y-" << y0 / (y - y0) << "=" << 1 / (z - z0) << "z-" << z0 / (z - z0);
}
else if ((x0 / (x - x0)) < 0 && (y0 / (y - y0)) < 0 && (z0 / (z - z0)) < 0) {
cout << 1 / (x - x0) << "x+" << -x0 / (x - x0) << "=" << 1 / (y - y0) << "y+" << -y0 / (y - y0) << "=" << 1 / (z - z0) << "z+" << -z0 / (z - z0);
}
else if ((x0 / (x - x0)) >= 0 && (y0 / (y - y0)) < 0 && (z0 / (z - z0)) < 0) {
cout << 1 / (x - x0) << "x-" << x0 / (x - x0) << "=" << 1 / (y - y0) << "y+" << -y0 / (y - y0) << "=" << 1 / (z - z0) << "z+" << -z0 / (z - z0);
}
else if ((x0 / (x - x0)) >= 0 && (y0 / (y - y0)) >= 0 && (z0 / (z - z0)) < 0) {
cout << 1 / (x - x0) << "x-" << x0 / (x - x0) << "=" << 1 / (y - y0) << "y-" << y0 / (y - y0) << "=" << 1 / (z - z0) << "z+" << -z0 / (z - z0);
}
else if ((x0 / (x - x0)) < 0 && (y0 / (y - y0)) < 0 && (z0 / (z - z0)) >= 0) {
cout << 1 / (x - x0) << "x+" << -x0 / (x - x0) << "=" << 1 / (y - y0) << "y+" << -y0 / (y - y0) << "=" << 1 / (z - z0) << "z-" << z0 / (z - z0);
}
else if ((x0 / (x - x0)) < 0 && (y0 / (y - y0)) >= 0 && (z0 / (z - z0)) >= 0) {
cout << 1 / (x - x0) << "x+" << -x0 / (x - x0) << "=" << 1 / (y - y0) << "y-" << y0 / (y - y0) << "=" << 1 / (z - z0) << "z-" << z0 / (z - z0);
}
else if ((x0 / (x - x0)) < 0 && (y0 / (y - y0)) >= 0 && (z0 / (z - z0)) < 0) {
cout << 1 / (x - x0) << "x+" << -x0 / (x - x0) << "=" << 1 / (y - y0) << "y-" << y0 / (y - y0) << "=" << 1 / (z - z0) << "z+" << -z0 / (z - z0);
}
else if ((x0 / (x - x0)) >= 0 && (y0 / (y - y0)) < 0 && (z0 / (z - z0)) >= 0) {
cout << 1 / (x - x0) << "x-" << x0 / (x - x0) << "=" << 1 / (y - y0) << "y+" << -y0 / (y - y0) << "=" << 1 / (z - z0) << "z-" << z0 / (z - z0);
}
break;
case 8:cout << "Coordinates of directional vector (x,y,z):" << endl;
cin >> x0 >> y0 >> z0;
cout << "Normal vector of the plane coordinates (x,y,z):" << endl;
cin >> x >> y >> z;
system("cls");
double hangle;
hangle = asin(sqrt((x*x0 + y*y0 + z*z0)*(x*x0 + y*y0 + z*z0)) / (sqrt(x*x + y*y + z*z)*sqrt(x0*x0 + y0*y0 + z0*z0))) * 180.0 / PI; // have some bugs :(
if (hangle == 90) {
cout << "Parallel"; // ! //
}
else if (hangle == 0) {
cout << "Perpendicular"; // ! //
}
else {
cout << "alpha = " <<90-hangle;
}
break;
case 9: cout << "Give me vector coordinates A,B,C "<<endl;
cin >> x0;
cin >> y0;
cin >> z0;
cout << "Point Coordinates x y z " << endl;
cin >> x >> y >> z;
k = x0*x + y0*y + z0*z;
if (x0==0 || y0==0 || z0 == 0){
cout <<"A or B or C = 0";
}
else if (x0 < 0 ||x0>0 && y0 < 0 && z0 < 0) {
cout << x0 << "x" << y0 << "y" << z0 << "z" << "=" << k;
}
else if (x0 < 0 || x0>0 && y0 > 0 && z0 < 0) {
cout << x0 << "x+" << y0 << "y" << z0 << "z" << "=" << k;
}
else if (x0 < 0 || x0>0 && y0 < 0 && z0 > 0) {
cout << x0 << "x" << y0 << "y+" << z0 << "z" << "=" << k;
}
else if ((x0 < 0) ||(x0>0) && (y0 > 0) && (z0 > 0)) {
cout << x0 << "x+" << y0 << "y+" << z0 << "z" << "=" << k;
}
else { cout << "warn"; }
break;
default:cout << "Select the existing number from the table, thank's!" << endl;
cout << "Try once more.";
}
ink = 0;
cout << " continue? press 1" << endl;;
cin >> ink;
system("cls"); // clears the screen * Оч. скрин
}
// debug point//
return 0;
}