From a305ed188e9601a5432aebeb7759cae549d3b22e Mon Sep 17 00:00:00 2001 From: Rohan Sharma <50175798+Rohanfizz@users.noreply.github.com> Date: Sun, 24 Oct 2021 11:32:27 +0530 Subject: [PATCH 1/2] Create Point_Location_Test.cpp --- .../Point_Location_Test.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Algorithms/Geometry-Algorithms/Point_Location_Test.cpp diff --git a/Algorithms/Geometry-Algorithms/Point_Location_Test.cpp b/Algorithms/Geometry-Algorithms/Point_Location_Test.cpp new file mode 100644 index 0000000..02be8c2 --- /dev/null +++ b/Algorithms/Geometry-Algorithms/Point_Location_Test.cpp @@ -0,0 +1,20 @@ +//https://cses.fi/problemset/task/2189 +#include +using namespace std; + +int main(){ + ios::sync_with_stdio(0); cin.tie(0); + int T; cin>>T; + while(T--){ + long x1,y1,x2,y2,x3,y3; + cin>>x1>>y1>>x2>>y2>>x3>>y3; + + long val = (x3-x2)*(y2-y1) - (x2-x1)*(y3-y2); + if(val>0){ // clockwise + cout<<"RIGHT"< Date: Sun, 24 Oct 2021 12:13:35 +0530 Subject: [PATCH 2/2] Create Line-Segment-Intersection.cpp --- .../Line-Segment-Intersection.cpp | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 Algorithms/Geometry-Algorithms/Line-Segment-Intersection.cpp diff --git a/Algorithms/Geometry-Algorithms/Line-Segment-Intersection.cpp b/Algorithms/Geometry-Algorithms/Line-Segment-Intersection.cpp new file mode 100644 index 0000000..80252e7 --- /dev/null +++ b/Algorithms/Geometry-Algorithms/Line-Segment-Intersection.cpp @@ -0,0 +1,121 @@ +// https://cses.fi/problemset/task/2190 + +/* + Code by, + ___ _ __ _ +| _ \___| |_ __ _ _ _ / _(_)______ +| / _ \ ' \/ _` | ' \| _| |_ /_ / +|_|_\___/_||_\__,_|_||_|_| |_/__/__| +*/ +#include +typedef int int32_t; +#define int long long int +#define LOOP(i,n) for (int i = 1; i <= n; i++) +#define loop(i,n) for(int i = 0;i +#define vi vector +#define vvi vector +#define vii vector + +#define szv(V) ((int)(V).size()) +#define allv(V) (V).begin(), (V).end() +#define sortv(V) sort(allv(V)); +#define debug cout<<"debugged here"< +#define graphType vector> +#define zt(x) get<0>(x) +#define ot(x) get<1>(x) +#define tt(x) get<2>(x) +//oprations +#define isPowerOf2(x) (x && ceil(log2(x))==floor(log2(x))) +#define dotp(a,b) ( (conj(a)*(b)).real() ) // a*b cos(T), if zero -> prep +#define crossp(a,b) ( (conj(a)*(b)).imag() ) // a*b sin(T), if zero -> parllel +#define firstSetBit(n) ( (log2(n & -n) + 1) ) +// +const double EPS = (1e-7); +const double PI = 3.141592653589793238460; +typedef std::complex point; +typedef std::valarray CArray; + +using namespace std; +int __lcm(int a,int b) {return a*b/__gcd(a,b);} +int dcmp(double x, double y) { return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1; } + +struct hash_pair { + template + size_t operator()(const pair& p) const{ + auto hash1 = hash{}(p.first); + auto hash2 = hash{}(p.second); + return hash1 ^ hash2; + } +}; + +void addEdge(graphType& graph, int src, int nbr, int wt){ + graph[src].pb(make_tuple(src,nbr,wt)); +} + +void addEdge2(graphType& graph, int src, int nbr, int wt){ + graph[src].pb(make_tuple(src,nbr,wt)); + graph[nbr].pb(make_tuple(nbr,src,wt)); +} + +graphType graphDefine(int sz){ + graphType graph; + for(int i = 0;i t; + graph.pb(t); + } + return graph; +} + +int ori(int x1,int y1,int x2,int y2,int x3,int y3){ + int val = (x3-x2)*(y2-y1) - (x2-x1)*(y3-y2); + if(val>0) return 1; // clockwise + else if(val<0) return 2; // counter-clockwise + return 0; //collinear +} + +bool onSeg(int x1,int y1,int x2,int y2,int x3,int y3){ + return (x3<=max(x1,x2) && x3>=min(x1,x2) && y3<=max(y1,y2) && y3>=min(y1,y2)); +} +int32_t main(){ + ios::sync_with_stdio(0); cin.tie(0); + // freopen("input.txt", "r", stdin); + // freopen("output.txt", "w", stdout); + int T; cin>>T; + while(T--){ + int x1,y1,x2,y2,x3,y3,x4,y4; cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4; + int o1 = ori(x1,y1,x2,y2,x3,y3); + int o2 = ori(x1,y1,x2,y2,x4,y4); + int o3 = ori(x3,y3,x4,y4,x1,y1); + int o4 = ori(x3,y3,x4,y4,x2,y2); + if( o1!=o2 && o3!=o4 ){ + cout<<"YES"< provided test cases +-> integer overflow,array bounds +-> special cases (n==1?) +-> copy all used functions +*/