/** * Gets the drawing points. This implementation simply calculates a certain number * of points per curve. * * This is a lsightly different inplementation from the one above. */ public Point3DList GetDrawingPoints1() { Point3DList drawingPoints = new Point3DList(); for (int i = 0; i < controlPoints.Count - 3; i += 3) { Point3D p0 = controlPoints[i]; Point3D p1 = controlPoints[i + 1]; Point3D p2 = controlPoints[i + 2]; Point3D p3 = controlPoints[i + 3]; if (i == 0) //only do this for the first end point. When i != 0, this coincides with the end point of the previous segment, { drawingPoints.Add(CalculateBezierPoint(0, p0, p1, p2, p3)); } for (int j = 1; j <= SEGMENTS_PER_CURVE; j++) { double t = j / (double)SEGMENTS_PER_CURVE; drawingPoints.Add(CalculateBezierPoint(t, p0, p1, p2, p3)); } } return(drawingPoints); }
Point3DList FindDrawingPoints(int curveIndex) { Point3DList pointList = new Point3DList(); Point3D left = CalculateBezierPoint(curveIndex, 0); Point3D right = CalculateBezierPoint(curveIndex, 1); pointList.Add(left); pointList.Add(right); FindDrawingPoints(curveIndex, 0, 1, pointList, 1); return(pointList); }
/// <summary> /// Create a Point3dList from Vector3d List and a color /// </summary> /// <param name="vertices"></param> /// <param name="color"></param> /// <returns></returns> public static Point3DList FromVertices(List <Vector3d> vertices, Color color) { Point3DList ret = new Point3DList(); for (int i = 0; i < vertices.Count; i++) { ret.Add(new Point3D(vertices[i], new Vector3d(0, 1, 0), color)); } return(ret); }
/** * Gets the drawing points. This implementation simply calculates a certain number * of points per curve. */ public Point3DList GetDrawingPoints0() { Point3DList drawingPoints = new Point3DList(); for (int curveIndex = 0; curveIndex < curveCount; curveIndex++) { if (curveIndex == 0) //Only do this for the first end point. //When i != 0, this coincides with the //end point of the previous segment, { drawingPoints.Add(CalculateBezierPoint(curveIndex, 0)); } for (int j = 1; j <= SEGMENTS_PER_CURVE; j++) { double t = j / (double)SEGMENTS_PER_CURVE; drawingPoints.Add(CalculateBezierPoint(curveIndex, t)); } } return(drawingPoints); }
/** * Calculates a Bezier interpolated path for the given points. */ public void Interpolate(Point3DList segmentPoints, double scale) { controlPoints.Clear(); if (segmentPoints.Count < 2) { return; } for (int i = 0; i < segmentPoints.Count; i++) { if (i == 0) // is first { Point3D p1 = segmentPoints[i]; Point3D p2 = segmentPoints[i + 1]; controlPoints.Add(p1); controlPoints.Add(Point3DList.Interpolate(p1, p2, scale)); } else if (i == segmentPoints.Count - 1) //last { Point3D p0 = segmentPoints[i - 1]; Point3D p1 = segmentPoints[i]; controlPoints.Add(Point3DList.Interpolate(p0, p1, scale)); controlPoints.Add(p1); } else { Point3D p0 = segmentPoints[i - 1]; Point3D p1 = segmentPoints[i]; Point3D p2 = segmentPoints[i + 1]; Vector3d tp = (p2.Position - p0.Position).Normalized(); Vector3d pos0 = p1.Position - scale * tp * (p1.Position - p0.Position).Length; Vector3d pos1 = p1.Position + scale * tp * (p2.Position - p1.Position).Length; Vector3d tn = (p2.Normal - p0.Normal).Normalized(); Vector3d norm0 = p1.Normal - scale * tn * (p1.Normal - p0.Normal).Length; Vector3d norm1 = p1.Normal + scale * tn * (p2.Normal - p1.Normal).Length; controlPoints.Add(new Point3D(pos0, norm0, p0.Color.GetStepColor(p1.Color, scale))); controlPoints.Add(p1); controlPoints.Add(new Point3D(pos1, norm1, p1.Color.GetStepColor(p2.Color, scale))); } } curveCount = (controlPoints.Count - 1) / 3; }
/// <summary> /// Get a interpolated list of this list composed od "count" point based on the Y position of another list of points /// </summary> /// <param name="count"></param> /// <returns></returns> public Point3DList GetYInterpolated(Point3DList reflist) { int count = reflist.Count; Point3DList ret = new Point3DList(count); if (count == 0) { return(ret); } for (int i = 0; i < count; i++) { double y = reflist[i].Position.Y; Point3D p = GetInterpolateByY(reflist[i].Position.Y, i == 0); ret.Add(p); } return(ret); }
/// <summary> /// Get a interpolated list of this list composed od "count" point /// </summary> /// <param name="count"></param> /// <returns></returns> public Point3DList GetInterpolatedList(int count) { Point3DList ret = new Point3DList(count); if (count == 0) { return(ret); } else if (count == Count) { ret.AddRange(this); } else { double max = Max.Y; double d = (max - Min.Y) / count; for (int i = 0; i < count; i++) { Point3D p = GetInterpolateByY(max - i * d, i == 0); ret.Add(p); } } return(ret); }