Computer geometry is a branch of computer science devoted to the study of algorithms which can be stated in terms of geometry.

learn more… | top users | synonyms

3
votes
0answers
34 views

Computing intersection of 2D infinite lines

I wrote a small program to compute intersection of 2D infinite lines using Boost Geometry A line is defined by two points in Line class. The ...
1
vote
1answer
33 views

Find cells crossed by a line

This method find cells that are crossed by line A-B and adds them to one vector. I have got some duplicates here and some lines of code are very similiar but they differ in one variable. Should this ...
4
votes
1answer
61 views

Perimeter of a polygon given its vertices

I recently completed this code challenge so just looking for some feedback on my code. The task is to read polygon coordinates from a file and calculate the perimeter, I was provided with a script ...
10
votes
1answer
104 views

Template class for Andrew's Monotone Chain Algorithm Convex Hull

This is my first attempt at writing a template class. I am implementing Andrew's Monotone Chain algorithm, as described here to calculate a 2D Convex Hull. Since this is my first try at templates, I ...
2
votes
1answer
49 views

Create a rotation matrix [closed]

I adapted this piece of code from a math book for game developers and the result is correct albeit with slight floating point errors. ...
7
votes
2answers
562 views

Point inside Polygon check

I have written a method to determine whether a Vector2 lies inside a polygon or outside of it. The polygon is defined by an array of clockwise vertices, p[]. It returns true if the point is inside, ...
3
votes
2answers
74 views

Striped closed poly-line

I'm working on class Striped_polyline which represents a closed poly-line filled with equidistant horizontal lines1: stripedpoly.cpp: ...
7
votes
3answers
267 views

Given a set of points and pairs of lines, count the number of points that are between the pairs of lines

This is a contest problem. The entire description is here. In resume: The question gives a point simulating a light explosion that always has a negative x coordinate, a set of pairs line segments on ...
8
votes
1answer
249 views

Count number of isosceles triangles in a set of points

Given a set of points, what is the number of isosceles triangles that can be formed with the combinations of all points in the set? It is certain that 3 collinear points never exists in the set. ...
4
votes
1answer
144 views

Project Euler 91 (via HackerRank): Right triangles with integer coordinates

This is my code to solve HackerRank's version of Project Euler Problem 91: on an N × N grid, find the number of possible right triangles where one vertex is (0, 0) and the other two vertices are ...
1
vote
3answers
689 views

Checking if the point is on the line segment [closed]

Previously, I wrote the following code: ...
0
votes
0answers
35 views

Scale geometry based on distance between 2 vertices - follow-up

Edit: Changes I made from previous script: Reformatted lines of code to be more readable and correct for Python Created individual functions for items that were previously crammed into singe ...
7
votes
2answers
165 views

Finding the maximum pairwise difference in a collection of colors

Note that this problem is equivalent to finding the longest line segment defined by any two points in a collection of 3D coordinates, which may be an easier way to visualize the problem, and is almost ...
6
votes
0answers
140 views

Graham scan implementation in Haskell

It looks like this is a really classical question, but I'd like to ask it one more time as all those solutions look quite long and complicated for me (maybe because I am dumb :) ) So this is a Graham ...
8
votes
1answer
411 views

Drawing circles with triangles

As pyglet has no in-built method to return a vertex list of circle, I had to build one myself. This is a critical piece of code that I will use very frequently. I need it to be of very fine ...
3
votes
1answer
70 views

Remove “lines” from a 2D vec

I have some code here that I am very unhappy with. The task I am trying to accomplish is this. Given a 2d vec like this: [[0 2 0] [1 3 5] [3 3 0]] which can ...
6
votes
2answers
520 views

Python Trig Calculator

It's big, it's ugly, but it should work. My question is: how could I have implemented the "typeselection" function so it is less repetitive? Any tips on other improvements in coding style are welcomed ...
0
votes
2answers
336 views
11
votes
5answers
282 views

Segment Intersection — Failing on Unknown Edge Cases

I was recently at a programming competition. One of the problems was to determine whether two line segments are parallel, intersect, or do not intersect. For all of the test cases I ran, my solution ...
4
votes
1answer
199 views

Implementing Mitchell's best candidate algorithm

I have written an implementation of Mitchell's best candidate algorithm. Mitchell’s best-candidate algorithm generates a new random sample by creating k candidate samples and picking the best of k. ...
7
votes
1answer
1k views

Line segment to circle collision algorithm

I've written a function (in Python 3) which computes if a line segment (constraint) and a circle (body) collide, and returns the point of intersection (closest point to the centre of the circle): ...
2
votes
2answers
150 views

Find non duplicate Triangle Triplets from a list of given numbers- version 3

It is a continuation of my previous question: Find non duplicateTriangle Triplets from a list of given numbers After I realized triplet structure using less space than ...
4
votes
1answer
77 views

Distance between angles as points

This code calculates the distance between angles, particularly for n-tuples of angles. One example where this situation occurs is as follows: I'm using a 2 arms, one 6 degree of freedom and the other ...
2
votes
1answer
106 views

Find non duplicateTriangle Triplets from a list of given numbers

I implemented an O(N^2) algorithmic solution but not sure it is better than my previous implementation Find Triangle Triplets from a list of given numbers in case of performance. I adapted almost ...
4
votes
1answer
192 views

Find Triangle Triplets from a list of given numbers

