/// <summary> /// Create a cylinder to encapsulate the arrows. The cylinder will /// be X m/s wide. The cylinder will be transparent so the arrows within /// can be seen. /// </summary> /// <param name="numBins"></param> /// <returns></returns> private Model3D CreateCylinder(int numBins) { var mb = new MeshBuilder(false, false); TruncatedConeVisual3D cyl = new TruncatedConeVisual3D(); // This will create a cylinder, basically 2 cones on top of each other cyl.BaseRadius = CylinderRadius * SCALE_ARROW; // Set the radius of the cylinder based off X m/s using the scale factor cyl.TopRadius = cyl.BaseRadius; // Set the radius of the cylinder cyl.Fill = new SolidColorBrush(Color.FromArgb(40, 00, 130, 255)); // Set the color of the cylinder. Make it trasparent cyl.Origin = new Point3D(0,0,0); // Set the origin of the cylinder as the origin of the plot if (YAxis) { cyl.Normal = new Vector3D(0, 1, 0); // Set the orientation of the cylinder Y Up cyl.Height = -numBins * TRANSLATION_SCALE; // Set the height based off the number bins and scale (go in the negative direction) } else { cyl.Normal = new Vector3D(1, 0, 0); // Set the orientation of the cylinder Y Up cyl.Height = numBins * TRANSLATION_SCALE; // Set the height based off the number bins and scale (go in the Positive direction) } return cyl.Content; }
private void UpdateVisuals() { Children.Clear(); if (WindTurbine == null) return; var baseTower = new TruncatedConeVisual3D { Fill = Brushes.Yellow, Origin = new Point3D(0, 0, -WindTurbine.BaseHeight) }; baseTower.Height = -baseTower.Origin.Z + 2; baseTower.BaseRadius = baseTower.TopRadius = WindTurbine.Diameter; var tower = new TruncatedConeVisual3D { Fill = Brushes.White, Origin = new Point3D(0, 0, 2), Height = WindTurbine.Height, BaseRadius = WindTurbine.Diameter }; tower.TopRadius = tower.BaseRadius * (1 - WindTurbine.Height * Math.Sin(WindTurbine.ShaftAngle / 180.0 * Math.PI)); var nacelle = new TruncatedConeVisual3D { Fill = Brushes.White, Origin = new Point3D(WindTurbine.Overhang, 0, tower.Origin.Z + tower.Height), Normal = new Vector3D(-1, 0, 0), TopRadius = WindTurbine.NacelleDiameter }; nacelle.BaseRadius = nacelle.TopRadius * 0.7; nacelle.Height = WindTurbine.NacelleLength; Children.Add(baseTower); Children.Add(tower); Children.Add(nacelle); var endcap = new SphereVisual3D { Center = new Point3D(WindTurbine.Overhang - WindTurbine.NacelleLength, 0, tower.Origin.Z + tower.Height), Radius = nacelle.TopRadius, Fill = Brushes.White }; Children.Add(endcap); var rotor = new ModelVisual3D(); for (int i = 0; i < WindTurbine.Blades; i++) { double angle = (double)i / WindTurbine.Blades * Math.PI * 2; // todo: the blade is simplified to a cone... it should be a real profile... var blade = new TruncatedConeVisual3D { Origin = nacelle.Origin, Normal = new Vector3D(0, Math.Cos(angle), Math.Sin(angle)), Height = WindTurbine.BladeLength, BaseRadius = WindTurbine.BladeRootChord, TopRadius = WindTurbine.BladeTipChord, Fill = Brushes.White }; rotor.Children.Add(blade); } var hub = new SphereVisual3D { Fill = Brushes.White, Center = nacelle.Origin, Radius = WindTurbine.HubDiameter / 2 }; rotor.Children.Add(hub); Children.Add(rotor); var rotation = new AxisAngleRotation3D(new Vector3D(1, 0, 0), 0); var rotorTransform = new RotateTransform3D(null, hub.Center) { Rotation = rotation }; rotor.Transform = rotorTransform; var b = new Binding("RotationAngle") { Source = this }; BindingOperations.SetBinding(rotation, AxisAngleRotation3D.AngleProperty, b); }