# Math Help - help - goniometric problem - formula for drawing a circular path inside a square

1. ## help - goniometric problem - formula for drawing a circular path inside a square

Hi,
After some coding in Visual Studio I came across a goniomethrical problem:

I want to draw a line.
this line is made by defining two positions. (position = X & Y value)

The first position is constant/stationary over time.

The second position changes over time.
I want to define the second position so that the second position of the line would move in a circular path,
following the traditional formula of drawing a circle

pos2.x = pos1.x + (cos(angle) * length);
pos2.y = pos1.y + (sin(angle) * length);

('angle' changes it's value as time passes)

However, that's not really what I want to achieve.

I want to achieve that the angle of the line would change in the exact same way as the example given above,
however the length of the line has to vary, so that the rotation of the line would fit in a square shape instead of a circular shape.

so that adds another variable: 'size' of the border of the square.

so the variables to use are:
pos1.x
pos1.y
pos2.x
pos2.y
angle
length
'size' of the border of the square

I have been struggling alot with this problem, and I've found some ways to approach the exact visualisation of this problem, but it is far from perfect.

Does anyone have an idea of a formula I could use or a solution to this problem?

see sketch below for help to the visualisation of the problem

http://i54.tinypic.com/315gxsh.png

2. Hello, xcrypt!

I hope I understand the problem.

$\text{We want a square with side }2r.$

$\text{We have its center }O(x_o,y_o)$

$\text{We want a function so that }P(x,y)\text{ traces out the square.}$

Code:
                      |
* - - - - - + - - - - - *
| *         |         * |
|   *       |       *   |
|     *    [2]    *     | r
|       *   |   *       |
|         * | *         |
- - + - - [3] - * - [1] - - + - -
|         * | *         |
|       *   |   *       |
|     *    [4]    *     | r
|   *       |       *   |
| *         |         * |
* - - - - - + - - - - - *
r     |     r

We divide the coordinate plane into four oblique quadrants.

Each quadrant has its set of parametric equations.

. . . . . . . . . . . . . . . $\begin{array}{ccc} [2] & \theta\in & \!\!\!\!\![45^o, 135^o] \\ x &=& x_o + r\cot\theta \\ y &=& y_o + r \end{array}$

$\begin{array}{ccc} [3] & \theta\in & \!\!\!\!\![135^o,225^o] \\ x &=& x_o - r \\ y &=& y_o - r\tan\theta \end{array}$ . . . . . . . . . . . . . . . . $\begin{array}{ccc} [1] & \theta\in & \!\!\!\!\![\text{-}45^o,45^o] \\ x &=& x_o + r \\ y&=&y_o + r\tan\theta \end{array}$

. . . . . . . . . . . . . . . $\begin{array}{ccc} [4] & \theta\in & \!\!\!\!\![225^o, 315^o]\\ x &=& x_o - r\cot\theta \\ y &=& y_o - r \end{array}$

3. ah, I see now, makes sense
I'll try to program it tomorrow and see if it works, while I'm sure it will trace out the square, I'm not sure if say I programmed this new line
, if it would draw exactly on top of the first one
(
pos2.x = pos1.x + (cos(angle) * length);
pos2.y = pos1.y + (sin(angle) * length);
)
only with a bigger radius as it reaches the corners of the square
, though I think it will

I will update tomorrow

Thanks a bunch

4. --> programmed it. Works perfectly.

Thank you kind sir