2 つの点が互いに回転していることを達成したいと考えています。したがって、回転行列を使用します。ただし、ポイント間の距離が大きくなっているという問題が発生しています(添付のビデオ1を参照)。ただし、距離はシミュレーション全体で一定に保つ必要があります。
速度の計算に使用するコードは次のとおりです。
ここで、p1 と p2 は 2 つのポイントです。
double xPos = p0.x+p1.x;
double yPos = p0.y+p1.y;
//The center between p1 and p2
xPos /=2;
yPos /=2;
//the rotating angle
double omega = 0.1;
//calculate the new positions
double x0new = xPos + (p0.x-xPos)*std::cos(omega) - (p0.y-yPos)*std::sin(omega);
double y0new = yPos + (p0.x-xPos)*std::sin(omega) + (p0.y-yPos)*std::cos(omega);
double x1new = xPos + (p1.x-xPos)*std::cos(omega) - (p1.y-yPos)*std::sin(omega);
double y1new = yPos + (p1.x-xPos)*std::sin(omega) + (p1.y-yPos)*std::cos(omega);
//the speed is exatly the difference as I integrate one timestep
p0.setSpeed(p0.x-x0new, p0.y-y0new);
p1.setSpeed(p1.x-x1new, p1.y-y1new);
次に、速度を正確に 1 タイムステップ積分します。私の計算で何が間違っていますか?
更新 私の統合が間違っているようです。位置を直接設定すると、完璧に機能します。ただし、この統合の何が問題なのかはわかりません。
setSpeed(ux,uy){
ux_=ux;
uy_=uy;
}
// integrate one timestep t = 1
move(){
x = x + ux_;
y = y + uy_;
}