private static Point3D[] GetSpherePlacement2(int count, double radius, Point3D[] existing) { Vector3D[] retVal = new Vector3D[count]; // Place them randomly for (int cntr = 0; cntr < count; cntr++) { retVal[cntr] = Math3D.GetRandomVector_Spherical(radius); } //int existingLength = existing == null ? 0 : existing.Length; //if (count + existingLength < 50) //{ //} //else //{ // //TODO: Use a quadtree // throw new ApplicationException("finish this"); //} // Exit Function return retVal.Select(o => o.ToPoint()).ToArray(); }
private void ShowVoronoi(Vector3D[] after) { Point[] points2D = after.Select(o => new Point(o.X, o.Y)).ToArray(); var result = Math2D.GetVoronoi(points2D, true); if (chkCapVoronoi.IsChecked.Value) { //result = CapVoronoi.CapCircle(result); result = Math2D.CapVoronoiCircle(result); } #region Edges ScreenSpaceLines3D lines = new ScreenSpaceLines3D(); lines.Color = UtilityWPF.ColorFromHex("808080"); lines.Thickness = 1d; foreach (var edge in result.Edges) { switch (edge.EdgeType) { case EdgeType.Segment: lines.AddLine(edge.Point0.ToPoint3D(), edge.Point1.Value.ToPoint3D()); break; case EdgeType.Ray: lines.AddLine(edge.Point0.ToPoint3D(), edge.Point0.ToPoint3D() + (edge.Direction.Value.ToVector3D().ToUnit() * 100)); break; case EdgeType.Line: Point3D point3D = edge.Point0.ToPoint3D(); Vector3D dir3D = edge.Direction.Value.ToVector3D().ToUnit() * 100; lines.AddLine(point3D - dir3D, point3D + dir3D); break; default: throw new ApplicationException("Unknown EdgeType: " + edge.EdgeType.ToString()); } } _visuals.Add(lines); _viewport.Children.Add(lines); #endregion #region Polygons #endregion }
private static Neuron_ZeroPos[] CreateNeurons(Vector3D[] thrustDirections) { Neuron_ZeroPos[] retVal; if (thrustDirections.Length == 1) { // Since there's only one, just put it in the center retVal = new Neuron_ZeroPos[] { new Neuron_ZeroPos(new Point3D(0, 0, 0)) }; } else { // Place the neurons along the direction of the corresponding thrust (the directions are already unit vectors) retVal = thrustDirections.Select(o => new Neuron_ZeroPos(o.ToPoint())).ToArray(); } return retVal; }
private void ShowDelaunay(Vector3D[] points, bool showLines, bool showCenters, bool reconstructTriangles) { if (!showLines && !showCenters && !reconstructTriangles) { return; } Point3D[] points3D = points.Select(o => o.ToPoint()).ToArray(); Point[] points2D = points3D.Select(o => new Point(o.X, o.Y)).ToArray(); TriangleIndexed[] triangles = Math2D.GetDelaunayTriangulation(points2D, points3D); if (showLines) { #region Lines ScreenSpaceLines3D lines = new ScreenSpaceLines3D(); lines.Color = UtilityWPF.ColorFromHex("709070"); lines.Thickness = 1d; foreach (var line in TriangleIndexed.GetUniqueLines(triangles)) { lines.AddLine(points3D[line.Item1], points3D[line.Item2]); } _visuals.Add(lines); _viewport.Children.Add(lines); #endregion } if (showCenters) { #region Centers Color color = Colors.Red; // Material MaterialGroup materials = new MaterialGroup(); materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(color))); materials.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(color, Colors.White, .5d)), 100d)); Model3DGroup geometries = new Model3DGroup(); for (int cntr = 0; cntr < triangles.Length; cntr++) { // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = UtilityWPF.GetSphere_LatLon(2, .04d); geometry.Transform = new TranslateTransform3D(triangles[cntr].GetCenterPoint().ToVector()); geometries.Children.Add(geometry); } // Add it AddVisual(geometries); #endregion } if (reconstructTriangles) { ShowReconstructTriangles(triangles.Select(o => o.GetCenterPoint()).ToArray()); } }
public double GetPositionSD(Vector3D[] data) { Vector3D mean = GetMeanVector(data); return Math.Sqrt(data.Select(x => Math.Pow((x - mean).Length, 2)).Sum() / data.Length); }