Equation of a Square?

Started by
22 comments, last by Cornstalks 12 years, 4 months ago
This is going to be quite a strange question... Does a _square_ have an equation? You know, an equation for the points on a square? For a circle there's r^2 = dx^2 + dy^2, but what would a square equation look like?
Advertisement
disjointed
a set of separate equations with some arbitrary semantics that indicate when you need to switch from one to the next
It's discontinuous (it has corners) and isn't a function, so it's not as straight forward, but thinking about it, this seems like it might work:

x = |d|, y = |d|, for all x,y ≤ |d|
We''re sorry, but you don''t have the clearance to read this post. Please exit your browser at this time. (Code 23)
you mean something like
r = max(abs(x), abs(y))
If you want to draw the square I guess a useful way would be to describe it as a linear combination of two perpendicular unit vectors.

For example, with the two vectors

A = (0, -1, 0)
B = (1, 0, 0)

Any point in the square is given by

P = Ar + Bs

Where r, s <= l (and l = length of the sides of the square).

If you want to describe the edge you just fix either r or s at 0 or l and you have a line equation.

A and B doesn't have to be unit vectors though, but it makes it easier to set the size of the square if they are.
Equation of a triangle

P in triangle (A, B, C) :

P = A + t * (B - A) + u * (C - A)
0 <= t <= 1,
0 <= u <= 1,
0 <= (t+u) <= 1,

let's say a parallelogram, which is like, two triangles... I am not sure waht would be the constraints on that.

0 <= (t+u) <= 2 maybe?


Everything is better with Metal.

another one :)

say you have square (x0, y0)-(x1, y1) (x0 < x1, y0 < y1)

x = min(max(x, x0), x1)
y = max(min(y, y0), y1)

Everything is better with Metal.

Actually, you just remove the the sum restriction u + t ≤ 1 completely to get the full quadrilateral (keep 0 ≤ u/t ≤ 1). But it describes the entire inner area. You would have more logic to get just the edges.
As nmi said, the equation for a zero-centered axis-aligned square of edge 2r is:

max(|x|,|y|) = r

You may apply a transform first to rotate, move or scale the square.
Quote:Original post by erissian
It's discontinuous (it has corners)

Not quite. A square is continuous (there are certainly no gaps), but it isn't smooth. If one were to describe it piecewise-implicitly or parametrically, then it's the first derivatives (and hence all that follow) that would be discontinuous. </unnecessary aside>

Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.

This topic is closed to new replies.

Advertisement