If a triplet of segments A, B and C are triangle triplets if and only if A + B > C A + C > B B + C > A Is there a better implementation for this problem? ...
2
votes
0answers
505 views

fftshift implementation for OpenCV

I'm trying to implement fftshift from matlab for OpenCV. Can you please review the correctness of my algorithm? Have I missed something? Also, is there a better and faster way to do it? ...
1
vote
2answers
62 views

Lazy properties for the angle and length of a line segment

The code below shows the pattern I use to manage properties in my classes when I have the following requirements: Some properties are slow to calculate and are rarely used, so I want them to be lazy ...
3
votes
1answer
156 views

Scale object based on distance between 2 vertices

I made this script so that I can scale objects for 3D printing from Maya. I had fun making it and I'm sure it could be cleaned up or improved. If it can be cleaned up please let me know. ...
2
votes
2answers
146 views

Comparing triangles using Java 8 streams

I'm trying to get more familiar with Java 8 streams as they seem to be very powerful (and shorter), so I rewrote a method to use streams. However I'm not very satisfied with it and would like some ...
6
votes
2answers
259 views

Speeding up 2D shadow algorithm

I wrote a class to represent a set of lights in a 2D game that raycast in order to find shadows. The draw method does a lot of calculations and takes a lot of time. Mainly, the adding of areas and ...
4
votes
2answers
125 views

Implementation of Graham Scan algorithm in Haskell

Here is an implementation of Graham Scan algorithm for computing the convex hull of a finite set of points: ...
5
votes
3answers
189 views

Line passing the most number of points

Given points on a two dimensional graph, find a line that passes the most number of points. Any comments please? ...
6
votes
1answer
114 views

Use of static factory methods for vectors and matrices library

I've been working on a Java-based mathematics library focusing on vectors and matrices. I plan to use it for an important upcoming project, so the classes are analogous to data types available in GLSL ...
4
votes
1answer
125 views

Tested cartesian plane utility

I am starting to explore automated testing of code, so I decided to write some trivial code about the cartesian plane and test it. I am particularly interested in automated testing conventions and ...
4
votes
2answers
353 views

Cubic “bezier” curve of grade n

This is code I wrote for calculating bezier curves as quickly and RAM efficiently as possible. I would like to know if there are faster ways to optimize anything, because I am very new to C++ and ...
3
votes
0answers
132 views

Graphical editor with geometric intersection

If it is possible I would like some comments on the overall style of the program. It feels like I am writing the whole program as one big script and I'm not sure how to break it down into several ...
3
votes
1answer
178 views

Ray→plane and ray→quad intersection

This checks the intersection between a Ray and a Plane and between a Ray and a ...
2
votes
2answers
379 views

Haversine formula in SQL

This is an implementation of the Haversine formula in Microsoft Transact SQL. How can I simplify the function? ...
6
votes
2answers
152 views

Quaternion rotations and preparing matrices for a shader

I am implementing an OpenGL ES 2.0 renderer in c. I want to use quaternions for rotations. Please take a look at the way I am implementing the rotation math. Everything looks as expected when the ...
6
votes
1answer
58 views

'Tis the season for gift-wrapping

When reviewing a Graham scan convex hull algorithm implementation, I wrote the following function in an answer: ...
7
votes
3answers
207 views

Checking for intersection points

The aim of the program is to find those points which comes under the intersection of at least 2 circles.(space is a 1000x1000 matrix) ...
8
votes
1answer
2k views

Jarvis's March Convex Hull

I'm more concerned about the coding best practices and how it's written here than the actual algorithm and math. I'm concerned about stack constraints, passing arguments,..etc. If there is anything ...
4
votes
1answer
254 views

Generate sample coordinates inside a Polygon

I have a Polygon named as poly. I attempted to randomly select 5 coordinate points that lies inside the polygon. ...
7
votes
1answer
152 views

2D Convex hull exercise

I'm reading Real World Haskell, and this is my first try with the language. This is the result of the exercises of chapter 3: Consider three two-dimensional points a, b, and c. If we look at ...
1
vote
0answers
255 views

Optimize QuadTree to find K Nearest Neighbors

I'm looking a way to make my k nearest neighbors search more efficient. The context of the question is that I'm given a list of topics that have a unique ID (integer) and a (x,y) coordinate (floats) ...
3
votes
1answer
171 views

Calculating the distance squared between all vertex-pairs of a number of 2D polygons

I have implemented my code using Cython. It is the current bottleneck in my computations. There are two non-numpy functions involved: calculate_2D_dist_squared ...
11
votes
2answers
865 views

CodeEval's SkyScrapers challenge

This is a solution to CodeEval's SkyScrapers challenge. You are given a list of triples \$(l, h, r)\$. Each triple represents an axis-aligned rectangle, with top-left corner at \$(l, h)\$ and ...
14
votes
7answers
2k views

Custom mathematical vector class

My first bigger C++ project: a vector class for personal use and statistical computation. ...
-1
votes
1answer
316 views

Custom 2D/3D Graphics Vector Classes vs SFML's

I don't really like SFML's Vector Classes so I tried making my own. Any criticism is welcome. ...
8
votes
6answers
5k views

C++ 3D Vector Implementation

I have been learning C++ now for 2 months and this week I started reading a book on 3D graphics. I like coding whatever mathematical stuff I learn so I can understand it better, so when I learnt about ...