2014-05-12 4 views
0

두 번째 그룹의 입자가 각속도를 설정하여 입자가 그룹 중심에서 회전 할 수 있습니다.각속도를 2d 입자 그룹으로 설정

나는이 방법을 사용하여 그룹의 각속도를 얻었고 실제로 각도 그룹 속도를 설정하는 논리를 뒤집어 봤습니다.

제 생각에는 그룹 질량, 그룹 중심 및 그룹 선형 속도를 같은 방식으로 얻음으로써 대부분의 논리를 그대로 둡니다. 그러나 대부분의 시행 착오가 예상 결과에 미치지 못하는 것 같습니다.

이 논리 반전에서 각속도를 설정하는 방법에 대해 알고 있다면, 내가하는 말을 듣고 싶습니다.

getParticleGroupAngularVelocity() 
{ 
particleCount = 30; 
particleMass = 1.5; 
particleGroupMass = 0; 
particleGroupInertia = 0; 
particleGroupAngularVelocity = 0; 

particleGroupCenter = vector(0, 0); 
particleGroupLinearVelocity = vector(0, 0); 

for (i = 0; i < particleCount; i++) 
{ 
    particleGroupMass += particleMass; 
    particleGroupCenter += particleMass * particles[i].position; 
    particleGroupLinearVelocity += particleMass * particles[i].velocity; 
} 

if (particleGroupMass > 0) 
{ 
    particleGroupCenter *= 1/particleGroupMass; 
    particleGroupLinearVelocity *= 1/particleGroupMass; 
} 

for (i = 0; i < particleCount; i++) 
{ 
    pos = particles[i].position - particleGroupCenter; 
    vel = particles[i].velocity - particleGroupLinearVelocity; 
    particleGroupInertia += particleMass * (pos.x * pos.x + pos.y * pos.y); 
    particleGroupAngularVelocity += particleMass * (pos.x * vel.y - pos.y * vel.x); 
} 

if (particleGroupInertia > 0) 
{ 
    particleGroupAngularVelocity *= 1/particleGroupInertia; 
} 

return particleGroupAngularVelocity; 
} 
+0

당신은 입자 그룹을 가지고 있으며 그룹에게 원하는 "그룹 각속도"를주기 위해 일부 또는 모든 입자의 속도를 변경하고자합니다 ""그룹 선형 속도 "를 동일하게 유지하면서이 코드와 동일한 의미로 느슨하게 용어를 사용합니다. 맞습니까? 다른 조건이 있습니까? 나는 * 할 수있는 많은 방법이 있기 때문에 물어 본다. – Beta

+0

그룹의 선 속도를 유지하면서 모든 입자의 속도를 변경할 수 있기를 원합니다. 따라서 입자 그룹이 x 축 및/또는 y 축에서 일정한 속도로 움직이는 경우 다른 그룹의 움직임에 영향을주지 않고 입자 그룹을 중심에서 회전시킬 수 있기를 바랍니다. – Claudia

+0

다른 조건은 다른 조건을 생각할 수 없습니다. 하지만 그 주제에 대한 통찰력이 부족할 수도 있습니다. – Claudia

답변

1

좋아,이 작업을 수행해야합니다.

for (i = 0; i < particleCount; i++) 
{ 
    pos = particles[i].position - particleGroupCenter; 
    vel.x = - particleGroupAngularVelocity * pos.y; 
    vel.y = particleGroupAngularVelocity * pos.x; 
    particles[i].velocity = vel + particleGroupLinearVelocity; 
} 

이렇게하면 그룹의 선형 속도가 유지됩니다. 개별 입자는 그룹 센터를 중심으로 회전하면서 동일한 유리 시트에 모두 박힌 것처럼 속도가 주어집니다. (그 궤도에있는을 유지하는 것은 다른 사람의 문제입니다.)

+0

위대한 작품! 대단히 감사합니다. 베타. 의심의 여지를 제거하는 하나의 질문. 원래 코드에는 관성을 기반으로 한 속도 조정이 있습니다. 당신이 제공하는 솔루션에서 관성은 입자 속도에 영향을주지 않습니다. 그 이유는 무엇입니까? 다시 한 번 감사드립니다, 베타! – Claudia

+0

@Claudia :이 솔루션은 선형 운동량을 보존하지만 각운동량은 보존하지 않습니다. (물리학적인 의미에서 "Conserve", "not not change".) 원래 코드는 각운동량을 측정 한 후 관성 모멘트로 나눈 다음 particleGroupAngularVelocity를 얻습니다. 이 코드는 입자를 서로에 대해 상대적으로 고정시킨 다음 전체 그룹을 "회전"시킵니다. – Beta

+0

나는 본다. 철저한 답변과 설명에 감사드립니다. – Claudia