private void SHOW_N_S_W_E_Plane_angle(Vector3d v1, StreamWriter file)
        {
            Vector3d v = v1.Copy();

            char[] dir = { 'E', 'N', 'U' };
            if (v.X < 0)
            {
                dir[0] = 'W';
                v.X    = -v.X;
            }
            if (v.Y < 0)
            {
                dir[1] = 'S';
                v.Y    = -v.Y;
            }
            if (v.Z < 0)
            {
                dir[2] = 'D';
                v.Z    = -v.Z;
            }
            double angle_EN = R2D(Math.Atan2(v.Y, v.X));
            double angle_NU = R2D(Math.Atan2(v.Z, Math.Sqrt(v.X * v.X + v.Y * v.Y)));

            file.WriteLine(dir[0] + " {0:0.##} " + dir[1] + " {1:0.##} " + dir[2], angle_EN, angle_NU);
        }
        private void SHOW_N_S_W_E(Vector3d v1)
        {
            Vector3d v = v1.Copy();

            char[] dir = { 'E', 'N', 'U' };
            if (v.X < 0)
            {
                dir[0] = 'W';
                v.X    = -v.X;
            }
            if (v.Y < 0)
            {
                dir[1] = 'S';
                v.Y    = -v.Y;
            }
            if (v.Z < 0)
            {
                dir[2] = 'D';
                v.Z    = -v.Z;
            }
            Console.WriteLine(dir[0] + ": {0:0.##}, " + dir[1] + ": {1:0.##}, " + dir[2] + ": {2:0.##}", v.X, v.Y, v.Z);
            Console.WriteLine();
            Console.WriteLine("단면(수직벡터)의 회전각도");
            double angle_EN = R2D(Math.Atan2(v.Y, v.X));
            double angle_NU = R2D(Math.Atan2(v.Z, Math.Sqrt(v.X * v.X + v.Y * v.Y)));

            Console.WriteLine(dir[0] + " {0:0.##} " + dir[1] + " {1:0.##} " + dir[2], angle_EN, angle_NU);
        }
Exemple #3
0
        bool CanClipEar(List <Vector3d> poly, int u, int v, int w, int n, int[] verts)
        {
            int p;

            Vector3d a = poly[verts[u]].Copy();
            Vector3d b = poly[verts[v]].Copy();
            Vector3d c = poly[verts[w]].Copy();
            Vector3d P;

            Vector3d d = Vector3d.SubtractVectors(b, a);

            d.Normalize();
            Vector3d e = Vector3d.SubtractVectors(b, c);

            e.Normalize();

            Vector3d g = Vector3d.Cross(d, e);

            Vector3d bn = b.Copy();

            bn.Normalize();

            //Determin if convex edge
            if (Vector3d.Dot(g, bn) > 0)
            {
                return(false);
            }


            // Check for any interecting vertexies that would invalidate this ear
            for (p = 0; p < n; p++)
            {
                if ((p == u) || (p == v) || (p == w))
                {
                    continue;
                }

                P = poly[verts[p]].Copy();

                // don;t Clip earth if  other intersecting vertex
                if (InsideTriangle(a, b, c, P))
                {
                    return(false);
                }
            }

            return(true);
        }
        public CameraParameters Copy()
        {
            CameraParameters temp = new CameraParameters();

            temp.Lat                  = Lat;
            temp.Lng                  = Lng;
            temp.Zoom                 = Zoom;
            temp.Rotation             = Rotation;
            temp.Angle                = Angle;
            temp.RaDec                = RaDec;
            temp.Opacity              = Opacity;
            temp.ViewTarget           = ViewTarget.Copy();
            temp.Target               = Target;
            temp.TargetReferenceFrame = TargetReferenceFrame;
            return(temp);
        }
        private void SHOW_N_S_W_E(Vector3d v1, StreamWriter file)
        {
            Vector3d v = v1.Copy();

            char[] dir = { 'E', 'N', 'U' };
            if (v.X < 0)
            {
                dir[0] = 'W';
                v.X    = -v.X;
            }
            if (v.Y < 0)
            {
                dir[1] = 'S';
                v.Y    = -v.Y;
            }
            if (v.Z < 0)
            {
                dir[2] = 'D';
                v.Z    = -v.Z;
            }
            file.WriteLine(dir[0] + " {0:0.##} " + dir[1] + " {1:0.##} " + dir[2] + " {2:0.##}", v.X, v.Y, v.Z);
        }
