示例#1
0
        private async Task <List <Pixel> > GetListAsync(Group group, int dx, int dy, int viceVersa, int width, int height, Bgr24Bitmap bitmap)
        {
            return(await Task.Run(() =>
            {
                List <Pixel> pixels = new List <Pixel>();
                int count = 0;
                ZBuffer zBuf = new ZBuffer(width, height);
                Parallel.ForEach(group.Faces, face =>
                {
                    if (IsFaceVisible(group.Vertices, face))
                    {
                        List <Pixel> pixelsForSide = new List <Pixel>();
                        List <Pixel> pixelsInSide = new List <Pixel>();
                        Vertex vertex0, vertex1;
                        int index0, index1;

                        Vector3 lightingVector = new Vector3(0, 0, 1);

                        int ind0 = (face.FaceElements.ElementAt(0).VertexNormalIndex != null) ? (int)face.FaceElements.ElementAt(0).VertexNormalIndex : 1;
                        Vector3 point0Normal = new Vector3(group.VertexNormals[ind0 - 1].X, group.VertexNormals[ind0 - 1].Y, group.VertexNormals[ind0 - 1].Z);

                        int ind1 = (face.FaceElements.ElementAt(1).VertexNormalIndex != null) ? (int)face.FaceElements.ElementAt(1).VertexNormalIndex : 1;
                        Vector3 point1Normal = new Vector3(group.VertexNormals[ind1 - 1].X, group.VertexNormals[ind1 - 1].Y, group.VertexNormals[ind1 - 1].Z);

                        int ind2 = (face.FaceElements.ElementAt(2).VertexNormalIndex != null) ? (int)face.FaceElements.ElementAt(2).VertexNormalIndex : 1;
                        Vector3 point2Normal = new Vector3(group.VertexNormals[ind2 - 1].X, group.VertexNormals[ind2 - 1].Y, group.VertexNormals[ind2 - 1].Z);

                        Color color = Color.FromArgb(255, 255, 0, 0);
                        Color point1Color = Lambert.GetPointColor(point0Normal, lightingVector, color);
                        Color point2Color = Lambert.GetPointColor(point1Normal, lightingVector, color);
                        Color point3Color = Lambert.GetPointColor(point2Normal, lightingVector, color);
                        Color faceColor = PlaneShading.GetAverageColor(point1Color, point2Color, point3Color);

                        for (int i = 0; i < face.FaceElements.Count - 1; i++)
                        {
                            index0 = (face.FaceElements.ElementAt(i).VertexIndex != -2) ? face.FaceElements.ElementAt(i).VertexIndex : (group.Vertices.Count - 1);
                            index1 = (face.FaceElements.ElementAt(i + 1).VertexIndex != -2) ? face.FaceElements.ElementAt(i + 1).VertexIndex : (group.Vertices.Count - 1);
                            vertex0 = group.Vertices.ElementAt(index0);
                            vertex1 = group.Vertices.ElementAt(index1);
                            pixelsForSide.AddRange(Bresenham.GetPixels((int)(vertex0.X + dx), (int)(vertex0.Y * viceVersa + dy), (int)(vertex0.Z), (int)(vertex1.X + dx), (int)(vertex1.Y * viceVersa + dy), (int)(vertex1.Z), windowWidth, windowHeight, bitmap, zBuf, faceColor));
                        }
                        index0 = (face.FaceElements.ElementAt(0).VertexIndex != -2) ? face.FaceElements.ElementAt(0).VertexIndex : (group.Vertices.Count - 1);
                        index1 = (face.FaceElements.ElementAt(face.FaceElements.Count - 1).VertexIndex != -2) ? face.FaceElements.ElementAt(face.FaceElements.Count - 1).VertexIndex : (group.Vertices.Count - 1);
                        vertex0 = group.Vertices.ElementAt(index0);
                        vertex1 = group.Vertices.ElementAt(index1);
                        pixelsForSide.AddRange(Bresenham.GetPixels((int)(vertex0.X + dx), (int)(vertex0.Y *viceVersa + dy), vertex0.Z, (int)(vertex1.X + dx), (int)(vertex1.Y *viceVersa + dy), vertex1.Z, windowWidth, windowHeight, bitmap, zBuf, faceColor));


                        RastAlgorithm.DrawPixelForRasterization(pixelsForSide, bitmap, zBuf, faceColor);
                        //pixels.AddRange(pixelsForSide);
                        //pixelsInSide.AddRange(RastAlgorithm.DrawPixelForRasterization(pixelsForSide, bitmap, zBuf));
                        //pixels.AddRange(pixelsInSide);
                        count++;
                    }
                });
                return pixels;
            }));
        }
