コード例 #1
0
		protected void DrawLine(Point3D point)
		{
			// point was in cube [0..1]x[0..1]x[0..1], we are transforming it 
			// to cube [0..width]x[0..height]x[0..depth]

			Point3D start = point.TransformToBounds(bounds);

			int maxLength = 10 * Math.Max(width, Math.Max(height, depth));
			const int maxIterations = 400;
			Size3D boundsSize = new Size3D(1.0 / width, 1.0 / height, 1.0 / depth);

			Action<double, List<Point3D>> pointTracking = (direction, track) =>
			{
				var position01 = point;
				double length = 0;
				int i = 0;
				do
				{
					var K1 = fieldWrapper.GetVector(position01).DecreaseLength(boundsSize);
					var K2 = fieldWrapper.GetVector(position01 + (K1 / 2)).DecreaseLength(boundsSize);
					var K3 = fieldWrapper.GetVector(position01 + (K2 / 2)).DecreaseLength(boundsSize);
					var K4 = fieldWrapper.GetVector(position01 + K3).DecreaseLength(boundsSize);

					var shift = ((K1 + 2 * K2 + 2 * K3 + K4) / 6);
					if (shift.X.IsNaN() || shift.Y.IsNaN() || shift.Z.IsNaN())
						break;

					var next = position01 + direction * shift;
					Point3D viewportPoint = position01.TransformToBounds(bounds);
					track.Add(viewportPoint);

					position01 = next;
					length += shift.Length;
					i++;
				} while (length < maxLength && i < maxIterations);
			};

			var forwardTrack = new List<Point3D>();
			forwardTrack.Add(start);
			pointTracking(+1, forwardTrack);
			if (forwardTrack.Count > 1)
			{
				var forwardLine = CreatePolyline(forwardTrack, start);
				Children.Add(forwardLine);
			}

			var backwardTrack = new List<Point3D>();
			backwardTrack.Add(start);
			pointTracking(-1, backwardTrack);
			if (backwardTrack.Count > 1)
			{
				var backwardLine = CreatePolyline(backwardTrack, start);
				Children.Add(backwardLine);
			}
		}