MarbleMice.com

Hacking the trees of knowledge.

Archive for the ‘Geometry’ Category

Distance Between A Point And A Line.

without comments

As seen in the diagram we define a line segment to be between P1 and P2 and want to know the Point on the line segment that is closest to our point P3. We call this closest point on the line point P. An assumption is made that P1 and P2 are not co-incident (exactly the same).

Closest point on a line diagram

We can write the Point P as

P=P1+u(P2-P1)

where u is a simple scaler. If we can work out u then it is easy to find P. For a line segment u must be between 0 an 1 as this keeps P between P1 and P2. If we are considering an infinite line defined by P1 and P2 then u can be any value.

The shortest distance is given when the line between P3 to P and the line p1 to p2 is perpendicular to each other. That is they have an angle of 90 degrees. The 90 degrees should give you a hint that we will need to use the dot product (inner product) to solve this problem. When the angle between two lines is 90 degree the dot product is zero. Therefor

(P2-P1) dot (P3-P) = 0

Substitute in the value for P we obtain

 (P2-P1) dot ( P3-P1-u(P2-P1)) = 0
Then is you site down and solve this you get

 u = \frac{(x3-x1)(x2-x1) + (y3-y1)(y2-y1)}{ |P2-P1|^2}

Now you know u find P is trivial.

Remember to clamp u between 0 and 1 if you are solving for the line segment rather than the infinite line case.

Written by birdle

November 6th, 2007 at 10:55 am

Posted in Geometry

Douglas Peuker Line Simplification Explained.

with 3 comments

Douglas Peuker Line simplification algorithm was first published in 1973 and has been a firm favourite ever since. Well I can’t be sure about the early years but google sure likes throwing up the algorithm when you search for line simplification. In this article I give an overview of how the algorithm works. It may be a bit wordy for those who prefer math equations but the idea it to present this in an accessible way. Part of the beauty of the Douglas Peuker algorithm is its simplicity and I hope to convey that here.

Read the rest of this entry »

Written by birdle

September 12th, 2007 at 8:56 pm

Posted in Geometry

Selecting a Random Point in a Triangle

without comments

Given a triangle defined by the 3 points a, b, c and given the vectors AB,AC going from point a to points b and c respectively as shown in the diagram below. Read the rest of this entry »

Written by birdle

June 21st, 2007 at 12:50 pm

Posted in Geometry

Bounding Circles – Algorithm Comparision

without comments

Repost from old site.
Introduction
In this article I am going to discuss how given a set of points you can generate a circle that encompasses them. Calculation of the best possible fit for n points has an O(n^3) dependence making it unsuitable for large data sets or real time applications. We have to use our brains to generate a good approximation to the optimum solution; I should say use other peoples brains as this is a well researched topic. To keep this article a reasonable length I will focus on a few algorithms that have guaranteed O(n) behaviour. These tend to be the simplest to implement but it does mean we exclude some good algorithms like the one discussed in Eberly[1]. Read the rest of this entry »

Written by birdle

September 4th, 2006 at 8:33 pm

Posted in Geometry