geometry

How do you test if a point is inside a circle?

In python, if you create a circle with: newcircle = circle(center_x, center_y, radius) How do you test if a given set of x/y coordinates are inside the circle? ...

Test case data for convex-hull.

I need to make a 2D convex hull function for a class assignment and I want a more robust test cases than the assignment provides. Does anyone known of a largish test cases (25 < n < 100) with the solution? ...

Finding a free area in the stage

I'm drawing rectangles at random positions on the stage, and I don't want them to overlap. So for each rectangle, I need to find a blank area to place it. I've thought about trying a random position, verify if it is free with private function containsRect(r:Rectangle):Boolean { var free:Boolean = true; for (var i:int = 0; i < ...

An effective algorithm for buffering a polyline to create a polygon?

I need to write some code that will buffer a line to create a polygon as shown below. http://www.sli.unimelb.edu.au/gisweb/BuffersModule/Buff_line.htm From following the steps outlined, I can create polygon shapes around simple lines that do not cross themselves or have too tight curves, but as the lines I'm trying to buffer are squigg...

How do you calculate the average of a set of angles?

I want to calculate the average of a set of angles. For example, I might have several samples from the reading of a compass. The problem of course is how to deal with the wraparound. The same algorithm might be useful for a clockface. The actual question is more complicated - what do statistics mean on a sphere or in an algebraic space...

Find the number of internal angles of a polygon, bigger than 180º

How can I find the number of internal angles of a polygon, bigger than 180º, having only the vertices of the polygon? For each vertex I want always the internal angle, not the external. Thanks from Brazil. ...

Position between two points?

I have a python app where I need to find a position that is exactly in the middle between two screen coordinates, but I can't seem to find an algorithm to do this. How can this be accomplished? ...

How to draw a Perspective-Correct Grid in 2D

I have an application that defines a real world rectangle on top of an image/photograph, of course in 2D it may not be a rectangle because you are looking at it from an angle. The problem is, say that the rectangle needs to have grid lines drawn on it, for example if it is 3x5 so I need to draw 2 lines from side 1 to side 3, and 4 lines...

What algorithm can I use to determine points within a semi-circle?

I have a list of two-dimensional points and I want to obtain which of them fall within a semi-circle. Originally, the target shape was a rectangle aligned with the x and y axis. So the current algorithm sorts the pairs by their X coord and binary searches to the first one that could fall within the rectangle. Then it iterates over e...

How can a convex polygon be broken down into right triangles aligned on the X- and Y- axes?

Given a convex polygon represented by a set of vertices (we can assume they're in counter-clockwise order), how can this polygon be broken down into a set of right triangles whose legs are aligned with the X- and Y-axes? Since I probably lack some math terminology, "legs" are what I'm calling those two lines that are not the hypotenuse ...

Compute the area of intersection between a circle and a triangle?

How does one compute the area of intersection between a triangle (specified as three (X,Y) pairs) and a circle (X,Y,R)? I've done some searching to no avail. This is for work, not school. :) It would look something like this in C#: struct { PointF vert[3]; } Triangle; struct { PointF center; float radius; } Circle; // returns the a...

Rotation & OpenGL Matrices

I have a class that holds a 4x4 matrix for scaling and translations. How would I implement rotation methods to this class? And should I implement the rotation as a separate matrix? ...

Connect two Line Segments

Given two 2D line segments, A and B, how do I calculate the length of the shortest 2D line segment, C, which connects A and B? ...

In SqlServer 2008, how would I generalize multiple adjacent polygons?

When you have a table with a Geometry type field (or Geography), you can call the Reduce() function to have the shapes reduced in number of vertices. Works very nicely. However, when sevral of the polygons are adjacent (they share parts of their borders), the reduced polygons do not necessarily do so. Example The SQL batch: CREATE TA...

Algorithm to compute a Voronoi diagram on a sphere?

Hi, I'm looking for a simple (if exists) algorithm to find the Voronoi diagram for a set of points on the surface of a sphere. Source code would be great. I'm a Delphi man (yes, I know...), but I eat C-code too. TIA Steven ...

How to find sign of directed distance?

I have 2 points, P and Q, on a directed line AB in 3D space. They can be anywhere on the line, i.e. not necessarily between A and B. Pythagoras gives you the distance, obviously, but how do I calculate the sign of the directed distance from P to Q? Accepted answer: I was aware of Nick's solution, but I find it ugly because of the test...

Pathfinding on arbitrary non-rectangular bodies

I have various objects whose surfaces are 3D and non rectangular, such as spheres, pyramids, and various other objects represented by meshes. The mesh is not composed of polygons of equal size and distribution across the surface of the object, nor are they all semi/symmetrical objects like the ideal shapes of cylinders, spheres and cones...

How to generate a subdivided icosahedron?

I've asked some questions here and seen this geometric shape mentioned a few times among other geodesic shapes, but I'm curious how exactly would I generate one about a point xyz? ...

How do you detect where two line segments intersect?

How do I determine whether or not two lines intersect, and if they do, at what x,y point? ...

Formula to determine whether a line form by 2 geo points (lat, lon) intersects geo region (circle)?

It does not need to be very accurate. Does anyone know a good way to do this? any help is much appreciated. ...