Welcome, Guest. Please login or register.

Author Topic: Calculate whether a point exists on a line  (Read 3166 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Calculate whether a point exists on a line
« on: September 01, 2007, 01:34:03 PM »
From your other thread about scores, if floating point is too much of a performance hit, try fixed point.

Depending on your screen's spatial resolution, you arent likely to encounter extreme gradients (except in the straight vertical/hortizontal cases, which should be handled separately)*

In other words, suppose your screen size was 640x480. The steepest non-vertical gradient you will be able to represent on screen anyway is 480 (ie dy/dx = 480) and the shallowest is 1/640.

You can use a signed 15:16 fixed point format (basically 32-bit signed integer where the lowest 16-bits are assumed to be fractional) which is more than precise enough for any screen based calculation you need to do at that resolution.

*a word of warning. If your line is vertical, the basic gradient is going to be infinite, since dx=0. If you use your basic 2D equation of a line approach as presented, you need to handle pure vertical lines as a special case.
int p; // A