// Calculate button click private void Button_Click(object sender, RoutedEventArgs e) { if (Validation.GetHasError(longText) || Validation.GetHasError(latText) || Validation.GetHasError(longSatText)) { return; } double longitude = double.Parse(longText.Text, CultureInfo.CurrentCulture) * ((longEast.IsChecked == true) ? -1 : 1); double latitude = double.Parse(latText.Text, CultureInfo.CurrentCulture) * ((latSouth.IsChecked == true) ? -1 : 1); double longitudeSat = double.Parse(longSatText.Text, CultureInfo.CurrentCulture) * ((longSatEast.IsChecked == true) ? -1 : 1); MainViewport.Focus(); double elevation = SatelliteAntennaCalculator.GetElevationAngle(longitude, latitude, longitudeSat); if (elevation > 0) { azimutText.Text = SatelliteAntennaCalculator.GetAzimutAngle(longitude, latitude, longitudeSat).ToString("0#.#0°", CultureInfo.CurrentCulture); elevationText.Text = elevation.ToString("0#.#0°", CultureInfo.CurrentCulture); declinationText.Text = SatelliteAntennaCalculator.GetDeclinationAngle(longitude, latitude, longitudeSat).ToString("0#.#0°", CultureInfo.CurrentCulture); azimutText.Background = elevationText.Background = declinationText.Background = Brushes.White; azimutText.Foreground = declinationText.Foreground = elevationText.Foreground = Brushes.Black; } else { SolidColorBrush b = new SolidColorBrush(Color.FromArgb(0x99, 0xFF, 00, 00)); azimutText.Background = elevationText.Background = declinationText.Background = b; azimutText.Foreground = declinationText.Foreground = elevationText.Foreground = Brushes.White; azimutText.Text = declinationText.Text = elevationText.Text = "Nicht empfangbar!"; } DefineModel(longitude, latitude, longitudeSat); CameraPhi = -SatelliteAntennaCalculator.DegToRad(longitudeSat); CameraTheta = 0; switch (SelectedCamera) { case 1: PositionCamera2(longitude, latitude, longitudeSat); break; default: PositionCamera(); break; } if (latitude != 0) { FillElevationCurveRows(latitude, longitude, longitudeSat); angleGrid.ItemsSource = rows; ElevationCurveTab.IsEnabled = true; } else { rows.Clear(); ElevationCurveTab.IsEnabled = false; tabControl.SelectedIndex = 0; } ExportTab.IsEnabled = true; }
// Position the antenna camera. private void PositionCamera2(double longitude, double latitude, double longitudeSat) { // Calculate the camera's position in Cartesian coordinates. Vector3D v = SphericalCoordinatesToCartesic(r_e, -SatelliteAntennaCalculator.DegToRad(longitude), SatelliteAntennaCalculator.DegToRad(latitude)) * 1.005; TheCamera.Position = new Point3D(v.X, v.Y, v.Z); // Look toward the satellite Vector3D sat_vector = SphericalCoordinatesToCartesic(r_e / radius_earth, -SatelliteAntennaCalculator.DegToRad(longitudeSat), 0); TheCamera.LookDirection = Vector3D.Subtract(sat_vector, v); // Set the Up direction. TheCamera.UpDirection = new Vector3D(0, 0, 1); }
void FillElevationCurveRows(double latitude, double longitude, double longitudeSat) { rows.Clear(); int begin = ((latitude > 0) ? 90 : 270); for (int i = begin; i != (begin + 180 + 5) % 360; i = (i + 5) % 360) { double alpha = SatelliteAntennaCalculator.GetElevationCurve(i, latitude); if (alpha < 0) { rows.Add(new ElevationCurveRow { Azimut = i.ToString("0°", CultureInfo.CurrentCulture), Elevation = "nicht empfangbar", Deklination = "nicht empfangbar" }); continue; } else { double delta = SatelliteAntennaCalculator.GetDeclinationAngle(i, latitude); rows.Add(new ElevationCurveRow { Azimut = i.ToString("0°", CultureInfo.CurrentCulture), Elevation = alpha.ToString("0#.#0°", CultureInfo.CurrentCulture), Deklination = delta.ToString("0#.#0°", CultureInfo.CurrentCulture) }); } } }
// Add the model to the Model3DGroup. private void DefineModel(double longitude, double latitude, double longitudeSat) { // Clear everthing MainModel3Dgroup.Children.Clear(); Panel3D.Background = Brushes.SkyBlue; SetSun(longitude, latitude); // Make earth MainModel3Dgroup.Children.Add(new GeometryModel3D(AddSmoothSphere(new Point3D(0, 0, 0), r_e, 360, 180), new DiffuseMaterial(Brushes.Aqua))); // Make satellite cylinder Vector3D sat_vector = SphericalCoordinatesToCartesic(r_e / radius_earth, -SatelliteAntennaCalculator.DegToRad(longitudeSat), 0); MainModel3Dgroup.Children.Add(new GeometryModel3D(AddSmoothCylinder(new Point3D(sat_vector.X, sat_vector.Y, sat_vector.Z), Vector3D.Multiply(sat_vector, 0.005), 200, 50), new DiffuseMaterial(Brushes.Silver))); // Make antenna cylinder Vector3D person_vec = SphericalCoordinatesToCartesic(r_e, -SatelliteAntennaCalculator.DegToRad(longitude), SatelliteAntennaCalculator.DegToRad(latitude)) * 1.005; MainModel3Dgroup.Children.Add(new GeometryModel3D(AddSmoothCylinder(new Point3D(person_vec.X, person_vec.Y, person_vec.Z), Vector3D.Subtract(sat_vector, person_vec) * 0.00005 * r_e, 0.003 * r_e, 50), new DiffuseMaterial(Brushes.Gray))); // Add line between person and satellite SolidColorBrush brush6; if (SatelliteAntennaCalculator.GetElevationAngle(longitude, latitude, longitudeSat) < 0) { brush6 = new SolidColorBrush(Color.FromArgb(0x80, 0xff, 0, 0)); } else { brush6 = new SolidColorBrush(Color.FromArgb(0x80, 0x01, 0x32, 0x20)); } GeometryModel3D model6 = new GeometryModel3D(AddSmoothCylinder(new Point3D(person_vec.X, person_vec.Y, person_vec.Z), Vector3D.Subtract(sat_vector, person_vec), 0.003 * r_e, 50), new DiffuseMaterial(brush6)); MainModel3Dgroup.Children.Add(model6); }