# Tag Info

## Hot answers tagged computational-geometry

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 ...
• 49.7k
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,...
• 41k
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 ...
• 17.3k
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 ...
• 6,508

### 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:...
• 49.7k

### 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. ...
• 24.1k

### 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 ...
• 213

### N dimensional cubes

Generation of vertices You could use itertools.product to generate vertices. You can ...
• 29.2k
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. ...
• 19.3k

### 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: ...
• 14.9k
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 ...
• 41k

### 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 ...
• 60.1k

### 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 ...
• 7,912

### 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 ...
• 3,597

### 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 ...
• 79.3k

### 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 ...
• 246
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. ...
• 25.3k

### 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-...
• 6,217
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 ...
• 276

### 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 ...
• 3,770
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 ...
• 49.7k

### 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 ...
• 1,290
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 ...
• 13k

### 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 ...
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: ...
• 66.5k
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 ...
• 33.6k

### 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 ...
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 ...
• 49.7k