×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    12

    how to get the distance between two points

    In J2me, only use +,-,*,/, how to get the distance of 2 points(x1,y1) and (x2,y2)?

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395
    You need to use Pythagoras to do this, for which you'll need to perform a square-root. You'll need to write your own square-root method; do a search for "Newton-Raphson method".

    If you don't need to know the actual distance, but just, say, which of two distances is smaller, then you can skip the square-root step and just compare the sum of the squares.

    Graham.

  3. #3
    Regular Contributor
    Join Date
    Mar 2005
    Posts
    249
    IF you need to use alot more floating point math than just the sqrt, then try using a library like mathfp.

    Cheers.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •