Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 在飞机上拦截日出_Objective C_Swift_Great Circle - Fatal编程技术网

Objective c 在飞机上拦截日出

Objective c 在飞机上拦截日出,objective-c,swift,great-circle,Objective C,Swift,Great Circle,我想计算飞机与日出或日落之间最接近的预计时间,记住: 红线是飞机上的大圆轨道。 蓝色的圆圈是飞机。 1-已知太阳赤纬度(纬度)和交叉经度,加上日出半径约为5450海里,因此日出可以显示为一个圆心和半径已知的圆 2-我使用了2D矢量代码,因为大圆路径不能应用于XY平面,所以该代码不起作用 2-飞机在弯曲的大圆轨道上飞行,纬度变化不是线性的,如果纬度变化不是恒定的,我如何使用飞机速度作为速度矢量 /// Va - Velocity of circle A. Va = new Vect

我想计算飞机与日出或日落之间最接近的预计时间,记住:

红线是飞机上的大圆轨道。 蓝色的圆圈是飞机。

1-已知太阳赤纬度(纬度)和交叉经度,加上日出半径约为5450海里,因此日出可以显示为一个圆心和半径已知的圆

2-我使用了2D矢量代码,因为大圆路径不能应用于XY平面,所以该代码不起作用

2-飞机在弯曲的大圆轨道上飞行,纬度变化不是线性的,如果纬度变化不是恒定的,我如何使用飞机速度作为速度矢量

 /// Va - Velocity of circle A.
     Va = new Vector2(450, 0);
我用的是c代码


我要找的就是算法。以及如何将飞机速度表示为Velocity Vector2D或Vector3D。

我接受任何语言的答案,JAVA、JS、Objective C、Swift、,
    /// Calculate the time of closest approach of two moving circles.  Also determine if the circles collide.
    /// 
    /// Input:
    /// Pa - Position of circle A.
    /// Pb - Position of circle B.
    /// Va - Velocity of circle A.
    /// Vb - Velocity of circle B.
    /// Ra - Radius of circle A.
    /// Rb - Radius of circle B.

    // Set up the initial position, velocity, and size of the circles.
        Pa = new Vector2(150, 250);
        Pb = new Vector2(600, 400);
        Va = new Vector2(450, 0);
        Vb = new Vector2(-100, -250);
        Ra = 60;
        Rb = 30;


    /// Returns:
    /// collision - Returns True if a collision occured, else False.
    /// The method returns the time to impact if collision=true, else it returns the time of closest approach.
    public float TimeOfClosestApproach(Vector2 Pa, Vector2 Pb, Vector2 Va, Vector2 Vb, float Ra, float Rb, out bool collision)
    {
        Vector2 Pab = Pa - Pb;
        Vector2 Vab = Va - Vb;
        float a = Vector2.Dot(Vab, Vab);
        float b = 2 * Vector2.Dot(Pab, Vab);
        float c = Vector2.Dot(Pab, Pab) - (Ra + Rb) * (Ra + Rb);

        // The quadratic discriminant.
        float discriminant = b * b - 4 * a * c;

        // Case 1:
        // If the discriminant is negative, then there are no real roots, so there is no collision.  The time of
        // closest approach is then given by the average of the imaginary roots, which is:  t = -b / 2a
        float t;
        if (discriminant < 0)
        {
            t = -b / (2 * a);
            collision = false;
        }
        else
        {
            // Case 2 and 3:
            // If the discriminant is zero, then there is exactly one real root, meaning that the circles just grazed each other.  If the 
            // discriminant is positive, then there are two real roots, meaning that the circles penetrate each other.  In that case, the
            // smallest of the two roots is the initial time of impact.  We handle these two cases identically.
            float t0 = (-b + (float)Math.Sqrt(discriminant)) / (2 * a);
            float t1 = (-b - (float)Math.Sqrt(discriminant)) / (2 * a);
            t = Math.Min(t0, t1);

            // We also have to check if the time to impact is negative.  If it is negative, then that means that the collision
            // occured in the past.  Since we're only concerned about future events, we say that no collision occurs if t < 0.
            if (t < 0)
                collision = false;
            else
                collision = true;
        }

        // Finally, if the time is negative, then set it to zero, because, again, we want this function to respond only to future events.
        if (t < 0)
            t = 0;

        return t;
    }
    JAVA , JS, Objective-C , Swift , C#.