简体   繁体   English

我的对数螺旋函数无法正确计算

[英]My Logarithmic Spiral function does not compute correctly

I wasn't so sure where to ask this question (between math and here) 我不确定在哪里问这个问题(在数学和此处之间)

I try to draw Logarithmic Spiral using this formula 我尝试使用此公式绘制对数螺旋

在此处输入图片说明

It works (well it show a spiral on screen) , but when i change the pitch (a) the spiral does not change his pitch , only rotation and size (and setting a to 1 should make a circle but it does not) 它可以工作(好吧,它在屏幕上显示出一个螺旋形),但是当我改变螺距(a)时,螺旋形并不会改变其螺距,只有旋转和大小(并将a设置为1应该形成一个圆圈,但不会)

i tried thoses : 我试过那些:

double step = (end - start) / sample;
        for (int i = 1;i <= sample;i++) {
            double t = start+i*step;
            coordinates[i-1][0] =  a * Math.pow(Math.E,b*t) * Math.cos(t);
            coordinates[i-1][1] = a * Math.pow(Math.E,b*t) * Math.sin(t);
}

(a and b are constant , start = -4*PI , end = 4*PI) (a和b是常数,开始= -4 * PI,结束= 4 * PI)

and

    double step = (end - start) / sample;
        for (int i = 1;i <= sample;i++) {
            double r = start+i*step;
        double t = (1/b)*Math.log(r/a);
            coordinates[i-1][0] = r* Math.cos(t);
            coordinates[i-1][1] = r* Math.sin(t);
}

(a and b are constant , start = 0 , end = 10) (a和b是常数,开始= 0,结束= 10)

I guessing I have made a big error in the formula but I don't see wich one. 我想我在公式中犯了一个大错误,但我看不到哪一个。 I can provide an output picture if that can help , but I don't see how 如果可以提供帮助,我可以提供输出图片,但我看不出如何

Edit: I did succed to make it work using r = a exp(θ cot b) 编辑:我确实成功地使它使用r = a exp(θcot b)

    double r = Math.pow(a,t*(1/Math.tan(b)));

But i still don't get why the other formula didn't work out , that's why i edited this question rather than answering it. 但是我仍然不明白为什么其他公式无法解决问题,这就是为什么我编辑此问题而不是回答它的原因。

My guess would be that there's a rounding issue going on. 我的猜测是,存在一个四舍五入的问题。 I am assuming both 'a' and 'b' are doubles... I have to ask as it's not written in the code but assume this is the case. 我假设'a'和'b'都是双精度的。。。我不得不问,因为它不是写在代码中的,但前提是这样。 If not that'll be the problem :) 如果不是,那将是问题:)

Next I'd look at i*step and ensure this is what you're expecting... I would have thought this is ok but you're not casting the int 'i' to a double so asking for problems if you reshuffle parts. 接下来,我将查看i * step并确保这是您所期望的...我本以为这可以,但是您没有将int'i'转换为双精度,因此如果您改组零件,则会出现问题。

Ahhh, actually I'd want to look at is 'sample'. 啊,实际上我想看看的是“样本”。 If this is an int as I'd expect this will give you the wrong result for step since you're dividing by an int which I expect will give an int return value... actually my 1p's bet is on it's sample declared as an int. 如果这是我所期望的int,这将给您错误的步骤结果,因为您用int除以我期望会得到int的返回值...实际上我的1p下注在它的样本上声明为诠释

If that doesn't fix it, you can print out the step value and ensure it's what you're expecting, also check 't' is calculating correctly if it isn't this sample issue. 如果那不能解决问题,您可以打印出步长值并确保它是您期望的值,如果不是这个示例问题,还请检查“ t”是否在正确计算。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM