Started by Jan 25 2007 09:02 PM

,
23 replies to this topic

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?

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

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

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|

x = |d|, y = |d|, for all x,y ≤ |d|

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.

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.

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?

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?

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)

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

x = min(max(x, x0), x1)

y = max(min(y, y0), y1)

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.

Posted 26 January 2007 - 06:00 AM

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

Admiral

Posted 26 January 2007 - 07:48 AM

Quote:

Original post by Zipster

Actually, you justremovethe 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 :)

Posted 26 January 2007 - 08:41 AM

Quote:

Original post by TheAdmiralQuote:

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 thefirst derivatives(and hence all that follow) that would be discontinuous. </unnecessary aside>

Admiral

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

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.

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.

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

maybe, maybe.

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

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

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

Posted 01 February 2007 - 05:48 PM

Quote:That's a filled square though (or a filled diamond if you prefer)

Original post by Merlz

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

A more generic

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.

Posted 01 February 2007 - 06:46 PM

Quote:Try:

Original post by iMalc

A more genericunfilledversion 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

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

Christer Ericson

http://realtimecollisiondetection.net/blog/

http://realtimecollisiondetection.net/blog/

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|).

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

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:

- 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) }