Sign in to follow this  
Followers 0
mrbig

Equation of a Square?

23 posts in this topic

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?
0

Share this post


Link to post
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
0

Share this post


Link to post
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|
0

Share this post


Link to post
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.
0

Share this post


Link to post
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?


0

Share this post


Link to post
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)
0

Share this post


Link to post
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.
0

Share this post


Link to post
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.
0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Zipster
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.


true, which is the same :)
0

Share this post


Link to post
Share on other sites
Quote:
Original post by TheAdmiral
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


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

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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 :-)
0

Share this post


Link to post
Share on other sites
Quote:
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 :-)
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.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by iMalc
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
Try:

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

Share this post


Link to post
Share on other sites
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|).
2

Share this post


Link to post
Share on other sites
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
-4

Share this post


Link to post
Share on other sites
It also have parametric representations:
- Square:
x=infcos(t);
y=infsin(t);
(infPI=4):wink:

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

where:[code]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)
}[/code]
0

Share this post


Link to post
Share on other sites
yeah, as mbaitoff says above, to the extent that there is one, wouldn't the "equation of a square" be the limit of

x^n + y^n = 1

as n approaches infinity?

Anyway for practical purposes you can use x^n + y^n = 1 as the equation of a square by choosing a very large value for n. These sorts of shapes are known as "super ellipses". For example check out [url="http://en.wikipedia.org/wiki/Superellipse"]the picture of the squircle in the wikipedia article[/url]. It will get more square-like as n gets bigger.
0

Share this post


Link to post
Share on other sites
[quote name='erissian' timestamp='1169783566' post='3884525']
It's discontinuous (it has corners)
[/quote]

It is continuous, it's just not smooth, and therefore not differentiable.
0

Share this post


Link to post
Share on other sites
Am I the first to have noticed that the thread is from 2007? Because normally someone would have mentioned this!
1

Share this post


Link to post
Share on other sites
[quote name='D_Tr' timestamp='1322341788' post='4887965']
Am I the first to have noticed that the thread is from 2007? Because normally someone would have mentioned this!
[/quote]

Yes. Yes you are. Thanks. Thumbs down to the necromancer. Especially since that's the only post he's made.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0