public MyBezier(PointCollection points, double curve, int interval, DistanceType distanceType, RadianType radianType, Visibility vertexAndDirectionVisible) { OriginAnchorPoint = points; AnchorPoints = ChoiceAnchorPoint(points, interval); Curve = curve; Interval = interval; DistanceType = distanceType; RadianType = radianType; //ベジェ曲線Path作成 BezierPath = InitializeBezierPath(); //Pathの初期化 BezierPath.Data = MakeBezierPathGeometry(AnchorPoints); //PathのData作成 ToCurve(BezierPath, curve, distanceType, radianType); //制御点座標決定 //方向線Path作成 DirectionLinePath = InitializeDirectionLinePath(vertexAndDirectionVisible); DirectionLinePath.Data = MakeDirectionLinePathGeometry(BezierPath); //頂点Path作成 VertexPath = InitializeVertexPath(vertexAndDirectionVisible); VertexPath.Data = MakeVertexPathGeometry(BezierPath); }
//制御点座標を決めて曲線化 private void ToCurve(Path bezierPath, double curve, DistanceType distanceType, RadianType radianType) { PointCollection segPoints = GetPolyBezierSegmentPoints(bezierPath); for (int i = 1; i < AnchorPoints.Count - 1; i++) { Point beginAnchor = AnchorPoints[i - 1]; Point currentAnchor = AnchorPoints[i]; Point endAnchor = AnchorPoints[i + 1]; //方向線距離 if (radianType == RadianType.RightAngleOfCenter中間の直角) { double beginDistance = 0, endDistance = 0; switch (distanceType) { case DistanceType.Zero0距離: break; case DistanceType.Average平均: (beginDistance, endDistance) = DistanceAverage(beginAnchor, currentAnchor, endAnchor); break; case DistanceType.Separate別々: (beginDistance, endDistance) = DistanceSeparate(beginAnchor, currentAnchor, endAnchor); break; case DistanceType.Shorter短いほう: (beginDistance, endDistance) = DistanceShorter(beginAnchor, currentAnchor, endAnchor); break; case DistanceType.FrontBack前後間: (beginDistance, endDistance) = DistanceFrontAndBackAnchor(beginAnchor, currentAnchor, endAnchor); break; default: break; } //方向線弧度取得 (double bRadian, double eRadian) = GetRadianDirectionLine(beginAnchor, currentAnchor, endAnchor); //(double bRadian, double eRadian) = SharpTest(beginAnchor, currentAnchor, endAnchor); //始点側制御点座標 double xDiff = Math.Cos(bRadian) * beginDistance * curve; double yDiff = Math.Sin(bRadian) * beginDistance * curve; segPoints[i * 3 - 2] = new Point(currentAnchor.X + xDiff, currentAnchor.Y + yDiff); //終点側制御点座標 xDiff = Math.Cos(eRadian) * endDistance * curve; yDiff = Math.Sin(eRadian) * endDistance * curve; segPoints[i * 3] = new Point(currentAnchor.X + xDiff, currentAnchor.Y + yDiff); } else if (radianType == RadianType.Parallel平行) { Point bSide = currentAnchor; Point eSide = currentAnchor; switch (distanceType) { case DistanceType.Zero0距離: break; case DistanceType.Average平均: (bSide, eSide) = ControlPointsAverage(beginAnchor, currentAnchor, endAnchor, curve); break; case DistanceType.Separate別々: (bSide, eSide) = ControlPointsSeparate(beginAnchor, currentAnchor, endAnchor, curve); break; case DistanceType.Shorter短いほう: (bSide, eSide) = ControlPointsShorter(beginAnchor, currentAnchor, endAnchor, curve); break; case DistanceType.FrontBack前後間: (bSide, eSide) = ControlPointsFrontAndBack(beginAnchor, currentAnchor, endAnchor, curve); break; default: break; } segPoints[i * 3 - 2] = bSide; segPoints[i * 3] = eSide; } } }