본문 바로가기
Golf/Physics

Simulation - golf1

by wenect 2023. 6. 30.

골프공의 운동은 대기와의 상호작용, 공의 회전, 그리고 중력의 영향을 받습니다. 이 모든 요소들을 포함한 골프공의 물리식은 다소 복잡할 수 있지만, 단순화시킨 기본적인 물리식은 다음과 같습니다:

  1. 중력에 의한 운동: F = mg, 여기서 F는 힘, m는 골프공의 질량, 그리고 g는 중력 가속도입니다.
  2. 대기와의 마찰: 골프공의 속도가 빠를수록, 공과 대기간의 마찰력이 증가합니다. 이 마찰력은 공의 속도, 크기, 질량, 그리고 공과 대기 사이의 마찰 계수에 의해 결정됩니다. 이 마찰력은 공의 속도를 감소시키며, 공의 방향을 변화시키는 중요한 요소입니다.
  3. 회전에 의한 운동: 골프공이 회전할 때, 그 회전은 공의 궤적에 영향을 줍니다. 이는 공의 '리프트'를 증가시키는 '매그누스 효과'를 발생시키는데, 이는 공이 공기를 통해 상승하는 데 도움을 줍니다.

좀 더 상세한 물리적 모델링을 원하신다면, 각 힘에 대한 방정식을 통합하여 운동 방정식을 생성해야 할 수도 있습니다. 그러나 이는 고도의 수학적 이해와 물리학적 지식을 필요로 합니다. 골프공의 움직임에 영향을 미치는 다양한 요소들 때문에, 이는 상당히 복잡한 문제일 수 있습니다.

시간을 단위 시간마다 갱신하면서 골프공의 위치와 속도를 갱신합니다. 이를 통해 공이 중력과 공기 저항에 의해 어떻게 움직이는지 시뮬레이션합니다. 이 코드는 골프공의 움직임을 2차원으로 단순화하여 표현하였습니다.

using System;

class GolfBall
{
    // Constants
    private const double Gravity = 9.81;
    private const double Mass = 0.045;  // approx mass of a golf ball
    private const double DragCoefficient = 0.47;  // drag coefficient for a sphere
    private const double AirDensity = 1.225;  // at sea level and at 15 °C
    private const double BallRadius = 0.02135;  // standard radius of a golf ball
    private const double TimeStep = 0.01;  // time step for the simulation

    // Variables
    private double posX, posY;  // position of the golf ball
    private double velX, velY;  // velocity of the golf ball

    // Constructor
    public GolfBall(double initialSpeed, double launchAngle)
    {
        // Initial conditions
        posX = 0;
        posY = 0;
        velX = initialSpeed * Math.Cos(launchAngle);
        velY = initialSpeed * Math.Sin(launchAngle);
    }

    // Update the position and velocity of the golf ball
    public void Update()
    {
        // Calculate the drag force
        double speed = Math.Sqrt(velX * velX + velY * velY);
        double dragForce = 0.5 * DragCoefficient * AirDensity * speed * speed * Math.PI * BallRadius * BallRadius;
        double dragForceX = -dragForce * velX / speed;
        double dragForceY = -dragForce * velY / speed;

        // Calculate the force of gravity
        double gravityForceY = -Mass * Gravity;

        // Update velocity
        velX += (dragForceX / Mass) * TimeStep;
        velY += ((dragForceY + gravityForceY) / Mass) * TimeStep;

        // Update position
        posX += velX * TimeStep;
        posY += velY * TimeStep;
    }

    // Get the position of the golf ball
    public (double, double) GetPosition()
    {
        return (posX, posY);
    }
}
class Program
{
    static void Main()
    {        
        // Create a golf ball with an initial speed of 70 m/s and a launch angle of 45 degrees
        GolfBall golfBall = new GolfBall(70, Math.PI / 4);

        // Continue the simulation until the golf ball hits the ground
        while (true)
        {
            // Update the golf ball
            golfBall.Update();

            // Get the position of the golf ball
            (double posX, double posY) = golfBall.GetPosition();

            // Print the position of the golf ball
            Console.WriteLine($"Position: ({posX}, {posY})");

            // Stop the simulation when the golf ball hits the ground
            if (posY < 0)
            {
                break;
            }
        }
    }
}

골프공이 초기 속도로 70 m/s를 가지고 45도 각도로 발사될 때, 공이 어떻게 움직이는지를 시뮬레이션합니다. 공의 위치를 각 단계에서 출력하고, 공이 땅에 닿을 때까지 시뮬레이션을 계속합니다.

이 코드는 매우 단순화된 모델을 사용하고 있습니다. 공의 회전, 바람, 공의 표면의 디자인 등과 같은 다른 요소들은 이 시뮬레이션에서 고려되지 않았습니다. 또한, 공기 저항 계수는 공의 속도에 따라 변하며, 이에 따라 공의 행동이 달라질 수 있습니다. 이런 요소들을 고려하기 위해서는 더 복잡한 시뮬레이션 모델이 필요합니다.

'Golf > Physics' 카테고리의 다른 글

수학-알파지오메트리  (0) 2024.01.21
Simulation - golf3  (0) 2023.06.30
Simulation - golf2  (0) 2023.06.30

댓글