My apologies if this already has an answer, I've spent some time looking but haven't found anything that (to me) looked directly applicable.
I have a set of parametric equations describing a periodic curve on an interval, say, $0\le t\le 4\pi$: $$ x=t+\sin{(t)}\\ y=-\cos{(t)} $$ This curve looks like a function, so I feel like I ought to be able to come up with a Cartesian form $y=f(x)$ for which each (x,y) coordinate pair would be identical to the corresponding parametric coordinate pair.
I've tried solving and substituting, but I only know how to solve the $y$ parametric for $t$: $$y=-\cos{(t)}$$ becomes $$ t=\arccos{(-y)}$$ And so I treat can $y$ as the independent variable and do: $$ x=\arccos{(-y)} + \sin{(\arccos{(-y)})} $$ with $y$ defined only over the interval $-1\le y \le 1$ which limits me to a single half of one wavelength, and repeated concatenating of this is not trivial because the interval between each successive x-value is not the same. I don't know how to solve the $x$ parametric, maybe someone who is a whiz with trig identities can offer a path.
I can use the x and y parametric values to create an interpolation programatically, but this is cumbersome and problematic for reasons beyond scope, etc.
Here's a plot (code at the bottom, in Python) of a parametric and interpolated version of this curve:
parametric equations: x=a+sin(a); y=-cos(t); 0<t<4pi
My motivation is to be able to treat multiple wavelengths/amplitudes/phases as discretized waveforms to be manipulated together, with identical sample rate, syncronous sampling, etc. in simulating various physical effects (sample-wise addition, etc.). Also, not being able to figure this out bugs me. I would think this would be a simple additional term, as in $y=-cos{(x + [some\ expression])}$ over $x$ in some interval, but I can't come up with this additional expression. Maybe this is a case requiring implicitization as mentioned here?
Python code I used for the plot:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import numpy as np
from scipy.interpolate import interp1d
import matplotlib
from matplotlib import pyplot as plt
from matplotlib.ticker import AutoMinorLocator as AML
matplotlib.use('TKAgg')
cyc = 3.0
n_per_cyc = 20
def xy_from_a(a):
x = a + np.sin(a)
y = -np.cos(a)
return x, y
def interp_param_to_xy(a, x, y):
interpolator = interp1d(x, y)
x_interpolated = np.array(a)
y_interpolated = interpolator(x_interpolated)
return x_interpolated, y_interpolated
def plot(
xmin=None, xmax=None, ymin=None, ymax=None,
xunits=None, yunits=None,
title=None, square=True,
):
plt.rcParams['legend.fontsize'] = 10
plt.rcParams['figure.figsize'] = [18, 4]
plt.figure()
ax = plt.gca()
ax.set_xlabel('x (radians)', fontsize=16)
ax.set_ylabel('y', fontsize=16)
ax.plot(x_neg_cos, y_neg_cos,
label='neg_cos', color='#000000',
linestyle=':',
marker='.', markersize=5.0,
linewidth=0.5)
ax.plot(x_parametric, y_parametric,
label='parametric', color='#009f00',
linestyle='-',
marker='.', markersize=8.0,
linewidth=1.0)
ax.plot(x_interpolated, y_interpolated,
label='interpolated', color='#ff0000',
linestyle=':',
marker='.', markersize=5.0,
linewidth=1.0)
plt.legend(loc='best')
minorLocator1X = AML()
minorLocator1Y = AML()
ax.xaxis.set_minor_locator(minorLocator1X)
ax.yaxis.set_minor_locator(minorLocator1Y)
ax.tick_params(which='major', width=2, length=7)
ax.tick_params(which='minor', width=2, length=4)
ax.grid(visible=True, which='major', color='gray', linestyle='-')
ax.grid(visible=True, which='minor', color='gray', linestyle=':')
if title is not None:
plt.title(title, fontsize=20)
if xunits is not None:
ax.set_xlabel(xunits, fontsize=16)
if yunits is not None:
ax.set_ylabel(yunits, fontsize=16)
if xmin is not None:
ax.axis(xmin=xmin)
if xmax is not None:
ax.axis(xmax=xmax)
if ymin is not None:
ax.axis(ymin=ymin)
if ymax is not None:
ax.axis(ymax=ymax)
if square:
ax.set_aspect('equal', adjustable='box')
plt.tight_layout()
plt.show()
print('x = θ + sin(θ)')
print('y = -cos(θ)')
n = int(round(n_per_cyc * cyc, 0))
t = np.linspace(0.0, 2.0 * np.pi * cyc, num=n + 1, endpoint=True)
x_neg_cos = t[:n]
y_neg_cos = -np.cos(x_neg_cos)
x_parametric, y_parametric = xy_from_a(t)
t = t[:n]
x_interpolated, y_interpolated = interp_param_to_xy(t, x_parametric, y_parametric)
x_parametric = x_parametric[:n]
y_parametric = y_parametric[:n]
plot(
xmin=0.0,
xmax=np.pi / 2.0 * 8.0,
square=True,
)
EDIT:
Thanks @Gwen, with the help of your comment/answer I succeeded in finding several trig identities that let me follow you to your answer: $$y=-\cos(x\pm\sqrt{1-y^2})$$ It may be possible, using further trig identities or some other means, to solve for y, but if so, I can't figure it out. So, I solved for x, which gives me: $$x=\arccos(-y)\pm\sqrt{1-y^2}$$ But of course this, even treated piecewise, leaves me with the same problem as before, in that x is not the independent variable. (Also, in a programmatic context like Python, x values for both halves come out positive because of how arccos is defined to output in [0, $\pi$].)
Is there a way to solve for y, or some other way to rearrange this so that, whether piecewise or not, y is calculated from x, enabling me to programmatically assign x (piecewise if necessary) over whatever domain and granularity I need?