用Java使用参数方程绘制椭圆

huangapple 未分类评论56阅读模式
标题翻译

Drawing a ellipse using parametric equations in Java

问题

我尝试了下面的代码但它并没有按预期工作请帮忙

for(int i = 0; i < 20; i++){
    double angle = i * 2 * Math.PI / 20; 
    int rdif = (int) Math.round(yradius * Math.cos(angle));
    int row = ycenter + rdif;
    int cdif = (int) Math.round(xradius * Math.sin(angle));
    int col = xcenter + cdif;
    index[row][col] = '*';
}

xcenter 是 10
ycenter 是 10
xradius 是 5
yradius 是 3

请查看输出图像

<img src="https://i.stack.imgur.com/L9WqI.png" width="300">
英文翻译

I am trying code below but it is not working as expected, please help.

for(int i =0;i&lt;20;i++){
    double angle = i * 2 * Math.PI/20; 
    int rdif = (int) Math.round(yradius * Math.cos(angle));
    int row = ycenter + rdif;
    int cdif = (int) Math.round(xradius * Math.sin(angle));
    int col = xcenter + cdif;
    index[row][col] = &#39;*&#39;;
}

xcenter is 10,
ycenter is 10,
xradius is 5,
yradius is 3

Check the image for output:

<img src="https://i.stack.imgur.com/L9WqI.png" width="300">

enter image description here

huangapple
  • 本文由 发表于 2020年5月31日 01:45:30
  • 转载请务必保留本文链接:https://java.coder-hub.com/62106437.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定