私はSeed7という言語で書かれたコードリストをPythonに変換しようとしています。 1つの部分を除いて、ベータ段階になってしまいました。Pythonでcos()とsin()を正しく使用する
すべては私が(COSどのような機能を理解していないという事実を除いて、理にかなってx1 := flt(column) + 0.5;
y1 := flt(row) + 0.5;
angle := (course - 1.0) * 0.785398;
delta_x := cos(angle);
delta_y := -sin(angle);
inquad := TRUE;
blocked := FALSE;
number := 1;
while number <= distance do
y1 := y1 + delta_y;
x1 := x1 + delta_x;
row := trunc(y1);
column := trunc(x1);
if column < 1 or column > 8 or row < 1 or row > 8 then
inquad := FALSE;
number := distance;
else
if sect[row][column] <> 1 then (* Object blocking move *)
blocked := TRUE;
number := distance;
end if;
end if;
incr(number);
end while;
)とSeed7で罪()仕事:これはSeed7リストの抽出物です。
マニュアルは言う:
罪
のconst FUNCフロート:罪(フロート中:X)
Compute the sine of x, where x is given in radians.
Returns:
the trigonometric sine of an angle.
が、私はPythonで同等のものを作ることはできません。
この問題は純粋に私が正しくはPythonを理解していない(そして実際に数学のいずれかでその偉大されていない)によって引き起こされるものですので、私はこれらの事を理解しない人に聞いてここに来ます。
上記のコードをPythonで動作させるにはどのようなコードが必要ですか?助けて!!! :-)
多くのありがとう、
ジョセフ。
編集:問題はincr()関数だと思います。基本的には、ヘルプファイルからこのゲームは1未満にワープすることが可能である:
writeln("Warp - One warp moves you the width of a quadrant. A warp of .5 will move you");
writeln("halfway through a quadrant. Moving diagonally across a quadrant to the next");
writeln("will require 1.414 warps. Warp 3 will move you 3 quadrants providing nothing");
writeln("in your present quadrant blocks your exit. Once you leave the quadrant that");
writeln("you were in, you will enter hyperspace; coming out of hyperspace will place you");
writeln("randomly in the new quadrant. Klingons in a given quadrant will fire at you");
writeln("whenever you leave, enter, or move within the quadrant. Entering a course or");
writeln("warp of zero can be used to return to the command mode.")
私のコードは次のようになりますことは、私はでNUM + = 1を使用していている
x1 = float(column) + 0.5
y1 = float(row) + 0.5
angle = (course - 1.0) * 0.785398
deltaX = math.cos(angle)
deltaY = -math.sin(angle)
inQuad = True
blocked = False
num = 1
while num <= distance:
y1 += deltaY
x1 += deltaX
row = int(round(y1))
column = int(round(x1))
if column < 0 or column > 7 or row < 0 or row > 7:
inQuad = False
num = distance
else:
if sect[row][column] != 1:
blocked = True
num = distance
num += 1
incrとは対照的に、終わりですが、私はincrを理解していません。私が言ったように、私は試合からちょっと離れていましたが、いくつかのことが本当に私を魅了しています。
光を照らすのに役立つでしょう。
Joseph。
全体的な話があり、ちょうどあなたの質問を投稿するポストを下に短くしてくださいそれは単なる毛羽立ちで誰にも有用ではないので、必要ではありません。あなたは何を持っているのですか? 'math.cos'と' math.sin'は動作していませんか? [this](https://docs.python.org/3/library/math.html)を読んだことがありますか? – Li357
Andrew - ポストが短縮されました。私がそれをやった唯一の理由は、私が以前に尋ねた質問に十分な情報を追加していないことが多いということでした。答えが得られたときに、あなたの質問には、私は関数を入れて、すべての地獄は緩んだ。あなたが私に理論的に提供したリンクは、それはちょうどうまくいくはずだが、そうではないと言います。私は戻って私のコードを再チェックします。どうもありがとう。 –