Exemple #6
0
        public void AddGlyphPoints(List <PositionTexture> pointList, Vector2d size, Rectangle position, Rectangle uv)
        {
            PositionTexture[] points = new PositionTexture[6];

            for (int i = 0; i < 6; i++)
            {
                points[i] = new PositionTexture();
            }



            Vector3d left  = Vector3d.Cross(center, up);
            Vector3d right = Vector3d.Cross(up, center);

            left.Normalize();
            right.Normalize();
            up.Normalize();

            Vector3d upTan = Vector3d.Cross(center, right);

            upTan.Normalize();

            if (alignment == Alignment.Center)
            {
                left.Multiply(width - position.Left * 2);
                right.Multiply(width - ((width * 2) - position.Right * 2));
            }
            else if (alignment == Alignment.Left)
            {
                left.Multiply(-position.Left * 2);
                right.Multiply(position.Right * 2);
            }

            Vector3d top    = upTan.Copy();
            Vector3d bottom = Vector3d.SubtractVectors(Vector3d.Empty, upTan);

            top.Multiply(height - position.Top * 2);
            bottom.Multiply(height - ((height * 2) - position.Bottom * 2));
            Vector3d ul = center.Copy();

            ul.Add(top);
            if (sky)
            {
                ul.Add(left);
            }
            else
            {
                ul.Subtract(left);
            }
            Vector3d ur = center.Copy();

            ur.Add(top);
            if (sky)
            {
                ur.Add(right);
            }
            else
            {
                ur.Subtract(right);
            }
            Vector3d ll = center.Copy();

            if (sky)
            {
                ll.Add(left);
            }
            else
            {
                ll.Subtract(left);
            }

            ll.Add(bottom);

            Vector3d lr = center.Copy();

            if (sky)
            {
                lr.Add(right);
            }
            else
            {
                lr.Subtract(right);
            }
            lr.Add(bottom);

            points[0].Position = ul.Copy();
            points[0].Tu       = uv.Left;
            points[0].Tv       = uv.Top;
            //     points[0].Color = Color;

            points[2].Tu       = uv.Left;
            points[2].Tv       = uv.Bottom;
            points[2].Position = ll.Copy();
            //      points[2].Color = Color;

            points[1].Tu       = uv.Right;
            points[1].Tv       = uv.Top;
            points[1].Position = ur.Copy();
            //      points[1].Color = Color;

            points[3].Tu       = uv.Right;
            points[3].Tv       = uv.Bottom;
            points[3].Position = lr.Copy();
            //      points[3].Color = Color;

            points[5].Tu       = uv.Right;
            points[5].Tv       = uv.Top;
            points[5].Position = ur.Copy();
            //     points[5].Color = Color;

            points[4].Tu       = uv.Left;
            points[4].Tv       = uv.Bottom;
            points[4].Position = ll.Copy();
            //     points[4].Color = Color;

            if (Rotation != 0 || Tilt != 0 || Bank != 0)
            {
                if (!matInit)
                {
                    Matrix3d lookAt    = Matrix3d.LookAtLH(center, new Vector3d(), up);
                    Matrix3d lookAtInv = lookAt.Clone();
                    lookAtInv.Invert();

                    rtbMat = Matrix3d.MultiplyMatrix(Matrix3d.MultiplyMatrix(Matrix3d.MultiplyMatrix(Matrix3d.MultiplyMatrix(lookAt, Matrix3d.RotationZ(-Rotation / 180 * Math.PI)), Matrix3d.RotationX(-Tilt / 180 * Math.PI)), Matrix3d.RotationY(-Bank / 180 * Math.PI)), lookAtInv);
                    //todo make this true after debug
                    matInit = true;
                }
                for (int i = 0; i < 6; i++)
                {
                    points[i].Position = Vector3d.TransformCoordinate(points[i].Position, rtbMat);
                }
            }

            foreach (PositionTexture pnt in points)
            {
                pointList.Add(pnt);
            }
        }
        public override double GetSurfacePointAltitude(double lat, double lng, bool meters)
        {
            if (Level < lastDeepestLevel)
            {
                //interate children
                for (int ii = 0; ii < 4; ii++)
                {
                    Tile child = children[ii];
                    if (child != null)
                    {
                        if (child.IsPointInTile(lat, lng))
                        {
                            double retVal = child.GetSurfacePointAltitude(lat, lng, meters);
                            if (retVal != 0)
                            {
                                return(retVal);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }

            TileTargetLevel = Level;
            TileTargetX     = tileX;
            TileTargetY     = tileY;



            Vector3d testPoint = Coordinates.GeoTo3dDouble(-lat, lng);

            testPoint = Vector3d.SubtractVectors(new Vector3d(), testPoint);
            Vector2d uv = DistanceCalc.GetUVFromInnerPoint(TopLeft.Copy(), TopRight.Copy(), BottomLeft.Copy(), BottomRight.Copy(), testPoint.Copy());


            //Document.Title = "u:" + uv.X + ", v:" + uv.Y;
            //uv.X = 1 - uv.X;
            //uv.Y = 1 - uv.Y;
            // Get 4 samples and interpolate
            double uud = Math.Max(0, Math.Min(16, (uv.X * 16)));
            double vvd = Math.Max(0, Math.Min(16, (uv.Y * 16)));



            int uu = Math.Max(0, Math.Min(15, (int)(uv.X * 16)));
            int vv = Math.Max(0, Math.Min(15, (int)(uv.Y * 16)));

            double ha = uud - uu;
            double va = vvd - vv;

            if (demArray != null)
            {
                // 4 nearest neighbors
                double ul = demArray[uu + 17 * vv];
                double ur = demArray[(uu + 1) + 17 * vv];
                double ll = demArray[uu + 17 * (vv + 1)];
                double lr = demArray[(uu + 1) + 17 * (vv + 1)];

                double top    = ul * (1 - ha) + ha * ur;
                double bottom = ll * (1 - ha) + ha * lr;
                double val    = top * (1 - va) + va * bottom;

                return(val / DemScaleFactor);
            }

            return(demAverage / DemScaleFactor);
        }
Exemple #8
0
        //private Vector3d GetTragectoryPoint(double jNow, out Vector3d vector)
        //{
        //int min = 0;
        //int max = Trajectory.Count - 1;

        //Vector3d point =  new Vector3d();

        //vector = new Vector3d();

        //int current = max / 2;

        //bool found = false;

        //while (!found)
        //{
        //    if (current < 1)
        //    {
        //        vector = Trajectory[0].Position - Trajectory[1].Position;
        //        return Trajectory[0].Position;
        //    }


        //    if (current == Trajectory.Count - 1)
        //    {
        //        vector = Trajectory[current - 1].Position - Trajectory[current].Position;
        //        return Trajectory[current].Position;
        //    }

        //    if ((Trajectory[current-1].Time <= jNow) && (Trajectory[current].Time > jNow))
        //    {
        //        double denominator = Trajectory[current].Time -Trajectory[current-1].Time;
        //        double numerator = jNow - Trajectory[current - 1].Time;
        //        double tween = numerator / denominator;
        //        vector = Trajectory[current - 1].Position - Trajectory[current].Position;
        //        point = Vector3d.Lerp(Trajectory[current - 1].Position, Trajectory[current].Position, tween);
        //        return point;
        //    }

        //    if (Trajectory[current].Time < jNow)
        //    {
        //        int next = current + ( max - current + 1) / 2;
        //        min = current;
        //        current = next;
        //    }
        //    else
        //    if (Trajectory[current - 1].Time > jNow)
        //    {
        //        int next = current - ( current - min + 1) / 2;
        //        max = current;
        //        current = next;
        //    }
        //}

        //return point;
        //}

        private void ComputeOrbital(RenderContext renderContext)
        {
            EOE      ee    = Elements;
            Vector3d point = ELL.CalculateRectangularJD(SpaceTimeController.JNow, ee);

            MeanAnomoly = ee.meanAnnomolyOut;
            Vector3d pointInstantLater = ELL.CalculateRectangular(ee, MeanAnomoly + .001);

            Vector3d direction = Vector3d.SubtractVectors(point, pointInstantLater);

            Vector3d up = point.Copy();

            up.Normalize();
            direction.Normalize();

            double dist        = point.Length();
            double scaleFactor = 1.0;

            switch (SemiMajorAxisUnits)
            {
            case AltUnits.Meters:
                scaleFactor = 1.0;
                break;

            case AltUnits.Feet:
                scaleFactor = 1.0 / 3.2808399;
                break;

            case AltUnits.Inches:
                scaleFactor = (1.0 / 3.2808399) / 12;
                break;

            case AltUnits.Miles:
                scaleFactor = 1609.344;
                break;

            case AltUnits.Kilometers:
                scaleFactor = 1000;
                break;

            case AltUnits.AstronomicalUnits:
                scaleFactor = UiTools.KilometersPerAu * 1000;
                break;

            case AltUnits.LightYears:
                scaleFactor = UiTools.AuPerLightYear * UiTools.KilometersPerAu * 1000;
                break;

            case AltUnits.Parsecs:
                scaleFactor = UiTools.AuPerParsec * UiTools.KilometersPerAu * 1000;
                break;

            case AltUnits.MegaParsecs:
                scaleFactor = UiTools.AuPerParsec * UiTools.KilometersPerAu * 1000 * 1000000;
                break;

            case AltUnits.Custom:
                scaleFactor = 1;
                break;

            default:
                break;
            }
            scaleFactor *= 1 / renderContext.NominalRadius;


            Matrix3d look = Matrix3d.LookAtLH(Vector3d.Create(0, 0, 0), direction, up);

            look.Invert();

            WorldMatrix = Matrix3d.Identity;
            WorldMatrix.Translate(Translation);

            double localScale = (1 / renderContext.NominalRadius) * Scale * MeanRadius;

            WorldMatrix.Scale(Vector3d.Create(localScale, localScale, localScale));

            //Matrix3d mat = Matrix3d.MultiplyMatrix(Matrix3d.MultiplyMatrix(Matrix3d.RotationY(Heading / 180.0 * Math.PI), Matrix3d.RotationX(Pitch / 180.0 * Math.PI)),Matrix3d.RotationZ(Roll / 180.0 * Math.PI));

            WorldMatrix.Multiply(Matrix3d.RotationYawPitchRoll((float)((Heading) / 180.0 * Math.PI), (float)(Pitch / 180.0 * Math.PI), (float)(Roll / 180.0 * Math.PI)));

            if (RotationalPeriod != 0)
            {
                double rotationCurrent = (((SpaceTimeController.JNow - this.ZeroRotationDate) / RotationalPeriod) * Math.PI * 2) % (Math.PI * 2);
                WorldMatrix.Multiply(Matrix3d.RotationX(-rotationCurrent));
            }

            point = Vector3d.Scale(point, scaleFactor);

            WorldMatrix.Translate(point);

            if (StationKeeping)
            {
                WorldMatrix = Matrix3d.MultiplyMatrix(look, WorldMatrix);
            }
        }