JSFiddle - React, Tailwind, and code Playground
HTML
<div style="width:600px;margin:auto;"><ul id="logstxt"></ul></div>
JavaScript
//You can change these values.
ang = 180; //In degrees
x0 = 0; //A point on the ellipse
y0 = 2;
rx = 2; //x-axis radius
ry = 1;
cx = 2;
cy = 2;
function log() {
var args = Array.prototype.slice.call(arguments);
$("<li>"+args.join(' ')+"</li>").appendTo($("#logstxt"));
}
$(document).ready(function(){
function getT(x, y) {
var N = ((x - cx) * Math.cos(ang) + (y - cy) * Math.sin(ang)) / rx;
return Math.acos(N);
}
function getXY(t) {
var res = {};
res.x = cx + rx * Math.cos(t) * Math.cos(ang) - ry * Math.sin(t) * Math.sin(ang);
res.y = cy + rx * Math.cos(t) * Math.sin(ang) + ry * Math.sin(t) * Math.cos(ang);
return res;
}
var p0 = getXY(0);
log("XY for pt at t=0:", p0.x, p0.y);
log("Calculating t using above xy. Should be 0. calculated t=", getT(p0.x, p0.y));
var t = getT(x0, y0);
log('t for the given pt x0,y0: ', t);
log('Calculated xy from using the above t', JSON.stringify(getXY(t)), ' should be ', x0,',',y0);
});