Jump to content
  • Advertisement
Sign in to follow this  
mrbig

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.

If you intended to correct an error in the post then please contact us.

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 this post


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

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?


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)

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.

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.

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!