Wednesday, February 13, 2008

Intersection between two lines

This is a sample C++ code to find the intersection between two lines.

Point findIntersection(Point p1,Point p2, Point p3,Point p4)
{
float xD1,yD1,xD2,yD2,xD3,yD3;
float dot,deg,len1,len2;
float segmentLen1,segmentLen2;
float ua,ub,div;

//calculate differencesxD1=p2.x-p1.x;
xD2=p4.x-p3.x;
yD1=p2.y-p1.y;
yD2=p4.y-p3.y;
xD3=p1.x-p3.x;
yD3=p1.y-p3.y;

// calculate the lengths of the two lines
len1=sqrt(xD1*xD1+yD1*yD1);
len2=sqrt(xD2*xD2+yD2*yD2);

// calculate angle between the two lines.
dot=(xD1*xD2+yD1*yD2); // dot product
deg=dot/(len1*len2);

// if abs(angle)==1 then the lines are parallell,
// so no intersection is possible
if(abs(deg)==1) return null;

// find intersection Pt between two lines
Point pt=new Point(0,0);
div=yD2*xD1-xD2*yD1;
ua=(xD2*yD3-yD2*xD3)/div;
ub=(xD1*yD3-yD1*xD3)/div;
pt.x=p1.x+ua*xD1;
pt.y=p1.y+ua*yD1;

// calculate the combined length of the two segments
// between Pt-p1 and Pt-p2
xD1=pt.x-p1.x;
xD2=pt.x-p2.x;
yD1=pt.y-p1.y;
yD2=pt.y-p2.y;
segmentLen1=sqrt(xD1*xD1+yD1*yD1)+sqrt(xD2*xD2+yD2*yD2);

// calculate the combined length of the two segments
// between Pt-p3 and Pt-p4
xD1=pt.x-p3.x;
xD2=pt.x-p4.x;
yD1=pt.y-p3.y;
yD2=pt.y-p4.y;
segmentLen2=sqrt(xD1*xD1+yD1*yD1)+sqrt(xD2*xD2+yD2*yD2);

// if the lengths of both sets of segments are the same as
// the lenghts of the two lines the point is actually
// on the line segment.

// if the point isn't on the line, return null

if(abs(len1-segmentLen1)>0.01 abs(len2-segmentLen2)>0.01)

return null;

// return the valid intersection

return pt;

}

class Point
{
float x,y;
Point(float x, float y)
{ this.x = x; this.y = y; }

void set(float x, float y)
{
this.x = x; this.y = y;
}
}

Friday, February 8, 2008

Free ebooks links

Following are the free e-book links. Hope those may be useful to the book lovers.

http://www.gutenberg.org/
http://www.bibliomania.com/
http://www.readprint.com/
http://www.readbookonline.net/
http://www.fictionpress.com/
http://etext.lib.virginia.edu/
http://www.free-ebooks.net/
http://manybooks.net/
http://www.worldwideschool.org/library/c...
http://www.thefreelibrary.com/
http://www.baen.com/library/
http://www.ebooks3.com/
http://www.bookyards.com/
http://www.free-online-novels.com/
http://www.starry.com/novel/authors.htm
http://www.bygosh.com/thebestnovels.htm
http://www.bookspot.com/ask/
http://www.online-literature.com/
http://onlinebooks.library.upenn.edu/
http://www.infomotions.com/alex/
http://www.pagebypagebooks.com/
http://www.literature.org/

Marriage & Love

  • I recently read that love is entirely a matter of chemistry. That must be why my wife treats me like toxic waste. - David Bissonette

  • When a man steals your wife, there is no better revenge than to let him keep her. - Sacha Guitry

  • After marriage, husband and wife become two sides of a coin; they just can't face each other, but still they stay together. - Hemant Joshi

  • By all means marry. If you get a good wife, you'll be happy. If you get a bad one, you'll become a philosopher. - Socrates

  • Woman inspires us to great things, and prevents us from achieving them. - Dumas

  • The great question... which I have not been able to answer... is, "What does a woman want? - Sigmund Freud

  • I had some words with my wife, and she had some paragraphs with me. - Anonymous

  • Some people ask the secret of our long marriage. We take time to go to a restaurant two times a week. A little candlelight, dinner, soft music and dancing. She goes Tuesdays, I go Fridays..
    - Henny Youngman

  • "I don't worry about terrorism. I was married for two years.." - Sam Kinison

  • "There's a way of transferring funds that is even faster than electronic banking. It's called marriage." - James Holt McGavran

  • "I've had bad luck with both my wives. The first one left me, and the second one didn't." - Patrick Murray

  • Two secrets to keep your marriage brimming. (a) Whenever you're wrong, admit it. (b) Whenever you're right, shut up. - Nash

  • The most effective way to remember your wife's birthday is to forget it once... - Anonymous

  • You know what I did before I married? Anything I wanted to. - Henny Youngman

  • My wife and I were happy for twenty years. Then we met. - Rodney Dangerfield

  • A good wife always forgives her husband when she's wrong. - Milton Berle

  • Marriage is the only war where one sleeps with the enemy. - Anonymous

  • A man inserted an 'ad' in the classifieds: "Wife wanted". Next day he received a hundred letters. They all said the same thing: "You can have mine. - Anonymous

  • First Guy (proudly): "My wife's an angel!" Second Guy: "You're lucky, mine's still alive."