Slope-Intercept vs Endpoint Pairs - Data Structure

In a graphics based programming, I’m starting to get the impression that it is better to store data in slope-intercept form rather than the raw start and end points.

Is my impression correct?

Why?

Hi.

Posted Jan 10, 2018, 11:05 PM UTC · edited

49
Meefims•

This question is better suited to a programming sub because how you store data depends significantly and how you use it. Mathematically the two are the same.

3
OneFishTwoFish42OP•

I kind of thought that too, but was torn.

I’ll post to one of those as well. Or cross post if I can.

2
SpaceEnthusiast•

Not exactly. The line segment (0, 0) to (0, 1), for example.

1
lewisje•

You can store a line segment as

  • its endpoints (four numbers in total, if this line segment is in a particular plane)
  • its start point, length, and direction angle (again, four numbers, only degenerate case is the point)
  • the slope and y-intercept of the line and the x-coordinates of its start and end (four numbers, degenerate case is a vertical line segment)

To store a line, it's probably better to go by a particular point on the line and its direction angle (three numbers), or two particular points on the line (still four numbers), just so you can still represent vertical lines.


Also, r/learnprogramming is a better idea, and maybe r/gamedev.

1
OneFishTwoFish42OP•

Thanks. You’re mentioning vertical lines just because of the special case where the slope is not defined?

3
lewisje•

yes

2
jacobolus•

I recommend against using angle measure if you can help it. Store a segment either as coordinates of the start point and a displacement vector between the two ends, or two pairs of point coordinates. For a line, the right format depends what you want to do with it. Sometimes it makes sense to put it in a form like ax + by = c and store a, b, and c.

3
lewisje•

There is definitely loss of precision with both storage and usage of the direction angle.

2
jacobolus•

Not just loss of precision, but also circular functions are a pain in the butt and almost always unnecessary.

4