示例#2
0
    private static void test02()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST02 tests WEW_B
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    11 June 2014
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        double en = 0;
        double w1 = 0;
        double x  = 0;

        Console.WriteLine("");
        Console.WriteLine("TEST02");
        Console.WriteLine("  Test WEW_B to evaluate");
        Console.WriteLine("  Lambert's W function.");
        Console.WriteLine("");
        Console.WriteLine("          X             Exact             Computed      Error");
        Console.WriteLine("");

        int n_data = 0;

        for (;;)
        {
            Burkardt.Values.Lambert.lambert_w_values(ref n_data, ref x, ref w1);

            if (n_data <= 0)
            {
                break;
            }

            double w2 = x switch
            {
                0.0 => 0.0,
                _ => Lambert.wew_b(x, ref en)
            };

            Console.WriteLine(x.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "  "
                              + w1.ToString(CultureInfo.InvariantCulture).PadLeft(16) + "  "
                              + w2.ToString(CultureInfo.InvariantCulture).PadLeft(16) + "  "
                              + Math.Abs(w1 - w2).ToString(CultureInfo.InvariantCulture).PadLeft(10) + "");
        }
    }
}
示例#3
0
        bool LambertSolutionExists()
        {
            // Make local copies of departure and arrival orbits.
            OrbitData earthCopy    = null;
            OrbitData asteroidCopy = null;

            foreach (Body body in Bodies)
            {
                if (body.tag == "Earth")
                {
                    earthCopy = new OrbitData(body.Orbit);
                }
                else if (body.tag == "Asteroid")
                {
                    asteroidCopy = new OrbitData(body.Orbit);
                }
            }

            // Advance orbits to epoch of impact for Lambert solver
            earthCopy.Epoch    = ImpactEpoch;
            asteroidCopy.Epoch = ImpactEpoch;

            // Get the transfer orbit and C3 from the Lambert solution
            LambertSolution lambertSolution = Lambert.GetTransferOrbit(earthCopy, asteroidCopy, TimeOfDeflection, TransferTime, -1);

            if (lambertSolution == null)
            {
                Debug.Log("No Lambert solution found\nTry different mission values.");
                ShowInfeasibleLaunchWindow();
                return(false);
            }

            if (lambertSolution.C3 <= 0.0)
            {
                Debug.Log("Lambert solution requires negative C3");
                ShowInfeasibleLaunchWindow();
                return(false);
            }

            double deliverableMass = LaunchVehicleType.ComputeDeliverableMass(lambertSolution.C3, NumLaunches * EffectMultiplier);

            if (deliverableMass <= 0.0)
            {
                Debug.LogFormat("Launch C3 = {0:F4}\nLaunch Vehicle unable to obtain required launch energy",
                                lambertSolution.C3);
                ShowInfeasibleLaunchWindow();
                return(false);
            }
            Debug.LogFormat("Launch C3 = {0:F4}Impact Mass = {1:F4}; Impact Vel. = {2:E4}",
                            lambertSolution.C3, MassKI, lambertSolution.arrDV.magnitude);
            SetMissionValuesText(deliverableMass, lambertSolution.C3, lambertSolution.arrDV.magnitude);
            return(true);
        }
示例#4
0
文件: Form1.cs 项目: lythhh/lytcck
        //兰伯特投影
        public static List <PointF[]> inverseCompute(List <PointF[]> mapPoints)
        {
            List <PointF[]> outList = new List <PointF[]>();

            for (int i = 0; i < mapPoints.Count; i++)
            {
                PointF[] points = new PointF[mapPoints[i].Length];
                for (int j = 0; j < mapPoints[i].Length; j++)
                {
                    points[j] = Lambert.blToXY(mapPoints[i][j]);
                }
                outList.Add(points);
                Lambert.blToXY
            }
            return(outList);
        }
        public void LambertTest()
        {
            /*
             * Vector3 EarthRad = Earth.Heliocentric(2457239 - 2451545);
             * Vector3 MarsRad = Mars.Heliocentric(2457239 - 2451545 + 150);
             * double time = 150;
             */
            Vector3 EarthRad  = new Vector3(4.440778960961146E+07, -1.454625135657227E+08, 7.039903338298202E+03);
            Vector3 MarsRad   = new Vector3(8.550441288420311E+07, 2.098123095830674E+08, 2.299312316831380E+06);
            double  time      = 2459219 - 2459039;
            Vector3 Vout      = new Lambert().Solver(EarthRad, MarsRad, time, "pro", "V1");
            double  LambertIs = Vout.Magnitude();
            double  ShouldBe  = 32.9054;

            Assert.AreEqual(LambertIs, ShouldBe, .05);
        }
    public static void lambert_w_values_test()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    LAMBERT_W_VALUES_TEST tests LAMBERT_W_VALUES.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    12 June 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        double fx = 0;
        double x  = 0;

        Console.WriteLine("");
        Console.WriteLine("LAMBERT_W_VALUES_TEST:");
        Console.WriteLine("  LAMBERT_W_VALUES stores values of ");
        Console.WriteLine("  the Lambert W function.");
        Console.WriteLine("");
        Console.WriteLine("                X                     W(X)");
        Console.WriteLine("");
        int n_data = 0;

        for (;;)
        {
            Lambert.lambert_w_values(ref n_data, ref x, ref fx);
            if (n_data == 0)
            {
                break;
            }

            Console.WriteLine("  "
                              + x.ToString("0.################").PadLeft(24) + "  "
                              + fx.ToString("0.################").PadLeft(24) + "");
        }
    }
示例#7
0
        /// <summary>
        /// Launches a spacecraft from Earth to intercept/deflect the asteroid.
        /// </summary>
        public void LaunchSpacecraft()
        {
            // Make local copies of departure and arrival orbits.
            OrbitData earth    = null;
            OrbitData asteroid = null;

            foreach (Body body in Bodies)
            {
                if (body.tag == "Earth")
                {
                    earth = new OrbitData(body.Orbit);
                }
                else if (body.tag == "Asteroid")
                {
                    asteroid = new OrbitData(body.Orbit);
                }
            }
            if (earth == null || asteroid == null)
            {
                Debug.LogError("Error finding departure/arrival orbits from bodies list by tag");
                return;
            }

            // Advance orbits to epoch of impact for Lambert solver
            earth.Epoch    = ImpactEpoch;
            asteroid.Epoch = ImpactEpoch;

            // Get the transfer orbit and C3 from the Lambert solution
            LambertSolution lambertSolution = Lambert.GetTransferOrbit(earth, asteroid, TimeOfDeflection, TransferTime, -1);

            if (lambertSolution == null || lambertSolution.C3 <= 0.0)
            {
                DisplayTextWithFadeEffect(MessageText, "No Lambert solution found");
                return;
            }

            // MassKI calculated here will be used in ProcessCollisionEnter
            MassKI = LaunchVehicleType.ComputeDeliverableMass(lambertSolution.C3, NumLaunches * EffectMultiplier);
            if (MassKI <= 0.0)
            {
                DisplayTextWithFadeEffect(MessageText, string.Format("Launch vehicle unable to achieve C3 {0:E3} (km/s)^2", lambertSolution.C3));
                return;
            }

            // TODO: Initialize spacecraft from prefab here
            //GameObject prefab = Instantiate(Resources.Load("Spacecraft.prefab", typeof(GameObject)) as GameObject);
            Body spacecraft = spacecraftObject.GetComponent <Body>();

            if (spacecraft == null)
            {
                Debug.LogError("Instantiated spacecraft prefab does not have Body component");
            }
            spacecraft.InitOrbit(lambertSolution.TransferOrbit);
            spacecraft.SetImpactEpoch(ImpactEpoch - TimeOfDeflection);
            spacecraft.gameObject.SetActive(true);

            Bodies = FindObjectsOfType <Body>(); // Update bodies list

            string message = string.Format("Launch successful!\nC3 = {0:F3} (km/s)^2\nMass = {1:F1} kg", lambertSolution.C3, MassKI);

            DisplayTextWithFadeEffect(MessageText, message);
        }
示例#8
0
 public Technique(string sid, Lambert item)
     : this(sid)
 { this.item = item; }