42

Assuming I have the graph of a function $f(x)$ is there function $f_1(f(x))$ that will give me a rotated version of the graph of that function?

For example if I plot $\sin(x)$ I will get a sine wave which straddles the $x$-axis, can I apply a function to $\sin(x)$ to yield a wave that straddles the line that would result from $y = 2x$?

Aryabhata
  • 82,206
  • 3
    The "graph of a function" here is actually the graph of points satisfying an equation relating $x$ and $y$, for example $y = \sin x.$ A perfectly correct answer that was posted below (and accepted) tells us how to rotate the graph of any equation relating $x$ and $y,$ even if the equation cannot be written in the form $y = f(x).$ For example, you can rotate the graph of $y^2 = 4 - 2x^2,$ which is an ellipse, by this same method. – David K Dec 14 '14 at 21:08
  • 1
    https://math.stackexchange.com/questions/154743/how-to-rotate-a-polar-equation – Adam Dec 06 '18 at 18:01
  • 2
    To rotate any curve by any angle, you need to use parametric equations. $x=t \cos \theta - f(t) \sin \theta$, $y=t \sin \theta + f(t) \cos \theta$. You get points along the range $[s,e]$ by plugging in values for $t$ starting at $s$ and ending at $e$. The space between the points is determined by the difference between values of $t$ that you plug in, and each one gives you a pair of $(x,y)$ coordinates. – retrovius Sep 30 '19 at 02:31

5 Answers5

33

Once you rotate, it need not remain a function (i.e. one $x$ value can have multiple $y$ values corresponding to it).

But you can use the following transformation

$$x' = x\cos \theta - y \sin \theta$$ $$y' = x \sin \theta + y \cos \theta$$

to rotate by an angle of $\theta$. Point $(x,y)$ gets rotated to point $(x',y')$. Note: this is a rotation about the origin.

In your case of $y = 2x$, you need to rotate by $\arctan(2)$.

See this for more info: Rotation Matrix.

Aryabhata
  • 82,206
  • 2
    In the specific case of sin(x) if you rotate by something in the range (-pi/4,pi/4) you still have a function because the slope of sin(x) is always less than 1 in absolute value. – Ross Millikan Jan 12 '11 at 17:34
  • I think this is what I want. I want to animate something so that it undulates as if it were following a sin wave but not always in parallel to the x axis. – Omar Kooheji Jan 12 '11 at 17:43
  • @Omar: It looks like the parameterization that Rasmus refers to will suit you nicely. It gives you x and y each as a function of t and avoids the "double x" problem. – Ross Millikan Jan 12 '11 at 19:25
  • 2
    Here is a fairly general example: https://www.desmos.com/calculator/njn9qb8dxy – Mason Jun 30 '18 at 21:04
7

Yes you can, but it might not be a function. Say y = f(x) is the curve you want to rotate. Then the equation of the curve of f(x) rotated by n radians is: ycos(n) - xsin(n) = f(ysin(n) + xcos(n)) Try it out here: https://www.desmos.com/calculator

Zen
  • 113
6

For common functions, it ms very easy. $f(x)$ rotated $\phi$ is can be calculated by $(x+f(x)\cdot i)(\cos(\phi)+\sin(\phi)\cdot i)$ as coordinates instead of complex numbers. Let's, however, replace $x$ with $t$, just to reduce confusion.

$(t+f(t)\cdot i)(\cos(\phi)+\sin(\phi)\cdot i) = t\cos(\phi)-f(t)\sin(\phi)+t\sin(\phi)\cdot i+f(t)\cdot \cos(\phi)\cdot i$

In parametric form, that's:

$X=t\cos(\phi)-f(t)\sin(\phi)$

$Y=t\sin(\phi)+f(t)\cos(\phi)$

To convert that to a function, we find $t$ as a function of $x$ and plug that into $Y$ as a function of $t$.

This is possible with some equations, such as $f(t)=t^2$ or $f(t)=\dfrac 1t$. However, with the sine function, it's not very easy. In fact, there is no definite function for the rotation of a sine function. However, you can represent it as an infinite polynomial.

The parametric of this graph would be

$X=\dfrac{t-2\sin(t)}{\sqrt5}$

$Y=\dfrac{2t+\sin(t)}{\sqrt5}$

To approximate a polynomial $y$-as-a-function-of-$x$ formula, we find the coefficients for each part of this formula.

The $x^0$ coefficient is the $y$-intercept divided by $0!$ ($y$ when $x$ is zero)/$0!$

The $x^1$ coefficient is the $y$-intercept of the derivative divided by $1!$ $((y$ when $x$ is $0.00001)-(y$ when $x$ is $0))/0.00001/1!$

The $x^2$ coefficient is the $y$-intercept of the second derivative divided by $2!$ $((y$ when $x$ is $0.00002)-2*(y$ when $x$ is $0.00001)+(y$ when $x$ is $0))/0.00001/0.00001/2!$

The $x^3$ coefficient is the $y$-intercept of the third derivative divided by $3!$

$((y$ when $x$ is $0.00003)-3*(y$ when $x$ is $0.00002)+3*(y$ when $x$ is $0.00001)-(y$ when $x$ is $0))/0.00001/0.0001/0.0001/3!$

In case you haven't noticed, I'm using Pascal's triangle in this calculation.

I hope this helps!

4

You can do the rotation as Moron says, or you can write $y=2x+\sin(x)$. This will remain a function, but doesn't have the same shape as a sine wave. It depends upon what you want.

Ross Millikan
  • 374,822
  • I've tried this and it yields okay results for what I want to do. I might use this for something else. I'd been trying to multiply when I should have been adding... – Omar Kooheji Jan 12 '11 at 17:45
4

In general, the answer is no since the rotated version of the graph might not be the graph of a function. For instance it could happen that your rotated version of the graph contains two different points with the same $x$-value -- this cannot happen for the graph of a function.

A way out could be to parametrise your graph. So instead of a map $x\mapsto y(x)$ you look at the map $t\mapsto (t,y(t))$. After rotating the trajectory of this thing (not the graph!) it will still be the trajectory of a map $$t\mapsto (x(t),y(t)).$$

Rasmus
  • 18,404