24
votes
Accepted
Intersection over Union for rotated rectangles
1. Review
The large bounty suggests that getting a review of this code is important. But there are some other things you could have done to make reviewing this code more productive:
Give us some ...
19
votes
Accepted
Determine if a triangle is equilateral, isosceles, or scalene
A triangle has, by definition, three sides. I find it therefore weird to take a single sides argument, which could be of any size. This opens you up to obscure bugs,...
15
votes
Accepted
Triangle area computation and linear transformations
Here are a few of the high- and low-level ideas:
too many comments. Remember, comments tend to age and outdate, they need to be maintained as the code changes. And, if they are over-used, they hurt ...
12
votes
Accepted
Program to see how many points lie strictly inside a convex polygon
Data types
Why not use a simple point struct instead of std::pair<int, int>? It doesn't have to do anything, just a ...
11
votes
Generate sample coordinates inside a Polygon
Rejection sampling was proposed in comments on the other answer. The problem with rejection sampling is that the area of a polygon can be an arbitrarily small fraction of its bounding box, for example:...
11
votes
Distance too close
Use types consistently
I prefer double over Double, but it doesn't really matter which you use as long as it's consistent. ...
11
votes
Area of the triangle generated by the hands of a clock
This is an addendum to Oscar's answer. Just doing some math.
Let t = 0 be 12 o'clock, when all hands are coinciding and the area is 0. We need to calculate the ...
10
votes
N dimensional cubes
Generation of vertices
You could use itertools.product to generate vertices. You can ...
10
votes
Accepted
Counting points on a given irregular grid that are inside or outside a circle
Well, you are manually testing every point \$(X_i, Y_j)\$ to see where it falls. You shouldn't, really.
Remember the sage advice: If in doubt, sort.
A better algorithm goes:
Read all X-coordinates.
...
9
votes
Order a list of points by closest distance
I don't like any of these answers. In particular, the accepted answer is simply wrong.
Let's start by critiquing the interface:
...
9
votes
Accepted
Farthest point algorithm in Python
First, a style comment. On the internet, especially in programming, and in particular on this website, English is the lingua franca. So you should avoid mixing other languages and English. This way ...
9
votes
Intersection over Union for rotated rectangles
There are two main reasons why your program is slow and using huge amounts of memory:
You are using a 768×768 pixel image for each overlap calculation
You are checking each anchor box against each ...
8
votes
Parsing shorts from binary file and finding the closest and furthest points
Given that this was for an interview I'll refrain from saying that Javadoc is missing.
private static final Point closest = new Point(-200, 300);
That's a ...
8
votes
Area of the triangle generated by the hands of a clock
So the first place to look is your area function. This currently uses 15 trig operations to calculate the area of a triangle (3 ...
8
votes
Area of the triangle generated by the hands of a clock
Avoid using namespace std;
Importing all names of a namespace is a bad habit to get into, and can cause surprise when names like ...
7
votes
Python implementation of the Ramer-Douglas-Peucker Algorithm
This is quite an old question, yet I'd like to answer because it comes up if one searches for "Python Ramer-Douglas-Peucker" on the internet.
First, the implementation is incorrect!
The OP ...
7
votes
Accepted
Compute the perimeter of a polygon
consec will wrap around and pair the last element of your list as consecutive with the first. This isn't documented in the comment and IMO a little bit problematic. ...
7
votes
Area of the triangle generated by the hands of a clock
The area of the triangle given points A, B, C is half the magnitude of the cross product of vectors AB and AC. The points are defined in 3D, with a zero z component. The cross product will only be non-...
7
votes
Accepted
Area of the triangle generated by the hands of a clock
The first thing to do is to get rid of trig functions which are slow (15-30 cycles) and replace them with precomputed tables. Since the hands have only 60 possible positions each this is a 60-slot ...
7
votes
Program to see how many points lie strictly inside a convex polygon
I'm unfamiliar with the algorithm, so I cannot speak for that.
perdot()
The function can be declared with the constexpr ...
7
votes
Accepted
Where is the most desolate place in Colorado?
If this were a problem on the Euclidean plane, and not on the surface of the Earth, then it could be solved exactly by computing the Voronoi diagram for the set of airport locations, and intersecting ...
7
votes
VBA functions to calculate sun and moon positions
At a bare minimum declare your variable types when Dimming variables*. If you don't, they're automatically Variant. The VBA ...
6
votes
Accepted
Lines, intersections and terrible unit tests
I don't see the benefits of having both static and non-static API: PointF? Intersect and static PointF? Intersect. It does not ...
6
votes
Lines, intersections and terrible unit tests
This is more of a long comment.
essentially it builds both lines in slope-intercept form (y = mx + b)
This doesn't work for vertical lines, because a vertical ...
6
votes
Accepted
Get all points within given radius for a given vector
Here are some things that may help you improve your code.
Use the appropriate #includes
In order to compile and link, this code requires at least following line:
...
6
votes
Accepted
Kattis "Hitting the Targets" utilizing a polymorphic relashionship
Virtual destructor
As a simple rule of thumb, if a base class contains any virtual functions, its destructor should also be ...
6
votes
Updating positions of enemies every frame
Some things you could try:
Unless the waypoints change position, the objects will continue in the same direction each frame. This means
you don't have to recalculate ...
6
votes
Accepted
Closest distance between points in a list
1. Review
There are no docstrings. What do these functions do? What arguments do they take and what do they return?
You write:
I just tried to delay the sqrt ...
6
votes
Count lines with more the X dots on it
1. Dynamic problem
The post says:
I have a Python-Tkinter UI that has a field with dots. A user can choose some of them, and program must show points for currently chosen dots after every new ...
6
votes
Counting points on a given irregular grid that are inside or outside a circle
@Deduplicator has given good advice: use binary search to find the X-coordinates that are nearest the circle.
I would just like to point out that ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
computational-geometry × 240python × 79
performance × 63
c++ × 61
algorithm × 59
java × 25
python-3.x × 23
beginner × 21
numpy × 20
c# × 18
programming-challenge × 16
clustering × 15
haskell × 13
time-limit-exceeded × 13
graphics × 12
javascript × 11
collision × 11
c++11 × 10
matrix × 10
python-2.x × 9
coordinate-system × 8
c × 7
mathematics × 7
unit-testing × 6
interview-questions × 6