• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Working with mathematical errors
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Working with mathematical errors


  • Subject: Working with mathematical errors
  • From: Ashley Perrien <email@hidden>
  • Date: Sun, 27 Jul 2008 20:41:02 -0500

What is the most common/accepted way of dealing with the inaccuracies of floating point math? I'm trying to find out 1) Do 2 NSBezierPath lines intersect and then 2) What is the point of the intersection?

Given a couple points on a line I can find the intersection point but since 2 line segments may not intersect, I then check:
if([lineOne containsPoint: intersectionPoint])


That will nearly always fail unless the math works out to very nice, neat, round numbers. I've seen one possible workaround of multiplying everything by 100 and then doing integer math but considering I've got some division involved, not sure exactly if that would work. I guess I could just check the values myself (if point1 is +- .001 of point2) but that seems kinda hackish.

What's the most common way of dealing with these types of problems?

Ashley Perrien
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Working with mathematical errors
      • From: Graham Cox <email@hidden>
    • Re: Working with mathematical errors
      • From: "Michael Ash" <email@hidden>
  • Prev by Date: Re: NSGraphicsContext restore crashes my xtension
  • Next by Date: NSDocument and window ivar
  • Previous by thread: Re: Handle errors within NSURLConnection
  • Next by thread: Re: Working with mathematical errors
  • Index(es):
    • Date
    • Thread