Questions tagged [geometry]

Data structures and algorithms related to geometry.

Data structures and algorithms related to geometry, a branch of mathematics concerned with questions of shape, figures, and dimensions in space.

See also Wikipedia

12992 questions
204
votes
15 answers

Easier way to create circle div than using an image?

I'm wondering if there's an easier way to create circular divs than what I'm doing now. Currently, I am just making an image for each different size, but it's annoying to do this. Is there anyway using CSS to make divs which are circular and I can…
bmaster
  • 2,293
  • 2
  • 16
  • 12
203
votes
2 answers

Why are my balls disappearing?

Pardon the funny title. I've created a little graphic demo of 200 balls bouncing and colliding, both against the walls and each other. You can see what I have currently here: http://www.exeneva.com/html5/multipleBallsBouncingAndColliding/ The…
Yang Pulse
  • 2,019
  • 1
  • 12
  • 13
191
votes
18 answers

Evenly distributing n points on a sphere

I need an algorithm that can give me positions around a sphere for N points (less than 20, probably) that vaguely spreads them out. There's no need for "perfection", but I just need it so none of them are bunched together. This question provided…
Befall
  • 6,560
  • 9
  • 24
  • 29
190
votes
11 answers

How can I find the smallest difference between two angles around a point?

Given a 2D circle with 2 angles in the range -PI -> PI around a coordinate, what is the value of the smallest angle between them? Taking into account that the difference between PI and -PI is not 2 PI but zero. An Example: Imagine a circle, with 2…
Tom J Nowell
  • 9,588
  • 17
  • 63
  • 91
183
votes
8 answers

Sort points in clockwise order?

Given an array of x,y points, how do I sort the points of this array in clockwise order (around their overall average center point)? My goal is to pass the points to a line-creation function to end up with something looking rather "solid", as convex…
Philipp Lenssen
  • 8,818
  • 13
  • 56
  • 77
181
votes
12 answers

Circle drawing with SVG's arc path

Using SVG path, we can draw 99.99% of a circle and it shows up, but when it is 99.99999999% of a circle, then the circle won't show up. How can it be fixed? The following SVG path can draw 99.99% of a circle: var paper = Raphael(0, 0, 300,…
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
177
votes
16 answers

How to tell whether a point is to the right or left side of a line

I have a set of points. I want to separate them into 2 distinct sets. To do this, I choose two points (a and b) and draw an imaginary line between them. Now I want to have all points that are left from this line in one set and those that are right…
Aaginor
  • 4,516
  • 11
  • 51
  • 75
166
votes
31 answers

How do you calculate the average of a set of circular data?

I want to calculate the average of a set of circular data. 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…
Nick Fortescue
  • 43,045
  • 26
  • 106
  • 134
157
votes
25 answers

How can I check if two segments intersect?

How can I check if 2 segments intersect? I've the following data: Segment1 [ {x1,y1}, {x2,y2} ] Segment2 [ {x1,y1}, {x2,y2} ] I need to write a small algorithm in Python to detect if the 2 lines are intersecting.
aneuryzm
  • 63,052
  • 100
  • 273
  • 488
149
votes
6 answers

Simple calculations for working with lat/lon and km distance?

Is there a simple calculation I can do which will convert km into a value which I can add to a lat or lon float to calculate a bounding box for searches? It doesn't need to be completely accurate. For instance: if I were given a lat/lon for London,…
Phillip B Oldham
  • 18,807
  • 20
  • 94
  • 134
148
votes
20 answers

Algorithm to detect intersection of two rectangles?

I'm looking for an algorithm to detect if two rectangles intersect (one at an arbitrary angle, the other with only vertical/horizontal lines). Testing if a corner of one is in the other ALMOST works. It fails if the rectangles form a cross-like…
user20493
  • 5,704
  • 7
  • 34
  • 31
140
votes
19 answers

How to draw circle in html page?

How do you draw a circle using HTML5 and CSS3? Is it also possible to put text inside?
Sergey Metlov
  • 25,747
  • 28
  • 93
  • 153
139
votes
10 answers

How to create circle with Bézier curves?

We have a start point (x, y) and a circle radius. There also exists an engine that can create a path from Bézier curve points. How can I create a circle using Bézier curves?
Rella
  • 65,003
  • 109
  • 363
  • 636
134
votes
15 answers

Postgis installation: type "geometry" does not exist

I am trying to create table with Postgis. I do it by this page. But when I import postgis.sql file, I get a lot of errors: ERROR: type "geometry" does not exist Does anybody know how can I fix it?
yetty
  • 2,326
  • 2
  • 19
  • 22
128
votes
10 answers

Converting from longitude\latitude to Cartesian coordinates

I have some earth-centered coordinate points given as latitude and longitude (WGS-84). How can i convert them to Cartesian coordinates (x,y,z) with the origin at the center of the earth?
daphshez
  • 9,272
  • 11
  • 47
  • 65