Mail Archives: geda-user/2013/08/19/13:16:26
On 08/18/2013 05:23 PM, Stefan Salewski wrote:
> On Sun, 2013-08-18 at 20:58 +0100, Gareth Edwards wrote:
> Yes, my statement may be a bit harsh -- but all the garbage in the
> Internet makes me really some sort of angry. Most of the time Google
> does a good job to skip all that dirt, but more and more often it fails.
> It is my impression that the volume of junk increases much faster now
> than the valuable content -- in the end the whole internet will become a
> large heap of garbage. Wikipedia may be left of the only reliable source
> of information. Recently I was looking for the formula for intersection
> of two line segments -- tried one promising google hit:
>
> http://cboard.cprogramming.com/c-programming/154196-check-if-two-line-segments-intersect.html
>
> It is wrong -- I contacted the original author, that forum thread was
> closed, so he was not able to correct it. One hour wasted of my time.
>
> I just checked the exact meaning of 'simple minded' at www.leo.org, one
> translation is the german word "einfältig", which is indeed harsh. But
> currently I have not really a more adequate term available in my head --
> guess I am too simple minded.
>
Gareth,
There's a lesson in there somewhere. If you are going to rely on the
internet for an education in basic algebra, I suspect that you will more
often than not get what you pay for. It is almost always better to do
your own math and avoid both the problems with others poor math skills
as well as their poor programming skills. By the way, for simple
straight line segments, just write 2 linear equations with a common "x"
and find the intersection. It is then a simple thing to ascertain if the
intersection is bounded by the line's endpoints. To wit, take the 2 lines:
Y1=m1x+b1 and Y2=m2x+b2.
Calculate the slopes (m) and intercepts (b) from the endpoints. The
value of x that gives the same value of Y for both line is by definition
the intersection. So set these 2 equal and solve for "x". You should get
something like:
x=(b2-b1)/(m1-m2)
This is the "x" value of the intersection. Then you can use either
line's equation to calculate the corresponding value of "y" at the
intersection. Note that you can do exactly the same with curves that are
defined with a quadratic. You just have to solve for x using the
standard quadratic solution:
x=(-b+- sqrt (b^2-4ac))/2a
Just remember that you will get 2 solutions (one may be imaginary) and
you will need to figure out how to decide which one is relevant. Higher
order curves - other than cubics - have no closed form solutions and
intersection will need to be determined numerically.
-- fictio cedit veritati
- Raw text -