public void SetData(float deltaMove, float delay, int loopCount, bool pingPong, bool useAnimationCurve, AnimationCurve animationCurve, CustomCurve customAnimationCurve, OnAnimationCompleteCallback onAnimationCompleteCallback) { mDeltaMove = deltaMove; mDelay = delay; mLoopCount = loopCount == 0 ? 1 : loopCount; mPingPong = pingPong; mAnimationCurve = animationCurve; mCustomAnimationCurve = customAnimationCurve; pState = TweenState.RUNNING; useAnimationCurve = mUseAnimationCurve; pOnAnimationCompleteCallback = onAnimationCompleteCallback; }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); #region Whole Curve string filePath = @"C:\Users\Steeve\source\repos\RateCurve\Utils\ratecurve1.csv"; char sep = ';'; SortedDictionary <double, double> myDictionary = CurveLoader.LoadFromFile(filePath, sep, true); #endregion #region Euribor Rates string euriborRatesPath = @"C:\Users\Steeve\source\repos\RateCurve\Input\Euribor_Rates.csv"; SortedDictionary <double, double> euriborRates = CurveLoader.LoadFromFile(euriborRatesPath, sep, true); #endregion #region Swap Rates string swapRatesPath = @"C:\Users\Steeve\source\repos\RateCurve\Input\ICESwapRateHistoricalRates.csv"; SortedDictionary <double, double> swapRates = CurveLoader.LoadFromFile(swapRatesPath, sep, true); #endregion #region building custom path CustomCurve customCurve = null; try { customCurve = new CustomCurve(euriborRates, swapRates); } catch (Exception ex) { string errMessage = "Error: unable to build custom curve.\n" + ex.Message; MessageBox.Show(errMessage); } #endregion //Application.Run(new RateCurvePlots(myDictionary)); SortedDictionary <double, double> points = customCurve.GetCurvePoints(); Application.Run(new RateCurvePlots(points)); }
public static List <Point3D> GetArcPoints(int index, bool redraw) { int i = 0, j = 0; if (index == 0) { i = 1; } if (index == 1) { j = 1; } int radius = 2 * (int)Math.Sqrt(Math.Pow(Helix3dSim.movePaths[index].ptCurve[i].point.X - Helix3dSim.movePaths[index + i - 1].ptCurve[j].point.X, 2) + Math.Pow(Helix3dSim.movePaths[index].ptCurve[i].point.Y - Helix3dSim.movePaths[index + i - 1].ptCurve[j].point.Y, 2) + Math.Pow(Helix3dSim.movePaths[index].ptCurve[i].point.Z - Helix3dSim.movePaths[index + i - 1].ptCurve[j].point.Z, 2)); if (redraw) { radius = Helix3dSim.movePaths[index].radius; } Point3D pt1 = new Point3D(); if (index == 0) { pt1 = Helix3dSim.movePaths[0].ptCurve[0].point; } else { if (index == 1) { pt1 = Helix3dSim.movePaths[index - 1].ptCurve[1].point; } else { pt1 = Helix3dSim.movePaths[index - 1].ptCurve[0].point; } } Point3D pt3 = new Point3D(); if (index == 0) { pt3 = Helix3dSim.movePaths[0].ptCurve[1].point; } else { pt3 = Helix3dSim.movePaths[index].ptCurve[0].point; } Point3D center = new Point3D(); if (redraw) { center = Helix3dSim.movePaths[index].ptAdjust[0].point; // center of arc } else { if (index > 0) { center = Helix3dSim.movePaths[index - 1].ptAdjust[1].point; } else { Point3D p2 = Helix3dSim.movePaths[0].ptCurve[0].point; p2.X += 300; p2.Y += 300; p2.Z += 300; center = p2; } } Vector3D v1 = new Vector3D(pt1.X, pt1.Y, pt1.Z); Vector3D v2 = new Vector3D(center.X, center.Y, center.Z); Vector3D v3 = new Vector3D(pt3.X, pt3.Y, pt3.Z); Vector3D p2top1 = v1 - v2; Vector3D p2top3 = v3 - v2; Vector3D circle_normal = new Vector3D(); circle_normal = Vector3D.CrossProduct(p2top1, p2top3); circle_normal.Normalize(); Vector3D xy_normal = new Vector3D(0, 0, 1); Vector3D rot_axis = new Vector3D(); if (circle_normal == xy_normal || circle_normal == -xy_normal) { rot_axis = xy_normal; } else { rot_axis = Vector3D.CrossProduct(xy_normal, circle_normal); } rot_axis.Normalize(); double angle; if (circle_normal == xy_normal || circle_normal == -xy_normal) { angle = 0; } else { angle = Vector3D.AngleBetween(xy_normal, circle_normal); } Quaternion rot = new Quaternion(rot_axis, -angle); Matrix3D m = Matrix3D.Identity; m.Rotate(rot); v1 = m.Transform(v1); v2 = m.Transform(v2); v3 = m.Transform(v3); List <Point3D> pt = new List <Point3D>(); Point3D ptTemp = new Point3D(v1.X, v1.Y, v1.Z); pt.Add(ptTemp); ptTemp = new Point3D(v2.X, v2.Y, v2.Z); pt.Add(ptTemp); ptTemp = new Point3D(v3.X, v3.Y, v3.Z); pt.Add(ptTemp); Point cent2D; if (redraw) { cent2D = new Point(pt[1].X, pt[1].Y); } else { cent2D = getCircleCenter(pt[0].X, pt[0].Y, pt[2].X, pt[2].Y, radius); } double r1 = (double)Math.Sqrt((pt[0].X - cent2D.X) * (pt[0].X - cent2D.X) + (pt[0].Y - cent2D.Y) * (pt[0].Y - cent2D.Y)); double r2 = (double)Math.Sqrt((pt[1].X - cent2D.X) * (pt[1].X - cent2D.X) + (pt[1].Y - cent2D.Y) * (pt[1].Y - cent2D.Y)); double r3 = (double)Math.Sqrt((pt[2].X - cent2D.X) * (pt[2].X - cent2D.X) + (pt[2].Y - cent2D.Y) * (pt[2].Y - cent2D.Y)); double fai1 = Math.Atan2((double)(pt[0].Y - cent2D.Y), (double)(pt[0].X - cent2D.X)); double fai3 = Math.Atan2((double)(pt[1].Y - cent2D.Y), (double)(pt[1].X - cent2D.X)); double fai2 = Math.Atan2((double)(pt[2].Y - cent2D.Y), (double)(pt[2].X - cent2D.X)); if (fai1 > fai2) { double temp = fai2; fai2 = fai1; fai1 = temp; } //if (fai1 - fai2 > Math.PI) //{ // double temp1 = fai2; // fai2 = 2 * Math.PI - fai1; // fai1 = temp1; //} List <Point3D> result = new List <Point3D>(); Point3D pp = new Point3D(); pp.Z = pt[0].Z; for (double step = fai1; step <= fai2; step += (double)spacing / (double)r1) { pp.X = cent2D.X + r1 * Math.Cos(step); pp.Y = cent2D.Y + r1 * Math.Sin(step); result.Add(pp); } rot = new Quaternion(rot_axis, angle); m = Matrix3D.Identity; m.Rotate(rot); List <Point3D> ret = new List <Point3D>(); Vector3D vector = new Vector3D(); for (i = 0; i < result.Count; i++) { vector = m.Transform(new Vector3D(result[i].X, result[i].Y, result[i].Z)); pp = new Point3D(vector.X, vector.Y, vector.Z); ret.Add(pp); } vector = m.Transform(new Vector3D(cent2D.X, cent2D.Y, pt[0].Z)); center = new Point3D(vector.X, vector.Y, vector.Z); if (!redraw) { CustomCurve cur = Helix3dSim.movePaths[index]; cur.ptAdjust[0].point = center; cur.radius = radius; Helix3dSim.movePaths[index] = cur; } return(ret); }
public static Point3D getCircleCenter(int index) // if bControl is true, it gets points on circle from given 3 points, else from given 2 points and radius { int radius = Helix3dSim.movePaths[index].radius; radius /= 2; radius += 100; Point3D pt1 = new Point3D(); if (index == 0) { pt1 = Helix3dSim.movePaths[0].ptCurve[0].point; } else { if (index == 1) { pt1 = Helix3dSim.movePaths[index - 1].ptCurve[1].point; } else { pt1 = Helix3dSim.movePaths[index - 1].ptCurve[0].point; } } Point3D pt2 = new Point3D(); if (index == 0) { pt2 = Helix3dSim.movePaths[0].ptCurve[1].point; } else { pt2 = Helix3dSim.movePaths[index].ptCurve[0].point; } Point3D pt3 = new Point3D(); if (index == 0) { pt3.X = (pt1.X + pt2.X) / 2 + 300; pt3.Y = (pt1.Y + pt2.Y) / 2 + 300; pt3.Z = (pt1.Z + pt2.Z) / 2 + 300; } else { string shape = Helix3dSim.movePaths[index - 1].shape; if (shape == "bezier") { pt3 = Helix3dSim.movePaths[index - 1].ptAdjust[1].point; } else if (shape == "segment") { if (index == 1) { pt3 = Helix3dSim.movePaths[index - 1].ptCurve[0].point; } else { pt3 = Helix3dSim.movePaths[index - 2].ptCurve[0].point; } } else if (shape == "arc") { pt3 = Helix3dSim.movePaths[index - 1].ptAdjust[0].point; } } Vector3D v1 = new Vector3D(pt1.X, pt1.Y, pt1.Z); Vector3D v2 = new Vector3D(pt2.X, pt2.Y, pt2.Z); Vector3D v3 = new Vector3D(pt3.X, pt3.Y, pt3.Z); Vector3D p2top1 = v1 - v2; Vector3D p2top3 = v3 - v2; Vector3D circle_normal = new Vector3D(); circle_normal = Vector3D.CrossProduct(p2top1, p2top3); circle_normal.Normalize(); Vector3D xy_normal = new Vector3D(0, 0, 1); Vector3D rot_axis = Vector3D.CrossProduct(xy_normal, circle_normal); rot_axis.Normalize(); double angle = Vector3D.AngleBetween(xy_normal, circle_normal); Quaternion rot = new Quaternion(rot_axis, -angle); Matrix3D m = Matrix3D.Identity; m.Rotate(rot); v1 = m.Transform(v1); v2 = m.Transform(v2); v3 = m.Transform(v3); List <Point3D> pt = new List <Point3D>(); Point3D ptTemp = new Point3D(v1.X, v1.Y, v1.Z); pt.Add(ptTemp); ptTemp = new Point3D(v2.X, v2.Y, v2.Z); pt.Add(ptTemp); ptTemp = new Point3D(v3.X, v3.Y, v3.Z); pt.Add(ptTemp); Point center; center = getCircleCenter(pt[0].X, pt[0].Y, pt[1].X, pt[1].Y, pt[2].X, pt[2].Y); double r1 = (double)Math.Sqrt((pt[0].X - center.X) * (pt[0].X - center.X) + (pt[0].Y - center.Y) * (pt[0].Y - center.Y)); double r2 = (double)Math.Sqrt((pt[1].X - center.X) * (pt[1].X - center.X) + (pt[1].Y - center.Y) * (pt[1].Y - center.Y)); double r3 = (double)Math.Sqrt((pt[2].X - center.X) * (pt[2].X - center.X) + (pt[2].Y - center.Y) * (pt[2].Y - center.Y)); CustomCurve curve = Helix3dSim.movePaths[index]; curve.radius = (int)r1; Helix3dSim.movePaths[index] = curve; rot = new Quaternion(rot_axis, angle); m = Matrix3D.Identity; m.Rotate(rot); List <Point3D> ret = new List <Point3D>(); Vector3D vector = new Vector3D(); vector = m.Transform(new Vector3D(center.X, center.Y, pt[0].Z)); return(new Point3D(vector.X, vector.Y, vector.Z)); }