geometry

Library / Data Structure to store convex polygon with holes

I need to create a map of a building. The area is a convex polygon that has several non-overlapping convex holes. As a simplification, the area can also be expressed as a rectangle. The holes can also be modelled as rectangles. I first tried to handle it with GEOS, a C++ library that comes with a low level C API. But it seemed that GEOS...

Rotation of camera used for perspective projection

Hi, I am trying to perform a simple perspective projection of various 3D structures, defined as a plurality of 3D polygons (different z's), each comprising a plurality of points. The structure will be viewed by a number of different cameras that I define. These cameras are defined by placing a world camera(eye) at (0,0,z) in my world co...

Programming math-based images for use in high-resolution artwork

I'm interested in creating poster-sized images that contain repeating patterns, similar to the two (public domain) images below, the Flower of Life and a Penrose tiling: My questions: How do people usually create images like these on a computer? I'm hoping the answer isn't, "Open Adobe Illustrator and guess at intersection points," ...

Count number of points inside a circle fast

Given a set of n points on plane, I want to preprocess these points somehow faster than O(n^2) (O(nlog(n)) preferably), and then be able to answer on queries of the following kind "How many of n points lie inside a circle with given center and radius?" faster than O(n) (O(log(n) preferably). Can you suggest some data structure or algo...

How to intelligently degrade or smooth GIS data (simplifying polygons)?

I have detailed US county maps, from the TIGER LINE data sets. How might I sample, smooth, or degrade the data so that I get straighter, more boxy, less "noisy" shapes to represent the geographical features -- in this case just county boundaries and state lines, but maybe also in the general case? The sampling could happen at renderin...

circle-circle collision problem

I have a problem with circle-circle collision detection.I used the following algorithm func collision(id,other.id) { var vaP1,vaP2,dis,va1,vb1,va2,vb2,vp1,vp2,dx,dy,dt; if (id!=other.id) { dx=other.x-x; dy=other.y-y; dis=sqrt(sqr(dx)+sqr(dy)); if dis<=radius+other.radius { /...

Finding the closest point from a set of points on plane

Given n points on a 2-D plane, what is the point such that the distance from all the points is minimized? This point need not be from the set of points given. Is it centroid or something else? How to find all such points(if more than one) with an algorithm? ...

Minimising distance: distance formula

I am writing a program in C. I want to find a solution by minimizing expression D1+D2+......+Dn where Di's are distances calculated by distance formula between 2 points. The above expression is in x & y variables Now I will differentiate this expression and find the solution. My doubt is: since in the above expression, all Di's will...

Evaluation of curve in Java2D

Are there methods for evaluating cubic or quadratic Java2D curves at a given time t? I know the algorithm is simple, but I would suspect that there is a method for that already in Java. ...

Shorten a line by a number of pixels

I'm drawing a custom diagram of business objects using .NET GDI+. Among other things, the diagram consists of several lines that are connecting the objects. In a particular scenario, I need to shorten a line by a specific number of pixels, let's say 10 pixels, i.e. find the point on the line that lies 10 pixels before the end point of t...

SQL 2008 geography & geometry - which to use?

I'm creating a Google map mashup and am using SQL 2008. I will have a large number of points on the earth and will want to perform various calculations on them in SQL - such as selecting all points contained within a particular polygone, or select all points within 10km of XY. I have never used and SQL spatial features before. Should I...

Calculating shortest path between 2 points on a flat map of the Earth

How do you draw the curve representing the shortest distance between 2 points on a flat map of the Earth? Of course, the line would not be a straight line because the Earth is curved. (For example, the shortest distance between 2 airports is curved.) EDIT: THanks for all the answers guys - sorry I was slow to choose solution :/ ...

Persisting a valid Geometry shape into Sql Server 2008 Geography column

I am using Spatial.NHibernate to save some geometry shapes to a Geography column in Sql Server 2008. Here is my mapping: public class AreaMapping : ClassMap<Area> { public AreaMapping() { Id(c => c.Id).GeneratedBy.HiLo(100.ToString()); Map(c => c.Name).Not.Nullable(); Map(x => x.Boundary) .Cus...

Chain of connected points and rotation matrices

Thanks for looking at this. I apologize for this rather lengthy build-up but I thought it is needed to clarify things. I have a chain of connected atoms, say a polymer which has rigid bonds and bond angles. With rigid bonds we get the condition that the distance between two immediate neighbours [eg. 2-3,3-4,etc.] is always fixed and the...

The smallest difference between 2 Angles

Given 2 angles in the range -PI -> PI around a coordinate, what is the value of the smallest of the 2 angles between them? Taking into account that the difference between PI and -PI is not 2 PI but zero ...

How can I implement a "Look At" behavior in 3D space

I am trying to implement a "Look At" behavior for planes moving around a sphere so they always face the camera. What I figured out so far, I know the normal that the plane should have and I know that its rotation around its local Z axis should always be 0. I thought it was a pretty trivial operation to figure out the missing rotation va...

How do you find a co-ordinates of a given perpendicular from point (x1 , y1)

I have a polygon which can be regular as well as irregular one. I have to do offsetting/buffering of polygon. I need to stretch the polygon by some amount of offset. The shape should be maintained. ...

How to merge two dynamically created objects overlapping each other?

Hi, Please find my code below. I tried this but didn't succeed. Any help? Path e1 = new Path(); Path e2 = new Path(); e1.Data = new EllipseGeometry(new Rect(new Size(100, 100))); e1.RenderTransform = new TranslateTransform(100, 100); e1.Fill = Brushes.Transparent; e1.Stroke = Brushes.Black; e2.Data = new EllipseGeometry(new Rect(new ...

Bézier curve compute point from one axis

I have a Cubic Bézier curve. But I have a problem when I need only one point. I have only value from the X-axis and want to find a value that coresponds to Y-axis to that point. Or find the t step, from it I can easely calculate the Y-axis. Any clue how to do it? Or is there any formula to do this? ...

How to find the x,y coordinates of a rotated vector

Hi all, I found the best way of calculating the width and height of the bounding box of a vector post-rotation from a different stack overflow post. This worked great. My problem now is calculating the new x,y coordinates of the rotated vector's bounding box. Here is the my javascript. The newWidth, newHeight variables are correct -- the...