JSFiddle - React, Tailwind, and code Playground

JavaScript

var width = 300;
var height = 150;
var w =  width / 2;
var h = height / 2;
var w2 = (width / .75) / 2;


var c = document.createElement('canvas');
c.width = 512;
c.height = 512;
document.body.appendChild(c);
var ctx = c.getContext('2d');

//draw the ellipse
ctx.translate(256,256);
ctx.save();
ctx.moveTo(0,-h);
ctx.bezierCurveTo(w,-h,w,h,0,h);
ctx.bezierCurveTo(-w,h,-w,-h,0,-h);
ctx.stroke();
//draw the rectangle with the same width and height
// control points are on corners
ctx.strokeRect(-w,-h,width,height);

// line down the middle
ctx.moveTo(0,-h - 30);
ctx.lineTo(0,h + 30);
ctx.stroke();


// start drawing the De Casteljau construction
var Ax,Ay,Bx,By,Cx,Cy,Dx,Dy,Ex,Ey,Px,Py;

Ax = w / 2;
Ay = -h;
Bx = w;
By = 0;
Cx = w / 2;
Cy = h;

ctx.moveTo(Ax,Ay);
ctx.lineTo(Bx,By);
ctx.lineTo(Cx,Cy);
ctx.stroke();

ctx.translate(Ax,Ay);
ctx.beginPath();
ctx.arc(0,0.2,2,0,Math.PI*2,true);
ctx.fill();

ctx.restore();
ctx.save();

ctx.translate(Bx,By);
ctx.beginPath();
ctx.arc(0,0.2,2,0,Math.PI*2,true);
ctx.fill();

ctx.restore();
ctx.save();

ctx.translate(Cx,Cy);
ctx.beginPath();
ctx.arc(0,0.2,2,0,Math.PI*2,true);
ctx.fill();

ctx.restore();
ctx.save();

Dx = .5 * Ax + .5 * Bx;
Dy = .5 * Ay + .5 * By;

ctx.translate(Dx,Dy);
ctx.beginPath();
ctx.arc(0,0.2,2,0,Math.PI*2,true);
ctx.fill();

ctx.restore();
ctx.save();

Ex = Dx;
Ey = -Dy;

ctx.translate(Ex,Ey);
ctx.beginPath();
ctx.arc(0,0.2,2,0,Math.PI*2,true);
ctx.fill();

ctx.restore();
ctx.save();

ctx.moveTo(Dx,Dy);
ctx.lineTo(Ex,Ey);

ctx.stroke();



Px = Dx;
Py = .5 * Dy + .5 * Ey;

ctx.translate(Px,Py);
ctx.beginPath();
ctx.arc(0,0.2,2,0,Math.PI*2,true);
ctx.fill();

ctx.restore();


console.log(Dx / w);

// We learned that the ellipses width is always going to be .75 times
// the size of the of the X distance of the control points

ctx.beginPath();

ctx.strokeStyle = "#FF0000";
ctx.lineWidth = 2;
ctx.moveTo(0,-h);
ctx.bezierCurveTo(w2,-h,w2,h,0,h);
ctx.bezierCurveTo(-w2,h,-w2,-h,0,-h);
ctx.stroke();