2

Given the four corners $(x, y)$ of a square, the center $(x, y)$, and a starting direction (ex: $45^\circ$) around a $360^\circ$ rotation ($0^\circ/360^\circ$ at the top), how do you find out the intercept on the perimeter as the direction is incrementally stepped?

What I'm basically doing is taking a circle of radius $(r)$, determining it's area $(A)$, converting that to length $(L)$ of the sides of the square, and then determining the corners $(x, y)$ given the starting center point and the above described direction. This allows for the square to rotate it's starting position depending on the direction. I used the equations below to determine the corners (assuming $(x, y)$ is the center of the circle):

$$\left(x - \frac{L}{2} * (\sin(\text{rotation}) - \cos(\text{rotation})), y + \frac{L}{2} * (\sin(\text{rotation}) + \cos(\text{rotation}))\right)$$ $$\left(x + \frac{L}{2} * (\sin(\text{rotation}) + \cos(\text{rotation})), y + \frac{L}{2} * (\sin(\text{rotation}) - \cos(\text{rotation}))\right)$$ $$\left(x + \frac{L}{2} * (\sin(\text{rotation}) - \cos(\text{rotation})), y - \frac{L}{2} * (\sin(\text{rotation}) + \cos(\text{rotation}))\right)$$ $$\left(x - \frac{L}{2} * (\sin(\text{rotation}) + \cos(\text{rotation})), y - \frac{L}{2} * (\sin(\text{rotation}) - \cos(\text{rotation}))\right)$$

Example Diagram

Xagen
  • 23
  • What do you mean by "intercept on the perimeter"? At a glance, your equations look roughly right although there's probably some neater notation. – ConMan Jul 30 '21 at 01:01
  • Maybe you can include a diagram? I guess you mean if the trigonometric equations were based on a square instead of a circle, what would they be, or you mean something else. Try rotation=θ. – Тyma Gaidash Jul 30 '21 at 01:05
  • Are the four corners given (first sentence), or are they to be determined? – peterwhy Jul 30 '21 at 01:15
  • I added a diagram showing what I'm talking about. The circle and the square have the same area, and I'm wondering how to figure out at what point $(x, y)$ that the purple line crosses the perimeter as we rotate it around (it will always be anchored in the center). – Xagen Jul 30 '21 at 01:30
  • I'm guessing that the only way is to make a right triangle with the midpoint of that side and then use it to find the length of the side on the perimeter and from that the coordinates on the other end. However, I was hoping for something less involved/more elegant. – Xagen Jul 30 '21 at 01:42
  • Try $$\mathrm{tan(θ)=\frac{f(x)}{x}}$$ if $\pm |f(x)|+|x|=1$, then$ x=\pm\frac{1}{1+|\tan\theta|}$

    This means the y value will be $$\mathrm{y=\pm\frac{tan\theta}{1+|tan\theta|}}$$

    graph.Is this what you mean? This uses the “square” trigonometric functions instead of the normal “circle” functions.

    – Тyma Gaidash Jul 30 '21 at 01:54

2 Answers2

1

One would first solve the problem in a normalized coordinate system, where the square's edges run parallel to the axes, and then rotate the solutions to the rotated-recentered square. Let $\vec x_C$ be the two Cartesian coordinates of the square center, and $\vec x_1$ be the coordinates of a square corner. [Obviously $\vec x_3=2\vec x_C-\vec x_1$ is the opposite corner.] $L=\sqrt{2}|\vec x_1-\vec x_C|$ is the side length of the square.

Define the angle $\omega$ that rotates from normalized to the rotated/decentered coordinate system via $$ \vec x_1= \left(\begin{array}{cc}\cos\omega & -\sin\omega \\ \sin\omega & \cos\omega\end{array}\right)\cdot\left(\begin{array}{c}L/2 \\ L/2\end{array}\right)+\vec x_C = \frac{L}{\sqrt 2}\left(\begin{array}{c}\cos(\omega+45^\circ) \\ \sin(\omega+45^\circ) \end{array}\right)+\vec x_C, $$ where we have obviously chosen $(L/2,L/2)$ to be the coordinates of corner $\vec x_1$ in the normalized coordinate system. So $\omega$ is computed by the arctan of the ratio of the two components of $\vec x_1-\vec x_C$.

