I have a square where the closest points are 1 unit from the center. See My ascii diagram below:
+-----------+ | | | x | |-----+ | | | | | +-----------+
Therefore, the distance from the origin to the angles is sqrt (2). I need a function that returns the distance from the origin to a point on the square at any angle. For example, to enter 0, the function will return 1. For input 45, the function will return the distance to the corner, the square root of 2. Then for 90 it will return again.
In other words, when you draw a function with a polar graphic, it draws a square.
I believe the function will be something like this:
f(x) = sqrt(tan(x)^2+1)
The only problem is that the above function will not display the sides of the square. I need something that draws all 4 sides.
I know that there is a trigonometric function for something similar, but I will use this function in javascript, so I will use only standard trigonometry functions.
Any help would be appreciated. Thanks in advance.
Joel
source share