Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- struct punct {
- double x, y;
- punct operator-(punct &B) {
- punct R;
- R.x = x - B.x;
- R.y = y - B.y;
- return R;
- }
- };
- double prod_scalar(punct &A, punct &B) {
- return A.x * B.x + A.y * B.y;
- }
- double f(double a, double b, double c) {
- return a * a * (b * b + c * c - a * a);
- }
- double dist(punct &A, punct &B) {
- return sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y));
- }
- void baricentric(punct *A, double &u, double &v, double &w) {
- punct v0 = A[1] - A[0], v1 = A[2] - A[0], v2 = A[3] - A[0];
- /*double d00 = prod_scalar(v0, v0),
- d01 = prod_scalar(v0, v1),
- d11 = prod_scalar(v1, v1),
- d20 = prod_scalar(v2, v0),
- d21 = prod_scalar(v2, v1);
- double det = d00 * d11 - d01 * d01,*/
- double inv_det = 1.0 / (v0.x * v1.y - v1.x * v0.y);
- v = (v2.x * v1.y - v1.x * v2.y) * inv_det;
- w = (v0.x * v2.y - v2.x * v0.y) * inv_det;
- u = 1.0 - v - w;
- }
- int main()
- {
- punct A[4], C;
- for (int i = 0; i < 4; i++)
- cin >> A[i].x >> A[i].y;
- double u, v, w;
- baricentric(A, u, v, w);
- cout << u << ' ' << v << ' ' << w;
- if (u > 0 && v < 0 && w > 0) {
- cout << "abcd\n";
- }
- else {
- cout << "Nu e convex";
- return 0;
- }
- double a, b, c;
- a = dist(A[0], A[1]);
- b = dist(A[1], A[2]);
- c = dist(A[0], A[2]);
- C.x = f(a, b, c);
- C.y = f(b, c, a);
- cout << C.x << ' ' << C.y << ' ' << f(c, a, b);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement