java怎么更改椭圆的角度_如何将椭圆变换为Java中的矩形?

有一些形状很容易相互转换。例如,正方形是具有相等边长的矩形,圆是具有相同轴的椭圆。所以很容易将一个正方形转换成一个矩形,因为您可以使用一些drawrectangle函数并以整个方式调整参数。同上圆圈到椭圆。

squaretorect(double width,double height)

{

//Transform a square width * width to a rectangle width * height

int n = 100;//Number of intermediate points

int i;

double currentheight;

for(i=0;i

{

currentheight = width + (height-width) * i/(n-1);

drawrectangle(width,currentheight);

}

}

从矩形到椭圆形转变为更硬的,因为在它们之间的形状既不是矩形也不是椭圆。也许有一些更一般的对象,可以是矩形,椭圆或其他东西,但我想不出来。

所以,简单的方法是,但有一个更难的方法来做到这一点。假设我将单位圆划分成N个部分并在椭圆Ei和矩形Ri上写入点。现在,随着转变发生,点Ei移动到点Ri。一个简单的方法是使用线性组合。

TI =(1-V)* EI + V *日

那么做,我们慢慢地从0增加v到1的转变,我们的点Ti的画线(或更好,但插值)。

ellipsetorectangle(double a, double b, double w, double h)

{

//(x/a)^2+(y/b)^2 = 1

//Polar r = 1/sqrt(cos(phi)^2/a^2 + sin(phi)^2/b^2)

int N = 1000;

int i;

double phi; double r;

double phirect = atan(w/h);//Helps determine which of the 4 line segments we are on

ArrayList Ei;

ArrayList Ri;

for(i=0;i

{

//Construct ellipse

phi = 2PI * (double)i/N;

r = 1/sqrt(cos(phi)^2/a^2 + sin(phi)^2/b^2);

Ei.add(new Point(r * cos(phi),r * sin(phi));

//Construct Rectangle (It's hard)

if(phi > 2Pi - phirect || phi < phirect)

{Ri.add(new Point(w/2,w/2 * tan(phi)));}

else if(phi > phirect)

{Ri.add(new Point(h/2 * tan(phi),h/2));}

else if(phi > PI-phirect)

{Ri.add(new Point(-w/2,-w/2 * tan(phi)));}

else if(phi > PI+phirect)

{Ri.add(new Point(-h/2,-h/2 * tan(phi)));}

}

}

Arraylist Ti;

int transitionpoints = 100;

double v;

int j;

for(j=0;j

{

//This outer loop represents one instance of the object. You should probably clear the picture here. This probably belongs in a separate function but it would take awhile to write it that way.

for(i=0;i

{

v = (double)1 * j/(N-1);

Ti = new Point(v * Ri.get(i).getx + (1-v) * Ei.get(i).getx,

v * Ri.get(i).gety + (1-v) * Ei.get(i).gety);

if(i != 0)

drawline(Ti,Tiold);

Tiold = Ti;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值