Let $\alpha$ be a direction in the normalized coordinate system. The ray intercepts the square in that coordinate system at $$ \vec x_i = \left(\begin{array}{c}L/2 \\ (L/2)\tan\alpha\end{array}\right),\quad -45^\circ\le \alpha \le 45^\circ $$ $$ \vec x_i = \left(\begin{array}{c}(L/2)\cot \alpha \\ L/2\end{array}\right),\quad 45^\circ\le \alpha \le 135^\circ $$ $$ \vec x_i = \left(\begin{array}{c}-L/2 \\ -(L/2)\tan\alpha\end{array}\right),\quad 135^\circ\le \alpha \le 225^\circ $$ $$ \vec x_i = \left(\begin{array}{c}-(L/2)\cot\alpha \\ -L/2\end{array}\right),\quad -135^\circ\le \alpha \le -45^\circ $$ for the four quadrants.

And the coordinates of interception in the rotated coordinate system are $$ \left(\begin{array}{cc}\cos\omega & -\sin\omega \\ \sin\omega & \cos\omega\end{array}\right)\cdot \vec x_i+\vec x_C $$ and the ray runs into the direction $\omega+\alpha$.

R. J. Mathar
  • 2,324
  • You stated "and so on for the other two quadrants". I don't understand the changes that would be made for the other two quadrants. Could you describe them as well? – Xagen Jul 30 '21 at 19:11
1

I am guessing you mean what would be the point on the perimeter of a square from a line in polar coordinates as $\theta=\theta_0\implies y=x\,\tan(\theta)$; this equation just gives the line with slope $\tan(\theta)$. This is the same as asking what the “sine and cosine” for a square are. Imagine this as the “square analogue” of the trigonometric functions defined in parametric coordinates as:

$$\mathrm{(cos_ \square(\theta),sin_ \square(\theta))=a|x|+a|y|=1}$$

To find theses “square” functions, simply construct and solve for x in terms of theta only:

$$\mathrm{y=x\,tan(\theta),a|x|+a|y|=1\implies a|x|+a|x||tan(\theta)|=1\implies a|x|(1+|tan(\theta)|)=1\implies |x|=\frac 1{a|tan(\theta)|+a}\implies x=cos_\square(\theta)=\pm \frac 1{a|tan(\theta)|+a},y=sin_\square(\theta) \pm\frac {tan(\theta)}{a|tan(\theta)|+a}}$$

These functions have that the tangent square function is just the tangent function and the (co)secant analogous are just reciprocals of x and y as seen above.

Values for the square functions. You really just need values from $0\le\theta\le\frac{\pi}{4}$ as you can either switch x and y or negate the results based on the quadrant; here is an explanation. Remember that $$\mathrm{x=cos_\square(\theta)=\pm \frac 1{a|tan(\theta)|+a},y=sin_\square(\theta)= \pm\frac {tan(\theta)}{a|tan(\theta)|+a}:}$$

$\theta=0:x=\frac1a,y=0;\theta=\frac\pi6:x=\frac{1}{\frac a{\sqrt3}+a},y=\frac{\sqrt3}{\sqrt3a+3a},\theta=\frac\pi4:x=y=\frac{1}{2a}$

This will also mean that the rest of these “square” based trigonometric functions are. In fact, this method always gives the new modified tangenr function as tan(θ) because of the setup:

$$\mathrm{\frac{y}{x}=tan_\square(\theta)=\frac{\pm\frac {tan(\theta)}{a|tan(\theta)|+a}}{\pm \frac 1{a|tan(\theta)|+a}}=tan(\theta)\implies cot_{\square}(\theta)=cot(\theta),sec_{\square}(\theta)= \frac{1}{cos_\square(\theta)}=\pm(a|tan(\theta)|+a),csc_\square(\theta)=\frac{1}{sin_{\square}}=\frac{1}{ \pm\frac {tan(\theta)}{a|tan(\theta)|+a}}= \pm\frac{a|tan(\theta)|+a} {tan(\theta)}=\pm (a\,sgn(tan(\theta))+a\,cot(\theta))}$$ Please see this

complete graph

for proof of these equations and visuals of the other (co)secant graphs. Tell me if you meant something else. Please correct me and give me feedback.

Тyma Gaidash
  • 12,081