From 8551b7e37b1ba064a1a2c8ba791a61ccb2e66500 Mon Sep 17 00:00:00 2001 From: Brebenel Mihnea <59292725+brebenelmihnea@users.noreply.github.com> Date: Sat, 29 Jun 2024 16:28:29 +0300 Subject: [PATCH 01/14] upd --- content/5_Plat/Geo_Pri.mdx | 17 +++++++++++++++++ content/5_Plat/Geo_Pri.problems.json | 14 ++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index f9f3f830f7..1aa1cf94bf 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -403,6 +403,23 @@ int main() { - [My Templates](<https://github.com/bqi343/USACO/tree/master/Implementations/content/geometry%20(13)/Primitives>) +## Radians and Angles + + +<FocusProblem problem="" /> + +#### Implementation + +**Time Complexity:** $\mathcal{O}()$ +<LanguageSection> +<CPPSection> + +```cpp +``` + +</CPPSection> +</LanguageSection> + ## Misc Problems Some European Olympiads, like the CEOI, Balkan OI, and the Croatian OI, tend to diff --git a/content/5_Plat/Geo_Pri.problems.json b/content/5_Plat/Geo_Pri.problems.json index 4c52b9e302..25b77aed04 100644 --- a/content/5_Plat/Geo_Pri.problems.json +++ b/content/5_Plat/Geo_Pri.problems.json @@ -70,6 +70,20 @@ } } ], + "radians": [ + { + "uniqueId": "leetcode-1610", + "name": "Maximum Number of Visible Points", + "url": "https://leetcode.com/problems/maximum-number-of-visible-points/description/", + "source": "LeetCode", + "difficulty": "Normal", + "isStarred": false, + "tags": ["Geometry", "Radians"], + "solutionMetadata": { + "kind": "none" + } + } + ], "standard": [ { "uniqueId": "ys-SortPointsByArgument", From 629a05c0ac3acd5a548503d5c1feac81d0daea02 Mon Sep 17 00:00:00 2001 From: Brebenel Mihnea <59292725+brebenelmihnea@users.noreply.github.com> Date: Sat, 29 Jun 2024 17:24:20 +0300 Subject: [PATCH 02/14] upd --- content/5_Plat/Geo_Pri.mdx | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index 1aa1cf94bf..f709969962 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -415,6 +415,33 @@ int main() { <CPPSection> ```cpp +class Solution { +public: + int visiblePoints(vector<vector<int>>& points, int angle, vector<int>& location) { + int cnt = 0; + vector<double> angles; + for(const vector<int> &p : points) { + if(p == location) { + cnt++; + continue; + } + angles.push_back(atan2(p[1] - location[1], p[0] - location[0])); + } + sort(angles.begin(), angles.end()); + for(int i = 0; i < (int)points.size(); i++) { + angles.push_back(angles[i] + 2 * M_PI); + } + int ans = 0; + double angle_radians = M_PI * angle / 180; + for(int r = 0, l = 0; r < (int)angles.size(); r++) { + while(angles[r] - angles[l] > angle_radians) { + l++; + } + ans = max(ans, r - l + 1); + } + return ans + cnt; + } +}; ``` </CPPSection> From 72e6e227bd7248fe420740e5ca4e50b4aefa49c1 Mon Sep 17 00:00:00 2001 From: Brebenel Mihnea <59292725+brebenelmihnea@users.noreply.github.com> Date: Sat, 29 Jun 2024 17:46:49 +0300 Subject: [PATCH 03/14] upd --- content/5_Plat/Geo_Pri.mdx | 9 ++++++++- content/5_Plat/Geo_Pri.problems.json | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index f709969962..9c6ea2308f 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -405,12 +405,17 @@ int main() { ## Radians and Angles +<FocusProblem problem="radians" /> -<FocusProblem problem="" /> + + +The movement of the field of view can be seen as a [sliding window](/gold/sliding-window) applied +on the sorted angles of the points. #### Implementation **Time Complexity:** $\mathcal{O}()$ + <LanguageSection> <CPPSection> @@ -433,7 +438,9 @@ public: } int ans = 0; double angle_radians = M_PI * angle / 180; + // Sliding window for(int r = 0, l = 0; r < (int)angles.size(); r++) { + // Pop all the points out of the field of view while(angles[r] - angles[l] > angle_radians) { l++; } diff --git a/content/5_Plat/Geo_Pri.problems.json b/content/5_Plat/Geo_Pri.problems.json index 25b77aed04..dbf1c31a3d 100644 --- a/content/5_Plat/Geo_Pri.problems.json +++ b/content/5_Plat/Geo_Pri.problems.json @@ -78,7 +78,7 @@ "source": "LeetCode", "difficulty": "Normal", "isStarred": false, - "tags": ["Geometry", "Radians"], + "tags": ["Geometry", "Radians", "Sliding Windows"], "solutionMetadata": { "kind": "none" } From 96904bf1f8734b9d9ccc976d78433edea820ab1d Mon Sep 17 00:00:00 2001 From: Brebenel Mihnea <59292725+brebenelmihnea@users.noreply.github.com> Date: Sat, 29 Jun 2024 18:28:32 +0300 Subject: [PATCH 04/14] upd --- content/5_Plat/Geo_Pri.mdx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index 9c6ea2308f..0a7bbab869 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -407,7 +407,15 @@ int main() { <FocusProblem problem="radians" /> - +Talking about angles only makes sense when dealing with lines or segments, so let's consider the segments +connecting the initial position and a dot: $(pos_x, pos_y)-(x, y)$. One such segment is inside the field of +view if and only if it's slope is bigger than the lower bound and smaller than the upper bound. Since we're +working with angles, we'll convert the slopes into radians. + +Consider $\alpha$ as the angle formed by one line with the +$$ +\texttt{slope}=\frac{\Delta y}{\Delta x} +$$ The movement of the field of view can be seen as a [sliding window](/gold/sliding-window) applied on the sorted angles of the points. From 24b91ca88951a3148495da15bba3462854059f23 Mon Sep 17 00:00:00 2001 From: Brebenel Mihnea <59292725+brebenelmihnea@users.noreply.github.com> Date: Sat, 29 Jun 2024 20:44:55 +0300 Subject: [PATCH 05/14] upd --- content/5_Plat/Geo_Pri.mdx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index 0a7bbab869..887f05823c 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -412,11 +412,13 @@ connecting the initial position and a dot: $(pos_x, pos_y)-(x, y)$. One such seg view if and only if it's slope is bigger than the lower bound and smaller than the upper bound. Since we're working with angles, we'll convert the slopes into radians. -Consider $\alpha$ as the angle formed by one line with the +Consider $\alpha$ as the angle formed by one line with the $\texttt{ox}$ axis. Then we have: $$ -\texttt{slope}=\frac{\Delta y}{\Delta x} +\texttt{slope}=\frac{\Delta y}{\Delta x}=\tg{\alpha} \\ +\alpha=\arctg{\frac{\Delta y}{\Delta x}} $$ +### Explanation The movement of the field of view can be seen as a [sliding window](/gold/sliding-window) applied on the sorted angles of the points. From 65bd79600dd62a8032bef1c6f3b74ee52edbf4b7 Mon Sep 17 00:00:00 2001 From: Brebenel Mihnea <59292725+brebenelmihnea@users.noreply.github.com> Date: Sat, 29 Jun 2024 20:55:27 +0300 Subject: [PATCH 06/14] upd --- content/5_Plat/Geo_Pri.mdx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index 887f05823c..20fae02f82 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -420,7 +420,8 @@ $$ ### Explanation The movement of the field of view can be seen as a [sliding window](/gold/sliding-window) applied -on the sorted angles of the points. +on the sorted angles of the points. The angle of the field of vies could be large enough to see +points from the beginning of the sorted array, thus the array of angles should be duplicated - cyclic array. #### Implementation @@ -436,13 +437,17 @@ public: int cnt = 0; vector<double> angles; for(const vector<int> &p : points) { + // Ignore points identical to location if(p == location) { cnt++; continue; } + // Take the arctg in radians angles.push_back(atan2(p[1] - location[1], p[0] - location[0])); } + // Sort agngles sort(angles.begin(), angles.end()); + // Duplicate the array and add 2*PI to the angles for(int i = 0; i < (int)points.size(); i++) { angles.push_back(angles[i] + 2 * M_PI); } From ffc97223cbd792e617caa47e02f37a0b1e4ceee4 Mon Sep 17 00:00:00 2001 From: Brebenel Mihnea <59292725+brebenelmihnea@users.noreply.github.com> Date: Sat, 29 Jun 2024 21:26:24 +0300 Subject: [PATCH 07/14] upd --- content/5_Plat/Geo_Pri.mdx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index 20fae02f82..049bbd9a91 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -405,10 +405,12 @@ int main() { ## Radians and Angles +### Maximum Number of Visible Points + <FocusProblem problem="radians" /> -Talking about angles only makes sense when dealing with lines or segments, so let's consider the segments -connecting the initial position and a dot: $(pos_x, pos_y)-(x, y)$. One such segment is inside the field of +Working with angles only makes sense when in the context of lines and segments. Therefore, let's consider the segments +connecting the initial position and each dot: $(pos_x, pos_y)-(x, y)$. One such segment is inside the field of view if and only if it's slope is bigger than the lower bound and smaller than the upper bound. Since we're working with angles, we'll convert the slopes into radians. @@ -418,7 +420,6 @@ $$ \alpha=\arctg{\frac{\Delta y}{\Delta x}} $$ -### Explanation The movement of the field of view can be seen as a [sliding window](/gold/sliding-window) applied on the sorted angles of the points. The angle of the field of vies could be large enough to see points from the beginning of the sorted array, thus the array of angles should be duplicated - cyclic array. From 2a56b7e50b2152a6c7e789fc8b873ff3ecb8048d Mon Sep 17 00:00:00 2001 From: Brebenel Mihnea <59292725+brebenelmihnea@users.noreply.github.com> Date: Sat, 29 Jun 2024 21:31:09 +0300 Subject: [PATCH 08/14] upd --- content/5_Plat/Geo_Pri.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index 049bbd9a91..caf1e7c2da 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -409,7 +409,7 @@ int main() { <FocusProblem problem="radians" /> -Working with angles only makes sense when in the context of lines and segments. Therefore, let's consider the segments +Working with angles only makes sense in the context of lines and segments. Therefore, let's consider the segments connecting the initial position and each dot: $(pos_x, pos_y)-(x, y)$. One such segment is inside the field of view if and only if it's slope is bigger than the lower bound and smaller than the upper bound. Since we're working with angles, we'll convert the slopes into radians. @@ -426,7 +426,7 @@ points from the beginning of the sorted array, thus the array of angles should b #### Implementation -**Time Complexity:** $\mathcal{O}()$ +**Time Complexity:** $\mathcal{O}(N)$ <LanguageSection> <CPPSection> From 8db43c3b97af757d3efc3e8101246deb8d68eeea Mon Sep 17 00:00:00 2001 From: Brebenel Mihnea <59292725+brebenelmihnea@users.noreply.github.com> Date: Sat, 29 Jun 2024 21:33:26 +0300 Subject: [PATCH 09/14] upd --- content/5_Plat/Geo_Pri.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index caf1e7c2da..13a2ba4ce4 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -403,7 +403,7 @@ int main() { - [My Templates](<https://github.com/bqi343/USACO/tree/master/Implementations/content/geometry%20(13)/Primitives>) -## Radians and Angles +## Angles ### Maximum Number of Visible Points From ea5d13e3f18e75078f260ddd2b8ce49f9b18b365 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 29 Jun 2024 18:34:47 +0000 Subject: [PATCH 10/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- content/5_Plat/Geo_Pri.mdx | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index 13a2ba4ce4..8a2f0d911a 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -403,7 +403,7 @@ int main() { - [My Templates](<https://github.com/bqi343/USACO/tree/master/Implementations/content/geometry%20(13)/Primitives>) -## Angles +## Angles ### Maximum Number of Visible Points @@ -411,8 +411,8 @@ int main() { Working with angles only makes sense in the context of lines and segments. Therefore, let's consider the segments connecting the initial position and each dot: $(pos_x, pos_y)-(x, y)$. One such segment is inside the field of -view if and only if it's slope is bigger than the lower bound and smaller than the upper bound. Since we're -working with angles, we'll convert the slopes into radians. +view if and only if it's slope is bigger than the lower bound and smaller than the upper bound. Since we're +working with angles, we'll convert the slopes into radians. Consider $\alpha$ as the angle formed by one line with the $\texttt{ox}$ axis. Then we have: $$ @@ -421,25 +421,26 @@ $$ $$ The movement of the field of view can be seen as a [sliding window](/gold/sliding-window) applied -on the sorted angles of the points. The angle of the field of vies could be large enough to see +on the sorted angles of the points. The angle of the field of vies could be large enough to see points from the beginning of the sorted array, thus the array of angles should be duplicated - cyclic array. -#### Implementation +#### Implementation **Time Complexity:** $\mathcal{O}(N)$ <LanguageSection> <CPPSection> -```cpp +```cpp class Solution { -public: - int visiblePoints(vector<vector<int>>& points, int angle, vector<int>& location) { - int cnt = 0; + public: + int visiblePoints(vector<vector<int>> &points, int angle, + vector<int> &location) { + int cnt = 0; vector<double> angles; - for(const vector<int> &p : points) { + for (const vector<int> &p : points) { // Ignore points identical to location - if(p == location) { + if (p == location) { cnt++; continue; } @@ -449,21 +450,19 @@ public: // Sort agngles sort(angles.begin(), angles.end()); // Duplicate the array and add 2*PI to the angles - for(int i = 0; i < (int)points.size(); i++) { + for (int i = 0; i < (int)points.size(); i++) { angles.push_back(angles[i] + 2 * M_PI); } int ans = 0; double angle_radians = M_PI * angle / 180; // Sliding window - for(int r = 0, l = 0; r < (int)angles.size(); r++) { + for (int r = 0, l = 0; r < (int)angles.size(); r++) { // Pop all the points out of the field of view - while(angles[r] - angles[l] > angle_radians) { - l++; - } + while (angles[r] - angles[l] > angle_radians) { l++; } ans = max(ans, r - l + 1); } return ans + cnt; - } + } }; ``` From f9b76850c4c2c118f6af16f4316c1a75fd8db0ef Mon Sep 17 00:00:00 2001 From: Brebenel Mihnea <59292725+brebenelmihnea@users.noreply.github.com> Date: Sun, 30 Jun 2024 01:12:43 +0300 Subject: [PATCH 11/14] upd --- content/5_Plat/Geo_Pri.mdx | 47 +++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index 8a2f0d911a..b449714297 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -8,11 +8,11 @@ frequency: 1 You should know operations such as the cross product and dot product. -## Standard Problems - -### Location of a point +# Location of a point <FocusProblem problem="pointlocationtest" /> +## Explanation + To check the $P$ location towards the $P_1$ $P_2$ line we use following formula: $(P.y - P_1.y) * (P_2.x - P_1.x) - (P.x - P_1.x) * (P_2.y - P_1.y)$ If it's equal to $0$ it means that $P$, $P_1$ and $P_2$ are collinear. Otherwise the value's sign indicated if $P$ is under the line - negative - or above the line - positive. @@ -31,7 +31,7 @@ This formula doesn't only tell us whether the points are collinear, but where th </Spoiler> -#### Implementation +## Implementation <LanguageSection> <CPPSection> @@ -79,13 +79,14 @@ int main() { </CPPSection> </LanguageSection> -### Segment intersection +# Segment intersection <FocusProblem problem="line" /> +## Explanation We can quickly dismiss the segment intersection by treating them as rectangles having the segments as diagonals which can be easily done. If it turns out the rectangles intersect then we just check if the segment's ends are on different sides of the other segment. -#### Implementation +## Implementation <LanguageSection> <CPPSection> @@ -163,12 +164,15 @@ int main() { </CPPSection> </LanguageSection> -### Polygon area +# Polygon area + <FocusProblem problem="polygon" /> +## Explanation + The following algorithm uses the [Shoelace formula](https://en.wikipedia.org/wiki/Shoelace_formula). -#### Implementation +## Implementation <LanguageSection> <CPPSection> @@ -208,17 +212,19 @@ int main() { </CPPSection> </LanguageSection> -### Point's location relative to polygon +# Point's location relative to polygon <FocusProblem problem="polygon2" /> +## Explanation + We can cast a ray from the point $P$ going in any fixed direction (people usually go to the right). If the point is located on the outside of the polygon the ray will intersect its edges an even number of times. If the point is on the inside of the polygon then it will intersect the edge an odd number of times. This approach is called [ray casting](https://en.wikipedia.org/wiki/Point_in_polygon). -#### Implementation +## Implementation <LanguageSection> <CPPSection> @@ -292,9 +298,12 @@ int main() { </CPPSection> </LanguageSection> -### Lattice points in polygon +# Lattice points in polygon + <FocusProblem problem="latticepoints" /> +## Explanation + Let's first focus on the lattice points on the polygon's boundary. We'll process each edge individually. The number of intersections of a line with lattice points is the greatest common divisor of $P_1.x - P_2.x$ and $P_1.y - P_2.y$. @@ -312,7 +321,7 @@ Let's denote $A$ polygon's area, $i$ the number of integer points inside and $b$ equation: $A = i + b/2 - 1$. Changing the order a little bit to get $i = A - b/2 + 1$. We've found $b$ and, as you've probably already solved [Polygon Area](https://cses.fi/problemset/task/2191) from above, $A$ can be computed using cross-product. -#### Implementation +## Implementation <LanguageSection> <CPPSection> @@ -403,12 +412,12 @@ int main() { - [My Templates](<https://github.com/bqi343/USACO/tree/master/Implementations/content/geometry%20(13)/Primitives>) -## Angles - -### Maximum Number of Visible Points +# Angles <FocusProblem problem="radians" /> +## Explanation + Working with angles only makes sense in the context of lines and segments. Therefore, let's consider the segments connecting the initial position and each dot: $(pos_x, pos_y)-(x, y)$. One such segment is inside the field of view if and only if it's slope is bigger than the lower bound and smaller than the upper bound. Since we're @@ -424,7 +433,7 @@ The movement of the field of view can be seen as a [sliding window](/gold/slidin on the sorted angles of the points. The angle of the field of vies could be large enough to see points from the beginning of the sorted array, thus the array of angles should be duplicated - cyclic array. -#### Implementation +## Implementation **Time Complexity:** $\mathcal{O}(N)$ @@ -436,12 +445,12 @@ class Solution { public: int visiblePoints(vector<vector<int>> &points, int angle, vector<int> &location) { - int cnt = 0; + int extra = 0; vector<double> angles; for (const vector<int> &p : points) { // Ignore points identical to location if (p == location) { - cnt++; + extra++; continue; } // Take the arctg in radians @@ -461,7 +470,7 @@ class Solution { while (angles[r] - angles[l] > angle_radians) { l++; } ans = max(ans, r - l + 1); } - return ans + cnt; + return ans + extra; } }; ``` From 1526bccb9db1d1e5b393734e7b7884d68f4c8cba Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 29 Jun 2024 22:13:54 +0000 Subject: [PATCH 12/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- content/5_Plat/Geo_Pri.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index b449714297..a47e6b9263 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -11,7 +11,7 @@ You should know operations such as the cross product and dot product. # Location of a point <FocusProblem problem="pointlocationtest" /> -## Explanation +## Explanation To check the $P$ location towards the $P_1$ $P_2$ line we use following formula: $(P.y - P_1.y) * (P_2.x - P_1.x) - (P.x - P_1.x) * (P_2.y - P_1.y)$ If it's equal to $0$ it means that $P$, $P_1$ and $P_2$ are collinear. Otherwise the value's sign indicated if $P$ is under the line - negative - or above the line - positive. From 5598baa8adf2d18964299294a63f1dd8b0775a74 Mon Sep 17 00:00:00 2001 From: SansPapyrus683 <55369003+SansPapyrus683@users.noreply.github.com> Date: Sat, 29 Jun 2024 15:17:15 -0700 Subject: [PATCH 13/14] Update Geo_Pri.mdx --- content/5_Plat/Geo_Pri.mdx | 100 ++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 47 deletions(-) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index a47e6b9263..58b00c379c 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -8,7 +8,48 @@ frequency: 1 You should know operations such as the cross product and dot product. -# Location of a point +<Resources> + <Resource source="CF" title="C++ - std::complex" url="22175" starred> + short description of operations + </Resource> + <Resource source="CPH" title="29 - Geometry" starred> + Complex #s, Points & Lines, Polygons, Distances + </Resource> + <Resource source="CF" title="Point Struct" url="48122" starred> + code, examples + </Resource> + <Resource + source="cp-algo" + title="Geometry - Elementary Operations" + url="https://cp-algorithms.com/" + starred + /> + <Resource source="CPC" title="12 - geometry" url="12_geometry" starred> + basics, polygon area, point in polygon + </Resource> + <Resource + source="CF" + title="vlecomte - Geometry Handbook" + url="59129" + starred + > + some material is quite advanced + </Resource> + <Resource source="CP2" title="7.2, 7.3 - Basic Geo, Polygons"/> +</Resources> + +<!-- <Resource + source="TC" + title="Basic Geometry Concepts Pts 1,2" + url="geometry-concepts-basic-concepts" + > + broken code format + </Resource> --> + +- [My Templates](<https://github.com/bqi343/USACO/tree/master/Implementations/content/geometry%20(13)/Primitives>) + +# Location of a Point + <FocusProblem problem="pointlocationtest" /> ## Explanation @@ -79,10 +120,12 @@ int main() { </CPPSection> </LanguageSection> -# Segment intersection +# Segment Intersection + <FocusProblem problem="line" /> ## Explanation + We can quickly dismiss the segment intersection by treating them as rectangles having the segments as diagonals which can be easily done. If it turns out the rectangles intersect then we just check if the segment's ends are on different sides of the other segment. @@ -164,13 +207,13 @@ int main() { </CPPSection> </LanguageSection> -# Polygon area +# Polygon Area <FocusProblem problem="polygon" /> ## Explanation -The following algorithm uses the [Shoelace formula](https://en.wikipedia.org/wiki/Shoelace_formula). +We can use the [Shoelace formula](https://en.wikipedia.org/wiki/Shoelace_formula). ## Implementation @@ -212,7 +255,7 @@ int main() { </CPPSection> </LanguageSection> -# Point's location relative to polygon +# Point's Location Relative to Polygon <FocusProblem problem="polygon2" /> @@ -325,6 +368,7 @@ $A$ can be computed using cross-product. <LanguageSection> <CPPSection> + ```cpp #include <bits/stdc++.h> @@ -365,53 +409,12 @@ int main() { cout << interior_points << ' ' << boundary_points; } ``` + </CPPSection> </LanguageSection> <Problems problems="standard" /> -## Resources - -<Resources> - <Resource source="CF" title="C++ - std::complex" url="22175" starred> - short description of operations - </Resource> - <Resource source="CPH" title="29 - Geometry" starred> - Complex #s, Points & Lines, Polygons, Distances - </Resource> - <Resource source="CF" title="Point Struct" url="48122" starred> - code, examples - </Resource> - <Resource - source="cp-algo" - title="Geometry - Elementary Operations" - url="https://cp-algorithms.com/" - starred - /> - <Resource source="CPC" title="12 - geometry" url="12_geometry" starred> - basics, polygon area, point in polygon - </Resource> - <Resource - source="CF" - title="vlecomte - Geometry Handbook" - url="59129" - starred - > - some material is quite advanced - </Resource> - <Resource source="CP2" title="7.2, 7.3 - Basic Geo, Polygons"/> -</Resources> - -<!-- <Resource - source="TC" - title="Basic Geometry Concepts Pts 1,2" - url="geometry-concepts-basic-concepts" - > - broken code format - </Resource> --> - -- [My Templates](<https://github.com/bqi343/USACO/tree/master/Implementations/content/geometry%20(13)/Primitives>) - # Angles <FocusProblem problem="radians" /> @@ -456,12 +459,14 @@ class Solution { // Take the arctg in radians angles.push_back(atan2(p[1] - location[1], p[0] - location[0])); } + // Sort agngles sort(angles.begin(), angles.end()); // Duplicate the array and add 2*PI to the angles for (int i = 0; i < (int)points.size(); i++) { angles.push_back(angles[i] + 2 * M_PI); } + int ans = 0; double angle_radians = M_PI * angle / 180; // Sliding window @@ -470,6 +475,7 @@ class Solution { while (angles[r] - angles[l] > angle_radians) { l++; } ans = max(ans, r - l + 1); } + return ans + extra; } }; From c5caac37532d4fb40e937fee1d59086b2c0ae891 Mon Sep 17 00:00:00 2001 From: Brebenel Mihnea <59292725+brebenelmihnea@users.noreply.github.com> Date: Sun, 30 Jun 2024 23:38:08 +0300 Subject: [PATCH 14/14] upd --- content/5_Plat/Geo_Pri.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index 58b00c379c..ffb04ba0ac 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -423,7 +423,7 @@ int main() { Working with angles only makes sense in the context of lines and segments. Therefore, let's consider the segments connecting the initial position and each dot: $(pos_x, pos_y)-(x, y)$. One such segment is inside the field of -view if and only if it's slope is bigger than the lower bound and smaller than the upper bound. Since we're +view if and only if its slope is bigger than the lower bound and smaller than the upper bound. Since we're working with angles, we'll convert the slopes into radians. Consider $\alpha$ as the angle formed by one line with the $\texttt{ox}$ axis. Then we have: