Questions tagged [geometry]

Data structures and algorithms related to geometry.

geometry
Filter by
Sorted by
Tagged with
2029 votes
23 answers
250k views

How do CSS triangles work?

There're plenty of different CSS shapes over at CSS Tricks - Shapes of CSS and I'm particularly puzzled with a triangle: #triangle-up { width: 0; height: 0; border-left: 50px solid ...
Stanislav Shabalin's user avatar
515 votes
27 answers
591k views

How do you detect where two line segments intersect? [closed]

How do I determine whether or not two lines intersect, and if they do, at what x,y point?
KingNestor's user avatar
  • 66.8k
448 votes
56 answers
352k views

Shortest distance between a point and a line segment

I need a basic function to find the shortest distance between a point and a line segment. Feel free to write the solution in any language you want; I can translate it into what I'm using (Javascript)....
438 votes
32 answers
541k views

Calculate distance between 2 GPS coordinates

How do I calculate distance between two GPS coordinates (using latitude and longitude)?
nicudotro's user avatar
  • 7,189
407 votes
21 answers
349k views

Determine if two rectangles overlap each other?

I am trying to write a C++ program that takes the following inputs from the user to construct rectangles (between 2 and 5): height, width, x-pos, y-pos. All of these rectangles will exist parallel to ...
Rob Burke's user avatar
  • 5,435
399 votes
17 answers
371k views

Equation for testing if a point is inside a circle

If you have a circle with center (center_x, center_y) and radius radius, how do you test if a given point with coordinates (x, y) is inside the circle?
user avatar
341 votes
25 answers
374k views

How to determine if a point is in a 2D triangle? [closed]

What is the simplest algorithm to determine if a point is inside a 2d triangle?
ET 0.618's user avatar
  • 3,493
337 votes
25 answers
200k views

How to determine if a list of polygon points are in clockwise order?

Having a list of points, how do I find if they are in clockwise order? For example: point[0] = (5,0) point[1] = (6,4) point[2] = (4,5) point[3] = (1,5) point[4] = (1,0) would say that it is anti-...
Stécy's user avatar
  • 12.2k
308 votes
23 answers
251k views

Generate a random point within a circle (uniformly)

I need to generate a uniformly random point within a circle of radius R. I realize that by just picking a uniformly random angle in the interval [0 ... 2π), and uniformly random radius in the ...
aioobe's user avatar
  • 417k
265 votes
6 answers
461k views

How to do a scatter plot with empty circles in Python?

In Python, with Matplotlib, how can a scatter plot with empty circles be plotted? The goal is to draw empty circles around some of the colored disks already plotted by scatter(), so as to highlight ...
Eric O. Lebigot's user avatar
244 votes
27 answers
268k views

Circle-Rectangle collision detection (intersection)

How can I tell whether a circle and a rectangle intersect in 2D Euclidean space? (i.e. classic 2D geometry)
aib's user avatar
  • 46.2k
243 votes
15 answers
117k views

An algorithm for inflating/deflating (offsetting, buffering) polygons

How would I "inflate" a polygon? That is, I want to do something similar to this: The requirement is that the new (inflated) polygon's edges/points are all at the same constant distance ...
Igor Brejc's user avatar
  • 18.8k
236 votes
6 answers
304k views

Using the "animated circle" in an ImageView while loading stuff

I am currently using in my application a listview that need maybe one second to be displayed. What I currently do is using the @id/android:empty property of the listview to create a "loading" text. ...
Waza_Be's user avatar
  • 39.5k
225 votes
29 answers
188k views

Circle line-segment collision detection algorithm?

I have a line from A to B and a circle positioned at C with the radius R. What is a good algorithm to use to check whether the line intersects the circle? And at what coordinate along the circles ...
Mizipzor's user avatar
  • 51.7k
213 votes
4 answers
259k views

How do I calculate the normal vector of a line segment? [closed]

Suppose I have a line segment going from (x1,y1) to (x2,y2). How do I calculate the normal vector perpendicular to the line? I can find lots of stuff about doing this for planes in 3D, but no 2D ...
Piku's user avatar
  • 3,576
205 votes
15 answers
467k views

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 ...
bmaster's user avatar
  • 2,303
204 votes
2 answers
7k views

Why are my balls disappearing? [closed]

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/...
Yang Pulse's user avatar
  • 2,029
199 votes
18 answers
164k views

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 ...
Befall's user avatar
  • 6,650
198 votes
11 answers
157k views

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 ...
Tom J Nowell's user avatar
  • 9,821
188 votes
9 answers
116k views

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 ...
Philipp Lenssen's user avatar
185 votes
12 answers
189k views

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 ...
183 votes
16 answers
211k views

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 ...
Aaginor's user avatar
  • 4,638
171 votes
31 answers
116k views

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 ...
Nick Fortescue's user avatar
165 votes
26 answers
242k views

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 ...
aneuryzm's user avatar
  • 63.9k
152 votes
6 answers
204k views

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. ...
Phillip B Oldham's user avatar
148 votes
20 answers
102k views

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. ...
user20493's user avatar
  • 5,764
145 votes
10 answers
108k views

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's user avatar
  • 65.9k
140 votes
19 answers
363k views

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's user avatar
139 votes
14 answers
132k views

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's user avatar
  • 2,396
133 votes
10 answers
370k views

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's user avatar
  • 9,460
125 votes
21 answers
171k views

How can you determine a point is between two other points on a line segment?

Let's say you have a two dimensional plane with 2 points (called a and b) on it represented by an x integer and a y integer for each point. How can you determine if another point c is on the line ...
Paul D. Eden's user avatar
  • 20.3k
120 votes
16 answers
291k views

How to calculate an angle from three points? [closed]

Lets say you have this: P1 = (x=2, y=50) P2 = (x=9, y=40) P3 = (x=5, y=20) Assume that P1 is the center point of a circle. It is always the same. I want the angle that is made up by P2 and P3, or in ...
user avatar
117 votes
15 answers
32k views

Combined area of overlapping circles

I recently came across a problem where I had four circles (midpoints and radius) and had to calculate the area of the union of these circles. Example image: For two circles it's quite easy, I can ...
Anton Hansson's user avatar
114 votes
6 answers
74k views

Animate drawing of a circle

I'm looking for a way to animate the drawing of a circle. I have been able to create the circle, but it draws it all together. Here is my CircleView class: import UIKit class CircleView: UIView { ...
Roi Mulia's user avatar
  • 5,816
114 votes
8 answers
84k views

Good geometry library in python? [closed]

I am looking for a good and well developed library for geometrical manipulations and evaluations in python, like: evaluate the intersection between two lines in 2D and 3D (if present) evaluate the ...
Stefano Borini's user avatar
106 votes
15 answers
93k views

How do I calculate the area of a 2d polygon? [duplicate]

Assuming a series of points in 2d space that do not self-intersect, what is an efficient method of determining the area of the resulting polygon? As a side note, this is not homework and I am not ...
Jason Z's user avatar
  • 13.3k
105 votes
9 answers
106k views

Find the point on a circle with given center point, radius, and degree

It's been 10 years since I did any math like this... I am programming a game in 2D and moving a player around. As I move the player around I am trying to calculate the point on a circle 200 pixels ...
Kyle Anderson's user avatar
104 votes
13 answers
143k views

Calculating the position of points in a circle

I'm having a bit of a mind blank on this at the moment. I've got a problem where I need to calculate the position of points around a central point, assuming they're all equidistant from the center and ...
JoeBrown's user avatar
  • 1,051
101 votes
11 answers
113k views

Transparent circle with border

I am trying to create a circle with only a border using XML in android: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape=...
Anirudh's user avatar
  • 2,080
99 votes
3 answers
170k views

Plotting a 3d cube, a sphere and a vector

I search how to plot something with less instruction as possible with Matplotlib but I don't find any help for this in the documentation. I want to plot the following things: a wireframe cube ...
Vincent's user avatar
  • 58.9k
99 votes
10 answers
166k views

Finding whether a point lies inside a rectangle or not

I want to find whether a point lies inside a rectangle or not. The rectangle can be oriented in any way, and need not be axis aligned. One method I could think of was to rotate the rectangle and ...
avd's user avatar
  • 14.2k
98 votes
6 answers
283k views

Draw radius around a point in Google map

I'm using the Google Maps API and have added markers. Now I want to add a 10 mile radius around each marker, meaning a circle that behaves appropriately while zooming. I have no idea how to do that ...
webjunkie's user avatar
  • 6,971
96 votes
11 answers
62k views

How do I combine complex polygons?

Given two polygons: POLYGON((1 0, 1 8, 6 4, 1 0)) POLYGON((4 1, 3 5, 4 9, 9 5, 4 1),(4 5, 5 7, 6 7, 4 4, 4 5)) How can I calculate the union (combined polygon)? Dave's example uses SQL server to ...
grenade's user avatar
  • 31.8k
91 votes
11 answers
237k views

How do I compute the intersection point of two lines?

I have two lines that intersect at a point. I know the endpoints of the two lines. How do I compute the intersection point in Python? # Given these endpoints #line 1 A = [X, Y] B = [X, Y] #line 2 ...
bolt19's user avatar
  • 2,023
88 votes
6 answers
27k views

Position of the sun given time of day, latitude and longitude

This question has been asked before a little over three years ago. There was an answer given, however I've found a glitch in the solution. Code below is in R. I've ported it to another language, ...
SpoonNZ's user avatar
  • 3,789
87 votes
10 answers
168k views

Using atan2 to find angle between two vectors

I understand that: atan2(vector.y, vector.x) = the angle between the vector and the X axis. But I wanted to know how to get the angle between two vectors using atan2. So I came across this solution: ...
user3150201's user avatar
  • 1,931
85 votes
10 answers
116k views

Drawing Sphere in OpenGL without using gluSphere()?

Are there any tutorials out there that explain how I can draw a sphere in OpenGL without having to use gluSphere()? Many of the 3D tutorials for OpenGL are just on cubes. I have searched but most of ...
Carven's user avatar
  • 15.3k
84 votes
2 answers
27k views

Algorithm for finding the fewest rectangles to cover a set of rectangles without overlapping

I have a set of rectangles and I would like to "reduce" the set so I have the fewest number of rectangles to describe the same area as the original set. If possible, I would like it to also be fast, ...
Mike Dour's user avatar
  • 3,666
83 votes
10 answers
102k views

Signed angle between two 3D vectors with same origin within the same plane

What I need is a signed angle of rotation between two vectors Va and Vb lying within the same 3D plane and having the same origin knowing that: The plane contatining both vectors is an arbitrary and ...
Advanced Customer's user avatar
83 votes
12 answers
94k views

Calculate Bounding box coordinates from a rotated rectangle

I have the coordinates of the top left point of a rectangle as well as its width, height and rotation from 0 to 180 and -0 to -180. I am trying to get the bounding coordinates of the actual box ...
coulix's user avatar
  • 3,338

1
2 3 4 5
263