16
$\begingroup$

I need to graph a rectangle on the Cartesian coordinate system. Is there an equation for a rectangle? I can't find it anywhere.

  • 0
    An *implicit* Cartesian equation would be the one Peter gave. Methinks that ain't much. Maybe you want a parametric equation?2011-10-01

11 Answers 11

21

Based on Raskolnikov's answer here, one can build an implicit Cartesian equation for a $2p \times 2q$ rectangle:

$\left(\frac{x}{p}\right)^2+\left(\frac{y}{q}\right)^2=\sec\left(\arctan\left(\frac{x}{p},\frac{y}{q}\right)-\frac{\pi}{2}\left\lfloor\frac2{\pi}\arctan\left(\frac{x}{p},\frac{y}{q}\right)+\frac12\right\rfloor\right)^2$

Another one is based on modifying the implicit equation of a Lamé curve:

$\left|\frac{x}{p}+\frac{y}{q}\right|+\left|\frac{x}{p}-\frac{y}{q}\right|=2$


For purposes of plotting with a computer, the implicit equation isn't terribly convenient to handle, so I'll throw in a set of parametric Cartesian equations for free, based on the parametric equations of the Lamé curve:

$\begin{align*}x&=p\left(|\cos\,t|\cos\,t+|\sin\,t|\sin\,t\right)\\y&=q\left(|\cos\,t|\cos\,t-|\sin\,t|\sin\,t\right)\end{align*}$

Here's another one, based on a special case of the parametric equations given in this answer:

$\begin{align*}x&=p\left(\cos\left(\frac{\pi}{2}\lfloor u\rfloor\right)-(2u-2\lfloor u\rfloor-1)\sin\left(\frac{\pi}{2}\lfloor u\rfloor\right)\right)\\y&=q\left(\sin\left(\frac{\pi}{2}\lfloor u\rfloor\right)+(2u-2\lfloor u\rfloor-1)\cos \left(\frac{\pi}{2}\lfloor u\rfloor\right)\right)\end{align*}$

...and another one:

$\begin{align*}x&=p\max\left(-1,\min\left(\frac4{\pi}\arcsin\left(\sin\left(\frac{\pi u}{2}+\frac{\pi}{4}\right)\right),1\right)\right)\\y&=q\max\left(-1,\min\left(-\frac4{\pi}\arcsin\left(\cos\left(\frac{\pi u}{2}+\frac{\pi}{4}\right)\right),1\right)\right)\end{align*}$

...and I suppose I should stop here. ;)

  • 0
    Forgot link: http://math.stackexchange.com/questions/655369/coordinate-of-intersection-between-line-and-square2014-01-29
7

This is an equation for a rectangle which has corners at $(a,b)$ and $(c,d)$

$(x-a)(x-c)(y-b)(y-d)=0$

but it extends a little beyond the corners, so instead

$\sqrt{(a-x)(x-c)}\sqrt{(b-y)(y-d)}=0$

which would throw an error for square roots of negative numbers

5

I found recently a new parametric form for a rectangle, that I did not know earlier: $ \begin{align} x(u) &= \frac{1}{2}\cdot w\cdot \mathrm{sgn}(\cos(u)),\\ y(u) &= \frac{1}{2}\cdot h\cdot \mathrm{sgn}(\sin(u)),\quad (0 \leq u \leq 2\pi) \end{align} $ where $w$ is the width of the rectangle and $h$ is its height.

I have used this in modelling parametric ruled surfaces, where it seems to be rather handy.

4

Try plotting $x^n + y^n = p^n$ where $p$ is the side length and $n$ is an even number. The larger $n$ is, the sharper the sides are.

  • 0
    +1. This is a great generalization of "rectangular-ish" shapes since $\lim_{n \to \infty}$ of $x^n+y^n=p^n$ actually gives the Max Norm: https://en.wikipedia.org/wiki/Uniform_norm2015-12-10
2

Maybe you're looking for something like this: for $x\in(-1,2)$ plot $y=|x|$ and $y=3-|x-1|$.

2

In general, the implicit formula for a rectangle a la $x^2 + y^2 = a^2$ for circles is not going to be well defined. This should be at least somewhat clear, as the boundary of a rectangle is not analytic (smooth) like the boundary of a circle is. I suppose we could generate a piece wise function to graph the edges, something like: $f(x,y) = \begin {cases} (x,b) , (x,0) & 0 \leq x \leq b \\ (0,y) , (a,y) & 0 \leq y \leq a \end {cases}$ For a rectangle with its bottom left corner at (0,0) and sides a,b. Such a function is messy, still non-analytic and doesn't help you that much. Ultimately, I think searching for a good implicit function of a rectangle is going to be nonproductive. What problem are you trying to apply this to? Any comment as to your next steps / applications for the equation you're searching for will prove helpful.

2

This is very easy. Instead of using all of that complex math, you can instead just use the rotation matrix to rotate a simple absolute value function.

$ \begin{pmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \\ \end{pmatrix} \begin{pmatrix} x \\ y \\ \end{pmatrix} $

$ x_1 = x_0\cos \theta - y_0\sin\theta\\ y_1 = x_0\sin \theta + y_0\cos \theta\\ $

Afterwards substitute the angle to be 45°. The original equation is |x|+|y|=c This is because the absolute value is at a 45 degree angle.

$ |\frac {\sqrt{2}}{2}x+\frac {\sqrt{2}}{2}y|+|\frac {\sqrt{2}}{2}x-\frac {\sqrt{2}}{2}y| = c $

1

If the equations of the diagonals of the rectangle are Ax + By + C = 0 and Dx + Ey + F = 0 then an equation for the rectangle is:

M|Ax + By + C| + N|Dx + Ey + F| = 1

M and N can be found by substituting the coordinates of two adjacent vertices of the rectangle.

In fact, this equation can be used to describe any parallelogram. Roughly speaking, M (together with A and B) and N (together with D and E) give the size of the diagonals of the parallelogram.

0

There is another interesting form using the Heaviside step function: $\theta(x)$.

If the sides are $a$ and $b$ and the rectangle is centered at $(x_0,y_0)$ then: $(y-y_0)^2+\alpha\theta\left[(x-x_0)^2-\frac{a^2}{4}\right]=\frac{b^2}{4}$

where $4\alpha>b^2$.

0

This is very easy. Instead of using all of that complex math, you can instead just use the rotation matrix to rotate a simple absolute value function.

$ \begin{pmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \\ \end{pmatrix} \begin{pmatrix} x \\ y \\ \end{pmatrix} $

$ x_1 = x_0\cos \theta - y_0\sin\theta\\ y_1 = x_0\sin \theta + y_0\cos \theta\\ $

-1

Lets say the rectangle is centred at $c(h,k)$ and half the length is $a$ and half the width is $b$.

The equation for this rectangle would be:

$(\frac{x-h}{a})^\infty+(\frac{y-k}{b})^\infty=1$

  • 0
    @Rahul 1: Can you direct me to a proof that my equation is not a thing ? 2: Graphing software seems to think it is a thing, which is what the OP asked for. 3: A large even number can be used instead of $\infty$ for a close approximation.2018-07-31