A better way to solve problems than using functions..?

Recommended Posts

First of all a NOTE: functions as in y=ax+b not void foo(); What I am saying is, I've been working on some calculations lately (which require calculating segment intersection, line intersection, calculating coords, rotation etc.) and since I am a math person I've tried the first and most obvious way of solving them - using functions. Now the methods I've used work really great, the answers I get are pretty accurate and all, however I'm starting to dislike using functions when solving geometrical problems due to one problem... infinite slope. Since float cannot have an infinite value, every time I'm working with a function I have to check if its slope isn't infinite. This is ok for smaller stuff but when I have to calculate intersection points of 3 different lines... things get a little messy. So yeah, is there a better, commonly known alternative to solving different geometrical problems with functions? The only thing I thought of is using a really big number for infinite slope (say, 1 000 000 or so) - if you consider that your typical screen width/height is about 1000 pixels it should work just fine. But there is always that small inaccuracy... or am I worrying too much?

Share on other sites
use vector equations of lines

[Edited by - petewood on August 4, 2004 4:43:48 AM]

Share on other sites
Instead of y=ax+b use Ax+By=C (which I guess are the vector equations Pete reffered to).

shmoove

Share on other sites
I could've sworn float's could store infinity...

Share on other sites
Quote:
 Original post by Holy FuzzI could've sworn float's could store infinity...

Anything a bit less is a problem

Share on other sites
I just glanced at the site petewood referenced, but it looked like the vector form of lines is more complicated than need be. Using the parametric equation from two points (Line=P1+U*(P2-P1)), http://astronomy.swin.edu.au/~pbourke/geometry/ works out several equations quite nicely. It sounds like you need more complex equations than they give, but using this form might help some..?

-Extrarius

Create an account

Register a new account

• Forum Statistics

• Total Topics
628306
• Total Posts
2981948

• 10
• 11
• 12
• 11
• 10