**0**

# Equation of a Square?

Started by mrbig, Jan 25 2007 09:02 PM

23 replies to this topic

Sponsor:

###
#5
Members - Reputation: **322**

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.

###
#6
Crossbones+ - Reputation: **2004**

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?

###
#10
Members - Reputation: **1118**

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

*first derivatives*(and hence all that follow) that would be discontinuous. </unnecessary aside>

Admiral

###
#11
Crossbones+ - Reputation: **2004**

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

###
#12
Members - Reputation: **722**

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

###
#16
Crossbones+ - Reputation: **2260**

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

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

###
#17
Members - Reputation: **819**

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/

###
#18
Members - Reputation: **126**

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

###
#20
Members - Reputation: **309**

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