Created
November 9, 2025 03:03
-
-
Save Mjkim-Programming/13c70f2cbacdceb31ca58a696587d9e0 to your computer and use it in GitHub Desktop.
CCW Algorithm Implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <bits/stdc++.h> | |
| using namespace std; | |
| // [COPY START] | |
| struct Point { | |
| long long x, y; | |
| }; | |
| enum Orientation { CW = -1, COLLINEAR = 0, CCW = 1 }; | |
| long long ccw(const Point& a, const Point& b, const Point& c) { | |
| return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x); | |
| } | |
| Orientation orientation(const Point& a, const Point& b, const Point& c) { | |
| long long v = ccw(a, b, c); | |
| if (v > 0) return CCW; | |
| if (v < 0) return CW; | |
| return COLLINEAR; | |
| } | |
| // [COPY END] | |
| int main() { | |
| ios::sync_with_stdio(false); | |
| cin.tie(nullptr); | |
| Point a, b, c; | |
| if (!(cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y)) return 0; | |
| auto r = orientation(a, b, c); | |
| if (r == CCW) | |
| cout << "CCW\n"; | |
| else if (r == CW) | |
| cout << "CW\n"; | |
| else | |
| cout << "COLLINEAR\n"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment