Skip to content

Commit 651fdc0

Browse files
author
Мето Трајковски
committed
Small changes
1 parent 2f0dc35 commit 651fdc0

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

Diff for: Math/check_if_point_inside_polygon.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,27 @@ def check_if_point_inside_polygon(polygon, p):
3535

3636
def intersect(a, b, p):
3737
# Y coordinate of p should be between Y coordinates
38-
# this can be written like (a[1] > p[1]) != (b[1] > p[1])
39-
if p[1] < max(a[1], b[1]) and p[1] >= min(a[1], b[1]):
38+
# the following check is a short form from (p[1] < max(a[1], b[1]) and p[1] >= min(a[1], b[1]))
39+
if (a[1] > p[1]) != (b[1] > p[1]):
4040
'''
4141
Equation of line:
4242
y = (x - x0) * ((y1 - y0) / (x1 - x0)) + y0
43-
This formula is computed using the gradients (slopes, changes in the coordinates)
44-
Modify this formula to find X instead Y (because you already have Y)
43+
This formula is computed using the gradients (slopes, changes in the coordinates).
44+
The following formula differs from the previous in that it finds X instead of Y (because Y is known).
4545
'''
4646
x_intersect = (p[1] - a[1]) * ((b[0] - a[0]) / (b[1] - a[1])) + a[0]
4747

4848
# check if the point is on the left of the intersection (because in this case you're drawing a line to the right)
4949
return x_intersect <= p[1]
50+
'''
51+
There exists a more complicated solution. (just in case if you're trying to compare X coordinates and find an intersection)
52+
Compare X coordinates, if both line X coordinates are bigger than point X then there is an intersection.
53+
If both line X coordinates are bigger than point X then there is no intersection.
54+
Else compute the angle between point-lineA and point-lineB (using math.atan2),
55+
if the angle is smaller or equal than 180 (Pi) there is an interesection else there is no intersection.
56+
'''
57+
58+
return False
5059

5160

5261
###########

Diff for: README.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ print(name_of_solution_1(test_val))
8282
print(name_of_solution_2(test_val))
8383
```
8484

85-
*Note that here I'm using the **simplest** way of testing, printing the results using the [print](https://docs.python.org/3/library/functions.html#print) method. Why? Because I think that the bigger part of the users of this repo isn't familiar with [unit testing](https://en.wikipedia.org/wiki/Unit_testing) and I wanted this part to be intuitive. Btw, I'm strongly recommend using some unit testing framework for this kind of testing. The Python Standard Library contains a **great** framework for unit testing called [unittest](https://docs.python.org/3/library/unittest.html), or you can install some third-party unit testing framework like [pytest](https://docs.pytest.org/en/latest/).*
85+
*Note that here I'm using the **simplest** way of testing, printing the results using the [print](https://docs.python.org/3/library/functions.html#print) method. Why? Because I think that the bigger part of the users of this repo isn't familiar with [unit testing](https://en.wikipedia.org/wiki/Unit_testing) and I wanted this part to be intuitive. Btw, I strongly recommend using some unit testing framework for this kind of testing. The Python Standard Library contains a **great** framework for unit testing called [unittest](https://docs.python.org/3/library/unittest.html), or you can install some third-party unit testing framework like [pytest](https://docs.pytest.org/en/latest/).*
8686

8787
### Categories
8888

@@ -115,9 +115,9 @@ Collection of free courses from one of the best CS universities.
115115
* [Shortest Paths Revisited, NP-Complete Problems and What To Do About Them](https://www.coursera.org/learn/algorithms-npcomplete)
116116
- [Introduction to Programming Contests - CS 97SI](http://web.stanford.edu/class/cs97si/)
117117

118-
2. Princeton University (Coursera)
119-
- [Algorithms Part 1](https://www.coursera.org/learn/algorithms-part1)
120-
- [Algorithms Part 2](https://www.coursera.org/learn/algorithms-part2)
118+
2. Princeton University
119+
- [Algorithms Part 1 - Coursera](https://www.coursera.org/learn/algorithms-part1)
120+
- [Algorithms Part 2 - Coursera](https://www.coursera.org/learn/algorithms-part2)
121121

122122
3. UC San Diego
123123
- [Data Structures and Algorithms Specialization (Coursera)](https://www.coursera.org/specializations/data-structures-algorithms)
@@ -131,20 +131,20 @@ Collection of free courses from one of the best CS universities.
131131
* [Algorithmic Design and Techniques](https://www.edx.org/course/algorithmic-design-and-techniques)
132132
* [Graph Algorithms](https://www.edx.org/course/graph-algorithms)
133133

134-
4. MIT University (YouTube)
135-
- [Introduction to algorithms 2005](https://www.youtube.com/playlist?list=PL8B24C31197EC371C) - [Official MIT page with resources](https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-046j-introduction-to-algorithms-sma-5503-fall-2005/). Note: this course is the old 6.046J course (the new name is ***Design and analysis of algorithms***, you can find it below).
136-
- [Introduction to algorithms 2011 - 6.006](https://www.youtube.com/playlist?list=PLUl4u3cNGP61Oq3tWYp6V_F-5jb5L2iHb)
137-
- [Design and analysis of algorithms - 6.046J](https://www.youtube.com/playlist?list=PLUl4u3cNGP6317WaSNfmCvGym2ucw3oGp) - [Official MIT page with resources](https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-046j-design-and-analysis-of-algorithms-spring-2015/index.htm)
138-
- [Advanced Data Structures - 6.851](https://www.youtube.com/playlist?list=PLUl4u3cNGP61hsJNdULdudlRL493b-XZf) - [Official MIT page with resources](http://courses.csail.mit.edu/6.851/spring14/lectures/)
139-
- [Advanced Algorithms 2016 - 6.854](https://www.youtube.com/playlist?list=PL6ogFv-ieghdoGKGg2Bik3Gl1glBTEu8c)
140-
- [Programming for the Puzzled 2018 - 6.S095](https://www.youtube.com/playlist?list=PLUl4u3cNGP62QumaaZtCCjkID-NgqrleA) - [Official MIT page with resources](https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-s095-programming-for-the-puzzled-january-iap-2018/)
134+
4. MIT University
135+
- [Introduction to algorithms 2005](https://www.youtube.com/playlist?list=PL8B24C31197EC371C) - *[Official MIT page with resources](https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-046j-introduction-to-algorithms-sma-5503-fall-2005/)*. Note: this course is the old 6.046J course (the new name is ***Design and analysis of algorithms***, you can find it below).
136+
- [Introduction to algorithms 2011 - 6.006](https://www.youtube.com/playlist?list=PLUl4u3cNGP61Oq3tWYp6V_F-5jb5L2iHb) - *[Official MIT page with resources](https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-006-introduction-to-algorithms-fall-2011/)*
137+
- [Design and analysis of algorithms - 6.046J](https://www.youtube.com/playlist?list=PLUl4u3cNGP6317WaSNfmCvGym2ucw3oGp) - *[Official MIT page with resources](https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-046j-design-and-analysis-of-algorithms-spring-2015/index.htm)*
138+
- [Advanced Data Structures - 6.851](https://www.youtube.com/playlist?list=PLUl4u3cNGP61hsJNdULdudlRL493b-XZf) - *[Official MIT page with resources](http://courses.csail.mit.edu/6.851/spring14/lectures/)*
139+
- [Advanced Algorithms 2016 - 6.854](https://www.youtube.com/playlist?list=PL6ogFv-ieghdoGKGg2Bik3Gl1glBTEu8c) - *[Official MIT page with resources](http://people.csail.mit.edu/moitra/854.html)*
140+
- [Programming for the Puzzled 2018 - 6.S095](https://www.youtube.com/playlist?list=PLUl4u3cNGP62QumaaZtCCjkID-NgqrleA) - *[Official MIT page with resources](https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-s095-programming-for-the-puzzled-january-iap-2018/)*
141141

142-
5. Harvard University (YouTube)
142+
5. Harvard University
143143
- [Advanced algorithms - CS224](https://www.youtube.com/playlist?list=PL2SOU6wwxB0uP4rJgf5ayhHWgw7akUWSf)
144144

145145
6. UC Berkeley
146146
- [Data Structures - CS61B](https://inst.eecs.berkeley.edu/~cs61b/archives.html)
147-
- [Efficient Algorithms and Intractable Problems - CS170](https://cs170.org/) - [YouTube videos](https://www.youtube.com/playlist?list=PLkFD6_40KJIx8lWWbE-Uk069aZ1R-W-VU)
147+
- [Efficient Algorithms and Intractable Problems - CS170](https://cs170.org/) - *[YouTube videos](https://www.youtube.com/playlist?list=PLkFD6_40KJIx8lWWbE-Uk069aZ1R-W-VU)*
148148

149149

150150
### Books

0 commit comments

Comments
 (0)