这样的椭圆只是一个圆,在y轴上按0.38倍的比例zoom .
我想用来理解答案的理由是逆转这种比例.
如果按系数1/0.38≈2.63zoom 整个图形y轴,则椭圆看起来将像一个圆.
但是,蓝线的Angular 就不同了.因为它的槽不是0.7/0.3,而是2.63×0.7/0.3.
这个Angular ,也就是那条蓝线和椭圆的交点的Angular .它是椭圆中交点的参数坐标.
由于参数坐标不依赖于比例,因此即使在当前0.38比例下它也保持不变
所以,结论是
let angle = Math.atan((0.7/0.3)*a/b);
let x = a*Math.cos(angle);
let y = b*Math.sin(angle);
演示:
let a=1;
let b=0.38;
let canvas=document.getElementById('canvas');
let ctx = canvas.getContext("2d");
let y0=120;
let x0=100;
let sc=150;
ctx.strokeStyle='#000000';
// Axis
ctx.beginPath();
ctx.moveTo(0,y0);
ctx.lineTo(300,y0);
ctx.stroke();
ctx.moveTo(x0,0);
ctx.lineTo(x0,300);
ctx.stroke();
// Ellipse
ctx.strokeStyle='#ff0000';
ctx.beginPath();
ctx.moveTo(x0+sc*a,y0);
ctx.ellipse(x0,y0,sc*a, sc*b, 0, 0, 6.28);
ctx.stroke();
// Blue line
ctx.strokeStyle='#0000ff';
ctx.beginPath();
ctx.moveTo(x0,y0);
ctx.lineTo(x0+0.3*sc, y0-0.7*sc);
ctx.stroke();
// Intersection coordinate. The next 3 lines are my answer
// (all the lines before, and after the next 3, are just
// what is needed for drawing)
let angle = Math.atan((0.7/0.3)*a/b);
let x = a*Math.cos(angle);
let y = b*Math.sin(angle);
// Draw a yellow box at this point. It should intersect both ellipse and line
ctx.fillStyle='#888800';
ctx.beginPath();
ctx.fillRect(x0+x*sc-5, y0-y*sc-5, 10, 10);
<canvas id=canvas width=300 height=200>
</canvas>
现在,你可能会注意到,它并没有严格地回答你题目中的问题.它不会根据Angular 给出椭圆中点的坐标.因为angle
不是蓝线的Angular ,而是它的Angular ,如果我们zoom 图表,使椭圆显示为一个圆.
但从问题的正文和代码来看,您真正的问题似乎是"根据直线斜率0.7/0.3在椭圆中寻找点".
但是如果你真的想从Angular (蓝线的Angular )找出这个点,你只需要用tan
来得到斜率,然后zoom 并用atan
来得到我们需要的真实Angular .
所以
let parametricAngle = Math.atan(Math.tan(inputAngle)*a/b);
let x=a*Math.cos(parametricAngle);
let y=b*Math.sin(parametricAngle);