# Equation of a Square?

This topic is 2523 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites
disjointed
a set of separate equations with some arbitrary semantics that indicate when you need to switch from one to the next

##### Share on other sites
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|

##### Share on other sites
you mean something like
r = max(abs(x), abs(y))

##### Share on other sites
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.

##### Share on other sites
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?

##### Share on other sites
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)

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
Quote:
 Original post by erissianIt'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>

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 11
• 13
• 9
• 10
• 12
• ### Forum Statistics

• Total Topics
633002
• Total Posts
3009823
• ### Who's Online (See full list)

There are no registered users currently online

×