New answers tagged

1

A couple of possibilities: The vector form of the equation for a straight line in 2 dimensions is n.x + s = 0, where 'n' is a vector normal (or perpendicular) to the line "." is the vector dot product operation, and s is a scalar constant. This allows you to represent arbitrary lines with two integers and a double. (note that the same representation in 3 ...


0

A single bit saying if the line is closer to horizontal or vertical. If closer to horizontal, slope + Y-intercept. If closer to vertical, inverse slope + X-intercept. That's two doubles, plus a bit. Equality testing is trivial.


9

The equations can be all rewritten into form : a*X + b*Y + c = 0 That means you can store three doubles a, b and c. This doesn't have a problem in representing an arbitrary slope. You can also calculate slope as a/b (or b/a). Two lines are equal if there exists k where a1*k = a2, b1*k=b2, c1*k = c2.


2

Possible methods For convenience of expression, this class will be used to represent any real points in a coordinate system in code snippets below: public class Point{ public double x, y; @Override public boolean equals(Object other){ if(!(other instanceof Point)) return false; Point point = (Point) other; return point.x == ...


0

First, I'll repeat that a modulo b should be equal to a - b * (a div b), and if a language doesn't provide that, you are in an awful mathematical mess. That expression a - b * (a div b) is actually how many implementations calculate a modulo b. There are some possible rationales. The first is that you want maximum speed, so a div b is defined as whatever ...



Top 50 recent answers are included