• FEATURED

View more

View more

View more

\$10

### Image of the Day Submit

IOTD | Top Screenshots

## Equation of a Square?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

23 replies to this topic

### #1mrbig  Members

Posted 25 January 2007 - 09:02 PM

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?

### #2haphazardlynamed  Members

Posted 25 January 2007 - 09:51 PM

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

### #3erissian  Members

Posted 25 January 2007 - 09:52 PM

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|

### #4nmi  Members

Posted 25 January 2007 - 10:12 PM

you mean something like
r = max(abs(x), abs(y))

### #5Jesper T  Members

Posted 25 January 2007 - 11:10 PM

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.

### #60BZEN  Members

Posted 26 January 2007 - 04:12 AM

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?

### #70BZEN  Members

Posted 26 January 2007 - 04:22 AM

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)

### #8Zipster  Members

Posted 26 January 2007 - 04:36 AM

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.

### #9ToohrVyk  Members

Posted 26 January 2007 - 05:28 AM

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.

Posted 26 January 2007 - 06:00 AM

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>

### #110BZEN  Members

Posted 26 January 2007 - 07:48 AM

Quote:
 Original post by ZipsterActually, 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.

true, which is the same :)

### #12erissian  Members

Posted 26 January 2007 - 08:41 AM

Quote:
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>

Ah, true. My schooling involved heavy use of mathematics and major abuse of it's terminology. :)

### #13Mastaba  Members

Posted 26 January 2007 - 09:11 AM

You could actually get away with using the equation of a superellipse to describe a square, if you use an exponent that is sufficiently high enough such that the deviation from a true square is less than the resolution of the square.

### #14Ultimape  Members

Posted 01 February 2007 - 04:59 PM

square waves are really only a bunch (an infinate bunch) of sine waves added together...

potentially, a square, is really a bunch of wobbly sine waves on a circular spread!

maybe, maybe.

### #15Merlz  Members

Posted 01 February 2007 - 05:08 PM

Here's another one, just for fun:

abs(x) + abs(y) <= 1

Although this one is at 45 degrees rotation to the axis, it's of max radius 1 :-)

### #16iMalc  Members

Posted 01 February 2007 - 05:48 PM

Quote:
 Original post by MerlzHere's another one, just for fun:abs(x) + abs(y) <= 1Although this one is at 45 degrees rotation to the axis, it's of max radius 1 :-)
That's a filled square though (or a filled diamond if you prefer)

A more generic unfilled version of that would be:
abs(x) + abs(y) = r

Of course you could probably rotate that by 45 degrees, which would probably look something like this:

abs(x*sin(45)+y*cos(45)) + abs(x*cos(45)-y*sin(45)) = r

But I'm probably just getting carried away, as nmi has already posted the simplest solution.

### #17Christer Ericson  Members

Posted 01 February 2007 - 06:46 PM

Quote:
 Original post by iMalcA more generic unfilled version of that would be:abs(x) + abs(y) = rOf course you could probably rotate that by 45 degrees, which would probably look something like this:abs(x*sin(45)+y*cos(45)) + abs(x*cos(45)-y*sin(45)) = r
Try:

abs(x + y) + abs(x - y) = r

### #18mbaitoff  Members

Posted 13 February 2007 - 04:35 PM

Equation of a sphere is x^2+y^2=r^2. Equation of a very rounded square is x^4+y^4=r^4. Equation of a square with decreasing roundings is x^p+y^p=r^p, (increasing p). The "limit" of this equation with p->oo is an equation of a square. This "limit" is L_inf metric, max(|x|,|y|).

### #19Ruleroftherealm  Members

Posted 26 November 2011 - 10:42 AM

I don't understand why all these people are answering so damn complicated... the equation for the (unit) square is abs(x)+abs(y)=1

### #20knighty  Members

Posted 26 November 2011 - 01:18 PM

It also have parametric representations:
- Square:
x=infcos(t);
y=infsin(t);
(infPI=4)

-Diamond:
x=abscos(t);
y=abssin(t);
(absPI=2*sqrt(2))

where:
sawtooth(x){
abs((x-4*floor(0.25*x))-2)-1
}
infcos(x){
min(1,max(-1,sawtooth(0.5*x)*2))
}
infsin(x){
infcos(x-2)
}
abscos(x){
x*=sqrt(2)*0.5;
sawtooth(x)
}
abssin(x){
x*=sqrt(2)*0.5;
sawtooth(x-1)
}

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.