public Satellite3D() { orbit = new TubeVisual3D() { Diameter = 0.3, ThetaDiv = 12 }; orbit.Material = MaterialHelper.CreateMaterial(null, Brushes.Gray, Brushes.White, 0.5, 40); Children.Add(orbit); }
/* internal void drawLine(Point3D start, Point3D pt, bool hit) { TubeVisual3D line; lines.TryGetValue(start, out line); if (line != null) { this.Children.Remove(line); lines.Remove(start); } Point3DCollection contours = new Point3DCollection(); contours.Add(ToWorld(start)); contours.Add(ToWorld(pt)); line = new TubeVisual3D { Diameter = 0.5, Path = contours, Fill = Brushes.SandyBrown }; lines.Add(start,line); this.Children.Add(line); addBox(start); if(hit) addBox(pt); } */ internal void drawLine(Point3D start, Point3D end) { TubeVisual3D line; lines.TryGetValue(start, out line); if (line != null) { this.Children.Remove(line); lines.Remove(start); } Point3DCollection contours = new Point3DCollection(); contours.Add(ToWorld(start)); contours.Add(ToWorld(end)); line = new TubeVisual3D { Diameter = 0.3, Path = contours, Fill = Brushes.DarkOliveGreen}; lines.Add(start, line); this.Children.Add(line); string x = string.Format("{0:0.00}",end.X); string y = string.Format("{0:0.00}", end.Y); string z = string.Format("{0:0.00}", end.Z); string text = x + "," + y + "," + z; addBox(start); addBox(end); add3DText(end, text); }
public Planet3D() { Satellites = new List<Satellite3D>(); orbit = new TubeVisual3D() {Diameter=0.8, ThetaDiv = 16 }; orbit.Material = MaterialHelper.CreateMaterial(null,Brushes.Blue,Brushes.Gray,0.5, 20); Children.Add(orbit); }
public Element() { Tube = new TubeVisual3D(); Tube.Path = new Point3DCollection(); Tube.Path.Add(new Point3D(-15, 0, 0)); Tube.Path.Add(new Point3D(15, 0, 0)); Tube.Diameter = tubeDiameter; Tube.IsSectionClosed = true; Tube.Fill = new SolidColorBrush(Colors.Silver); Tube.IsPathClosed = false; Sphere = new CubeVisual3D(); //Sphere.Center = new Point3D(15, 0, 0); Sphere.Fill = new SolidColorBrush(Colors.Silver); Sphere.SideLength = 0.75; }
void contours(Brush b) { model = new Wire(); model.Brace1 = brace1.Model; model.Brace2 = brace2.Model; Point3D c1 = brace1.centroid(); Point3D c2 = brace2.centroid(); /* int n = 6; // Create the data to be fitted float[] x = new float[n]; float[] y = new float[n]; Random rand = new Random(1); float xf = (float)(c2.X - c1.X)/n; float yf = (float)(c2.Y - c1.Y) / n; for (int i = 0; i < n; i++) { x[i] = (float) c1.X + (i * xf); y[i] = (float) c1.Y + (i * yf); } int upsampleFactor = 10; int nInterpolated = n * upsampleFactor; float[] xs = new float[nInterpolated]; for (int i = 0; i < nInterpolated; i++) { xs[i] = (float)i * (n - 1) / (float)(nInterpolated - 1); } CubicSpline spline = new CubicSpline(); float[] ys = spline.FitAndEval(x, y, xs, true); */ Point3DCollection contours = new Point3DCollection(); contours.Add(brace1.ToWorld(c1)); /*for (int i = 0; i < xs.Length; i++) { contours.Add(new Point3D(xs[i], ys[i], c1.Z)); }*/ contours.Add(brace2.ToWorld(c2)); this.Children.Clear(); TubeVisual3D tube = new TubeVisual3D { Diameter = 1.02, Path = contours, Fill = b }; this.Children.Add(tube); }
public FlightVisual3D(Point3D p1, Point3D p2) { var tube = new TubeVisual3D(); // tube.Material = MaterialHelper.CreateMaterial(Color.FromArgb(80, 255, 255, 255)); // Materials.Yellow; tube.Fill = new SolidColorBrush(Color.FromArgb(80, 255, 255, 255)); Children.Add(tube); Children.Add(new SphereVisual3D() { Center = p1, Radius = 100, Material = Materials.Green }); Children.Add(new SphereVisual3D() { Center = p2, Radius = 100, Material = Materials.Red }); double lat1, lon1, lat2, lon2; PointToLatLon(p1, out lat1, out lon1); PointToLatLon(p2, out lat2, out lon2); From = String.Format("{0:0.00} {1:0.00}", lat1, lon1); To = String.Format("{0:0.00} {1:0.00}", lat2, lon2); CruisingSpeed = DefaultCruisingSpeed; double cruisingRadius = EarthRadius + DefaultCruisingAltitude; double takeoffLength = DefaultTakeoffLength; double groundRadius = EarthRadius; const double tubeDiameter = 60; var o = new Point3D(0, 0, 0); var v1 = p1 - o; var v2 = p2 - o; var z = Vector3D.CrossProduct(v1, v2); var x = v1; var y = Vector3D.CrossProduct(x, z); x.Normalize(); y.Normalize(); double v2X = Vector3D.DotProduct(v2, x); double v2Y = Vector3D.DotProduct(v2, y); double v2A = Math.Atan2(v2Y, v2X); const int n = 100; var pts = new Point3DCollection(); double da = v2A / (n - 1); double distance = cruisingRadius * Math.Abs(v2A); double landingLength = takeoffLength; double l = 0; for (int i = 0; i < n; i++) { double a = i * da; Vector3D v = x * Math.Cos(a) + y * Math.Sin(a); double r = cruisingRadius; //if (l < takeoffLength) //{ // r = groundRadius + Math.Sin(Math.PI/2*l/takeoffLength)*(cruisingRadius - groundRadius); //} //if (l > distance - landingLength) //{ // r = groundRadius + Math.Sin(Math.PI/2*(distance - l)/takeoffLength)*(cruisingRadius - groundRadius); //} r = groundRadius + Math.Sin(Math.PI * i / (n - 1)) * (cruisingRadius - groundRadius); var p = o + v * r; // Children.Add(new SphereVisual3D() { Center = p, Radius = 60, Material = Materials.Gray}); pts.Add(p); l += Math.Abs(cruisingRadius * da); } tube.Diameter = tubeDiameter; tube.ThetaDiv = 16; tube.Path = pts; Distance = distance; }
public void drawBorderEdges(MeshGeometry3D mesh) { Int32Collection edges = MeshGeometryHelper.FindBorderEdges(mesh); Point3DCollection pos = mesh.Positions; for (int i = 1; i < edges.Count; i += 2) { Point3DCollection paths = new Point3DCollection(); paths.Add(pos[edges[i - 1]]); paths.Add(pos[edges[i]]); TubeVisual3D t = new TubeVisual3D { Diameter = 0.02, Path = paths, Fill = Brushes.Yellow }; //t.Transform = new TranslateTransform3D(1, 1, 1); this.Children.Add(t); } }
public JawVisual3D(Point3D p1, Point3D p2) { LineGeometry myLineGeometry = new LineGeometry(); var tube = new TubeVisual3D(); tube.Material = Materials.Blue; tube.Fill = new SolidColorBrush(Color.FromArgb(80, 0, 0, 0)); Children.Add(tube); Children.Add(new SphereVisual3D() { Center = p1, Radius = 0.07, Material = Materials.Red }); Children.Add(new SphereVisual3D() { Center = p2, Radius = 0.07, Material = Materials.Green }); //Point3DCollection pts = new Point3DCollection(); //pts.Add(p1); //pts.Add(p2); //LinesVisual3D ln = new LinesVisual3D(); //ln.Points = pts; //ln.Color = Colors.Black; //Children.Add(ln); //added by achie CruisingSpeed = DefaultCruisingSpeed; double cruisingRadius = EarthRadius + DefaultCruisingAltitude; double takeoffLength = DefaultTakeoffLength; double groundRadius = EarthRadius; var o = new Point3D(0, 0, 0); var v1 = p1 - o; var v2 = p2 - o; var z = Vector3D.CrossProduct(v1, v2); var x = v1; var y = Vector3D.CrossProduct(x, z); x.Normalize(); y.Normalize(); double v2X = Vector3D.DotProduct(v2, x); double v2Y = Vector3D.DotProduct(v2, y); double v2A = Math.Atan2(v2Y, v2X); const int n = 100; var pts = new Point3DCollection(); double da = v2A / (n - 1); double distance = cruisingRadius * Math.Abs(v2A); double landingLength = takeoffLength; double l = 0; for (int i = 0; i < n; i++) { double a = i * da; Vector3D v = x * Math.Cos(a) + y * Math.Sin(a); double r = cruisingRadius; r = groundRadius + Math.Sin(Math.PI * i / (n - 1)) * (cruisingRadius - groundRadius); var p = o + v * r; // Children.Add(new SphereVisual3D() { Center = p, Radius = 60, Material = Materials.Gray}); pts.Add(p); l += Math.Abs(cruisingRadius * da); } Distance = distance; }
public static void drawSnakes(ModelVisual3D container) { container.Children.Clear(); TubeVisual3D snake = new TubeVisual3D { Diameter = 2.00, Path = snakes, Fill = Brushes.LightGoldenrodYellow }; container.Children.Add(snake); }
/* watch = new Stopwatch(); watch.Start(); world = new World(new CollisionSystemSAP()); world.Gravity = new JVector(0, 0, 0); world.CollisionSystem.CollisionDetected += new CollisionDetectedHandler(CollisionSystem_CollisionDetected); //tester(); integratorThread = new Thread(IntegrationWorker); integratorThread.Start(); this.Closing += MainWindow_Closing; } void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { watch.Stop(); integratorThread.Abort(); } private void IntegrationWorker() { while (true) { watch.Restart(); float step = 1.0f / 65; if (step > 1.0f / 100.0f) step = 1.0f / 100.0f; world.Step(step, true); } } void CollisionSystem_CollisionDetected(RigidBody body1, RigidBody body2, JVector point1, JVector point2, JVector normal, float penetration) { Console.WriteLine("CollisionSystem_CollisionDetected"); } */ private void tester() { /* Wiring Brace */ Point3D p0 = new Point3D(-0.849706889491251, -3.41818201148931, -3.45752298819413); Point3D p1 = new Point3D(7.65467623338951, -2.94937570295315, -1.60678487891435); Point3DCollection contours = new Point3DCollection(); contours.Add(p0); contours.Add(p1); BoxVisual3D b = new BoxVisual3D(); b.Center = p0; b.Length = 2; b.Height = 2; b.Width = 2; view1.Children.Add(b); BoxVisual3D b1 = new BoxVisual3D(); b1.Center = p1; b1.Length = 2; b1.Height = 2; b1.Width = 2; view1.Children.Add(b1); TubeVisual3D tube = new TubeVisual3D { Diameter = 1.02, Path = contours, Fill = Brushes.Green }; view1.Children.Add(tube); //Point3D pp = new Point3D(0, 0, 0); //Vector3D mv = Point3D.Subtract(p0, pp); // view1.Children.Add(new RectangleVisual3D { Origin = p0, Normal = mv, Fill = new SolidColorBrush(Color.FromArgb(190, 255, 0, 0)), BackMaterial = MaterialHelper.CreateMaterial(new SolidColorBrush(Colors.Green)) }); //view1.Children.Add(new RectangleVisual3D { Origin = pp, Normal = mv, Fill = new SolidColorBrush(Color.FromArgb(190, 255, 0, 0)), BackMaterial = MaterialHelper.CreateMaterial(new SolidColorBrush(Colors.AliceBlue)) }); /* Normal Vector Directions Point3D p0 = new Point3D(-0.849706889491251,-3.41818201148931,-3.45752298819413); Point3D p1 = new Point3D(7.65467623338951,-2.94937570295315,-1.60678487891435); Point3D p2 = new Point3D(3.58212516465058, 3.19543635742251, -4.13603328982721); BoxVisual3D b = new BoxVisual3D(); b.Center = p0; b.Length = 2; b.Height = 2; b.Width = 2; view1.Children.Add(b); BoxVisual3D b1 = new BoxVisual3D(); b1.Center = p1; b1.Length = 2; b1.Height = 2; b1.Width = 2; view1.Children.Add(b1); BoxVisual3D b2 = new BoxVisual3D(); b2.Center = p2; b2.Length = 2; b2.Height = 2; b2.Width = 2; view1.Children.Add(b2); Vector3D n0 = Point3D.Subtract(p0, p1); n0.Negate(); view1.Children.Add(new RectangleVisual3D { Origin = p0, Normal = n0, Fill = new SolidColorBrush(Color.FromArgb(80, 255, 0, 0)), BackMaterial = MaterialHelper.CreateMaterial(new SolidColorBrush(Colors.Green)) }); Vector3D n1 = Point3D.Subtract(p1, p0); n1.Negate(); view1.Children.Add(new RectangleVisual3D { Origin = p1, Normal = n1, Fill = new SolidColorBrush(Color.FromArgb(100, 255, 0, 0)), BackMaterial = MaterialHelper.CreateMaterial(new SolidColorBrush(Colors.Green)) }); Point3D m = new Point3D(); m.X = (p1.X + p0.X)/2; m.Y = (p1.Y + p0.Y)/2; m.Z = (p1.Z + p0.Z)/2; BoxVisual3D b3 = new BoxVisual3D(); b3.Center = m; b3.Length = 1; b3.Height = 1; b3.Width = 1; view1.Children.Add(b3); Point3D pp = new Point3D(0, 0, 0); Vector3D mv = Point3D.Subtract(p0, pp); view1.Children.Add(new RectangleVisual3D { Origin = pp, Normal = mv, Fill = new SolidColorBrush(Color.FromArgb(190, 255, 0, 0)), BackMaterial = MaterialHelper.CreateMaterial(new SolidColorBrush(Colors.Green)) }); Vector3D n2 = Point3D.Subtract(p2, m); n2.Negate(); view1.Children.Add(new RectangleVisual3D { Origin = p2, Normal = n2, Fill = new SolidColorBrush(Color.FromArgb(190, 255, 0, 0)), BackMaterial = MaterialHelper.CreateMaterial(new SolidColorBrush(Colors.Green)) }); //Vector3D n = CalculateNormal(ref p0, ref p1, ref p2); //view1.Children.Add(new RectangleVisual3D { Origin = p1, Normal = n, Fill = new SolidColorBrush(Color.FromArgb(190, 255, 0, 0)), BackMaterial = MaterialHelper.CreateMaterial(new SolidColorBrush(Colors.Green)) }); */ /* Cutting Plane var mb = new MeshBuilder(); mb.AddSphere(new Point3D(-2, 0, 0), 2); var mesh = mb.ToMesh(); var n = new Vector3D(0, 0.2, 1); var p = new Point3D(0, 0, 0.5); var geo = MeshGeometryHelper.Cut(mesh, p, n); var m = new GeometryModel3D(geo, Materials.Blue); m.BackMaterial = Materials.Red; var mv = new ModelVisual3D(); mv.Content = m; view1.Children.Add(mv); var mbx = new MeshBuilder(); mbx.AddSphere(new Point3D(2, 0, 0), 1); var mvd = new ModelVisual3D(); GeometryModel3D g = new GeometryModel3D(mbx.ToMesh(), Materials.Blue); mvd.Content = g; view1.Children.Add(mvd); var segments = MeshGeometryHelper.GetContourSegments(mesh, p, n).ToList(); foreach (IList<Point3D> contour in MeshGeometryHelper.CombineSegments(segments, 1e-6).ToList()) { if (contour.Count == 0) continue; Point3DCollection contours = new Point3DCollection(contour); view1.Children.Add(new TubeVisual3D { Diameter = 0.02, Path = contours, Fill = Brushes.Green }); } view1.Children.Add(new RectangleVisual3D { Origin = p, Normal = n, Fill = new SolidColorBrush(Color.FromArgb(80, 255, 0, 0)) }); */ /* g = new SmileVisual3D(); GeometryModel3D geo1 = GeometryGenerator.CreateCubeModel(); geo1.Material = new DiffuseMaterial(new SolidColorBrush(Colors.Red)); Transform3DGroup transformGroup = new Transform3DGroup(); transformGroup.Children.Add(new ScaleTransform3D(2, 2, 2)); g.Transform = transformGroup; g.Content =geo1; view1.Children.Add(g); CombinedManipulator c = new CombinedManipulator(); //c.Diameter = 5; c.Bind(g); view1.Children.Add(c); */ /* List<Point3d> pointList = // list of candidate points Point3d bp = // point used to select nearest point in pointList // Because the same source element can be passed // to the function given to Aggregate() many times, // we cache each point along with the result of calling // DistanceTo() in an anonymous type, allowing us to // avoid redundant calls to DistanceTo(): var items = pointList.Select( p => new{ point = p, dist = p.DistanceTo( bp ) } ); // Find the nearest point: Point3d nearest = items.Aggregate( ( a, b ) => a.dist < b.dist ? a : b ).point; */ }