algorithm.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import type { AllPlotI } from "../../interface";
  2. import type { PointArr } from "../../interface";
  3. import { P } from "../../tools";
  4. const curseParams = {
  5. t: 0.3,
  6. };
  7. export const linePlot: AllPlotI = {
  8. version: "1.0.0",
  9. createTime: "2023-2-13",
  10. updateTime: "2023-2-13",
  11. author: "c-lei-en",
  12. algorithm: {
  13. // * 获取弧线坐标
  14. getArcPositions: (
  15. pnt1: PointArr,
  16. pnt2: PointArr,
  17. pnt3: PointArr
  18. ): PointArr[] => {
  19. const center = P.PlotUtils.getCircleCenterOfThreePoints(pnt1, pnt2, pnt3);
  20. const radius = P.PlotUtils.distance(pnt1, center);
  21. const angle1 = P.PlotUtils.getAzimuth(pnt1, center);
  22. const angle2 = P.PlotUtils.getAzimuth(pnt2, center);
  23. let startAngle, endAngle;
  24. if (P.PlotUtils.isClockWise(pnt1, pnt2, pnt3)) {
  25. startAngle = angle2;
  26. endAngle = angle1;
  27. } else {
  28. startAngle = angle1;
  29. endAngle = angle2;
  30. }
  31. return P.PlotUtils.getArcPoints(center, radius, startAngle, endAngle);
  32. },
  33. // * 获取曲线坐标
  34. getCurvePoints: (controlPoints: Array<PointArr>): PointArr[] => {
  35. return P.PlotUtils.getCurvePoints(curseParams.t, controlPoints);
  36. },
  37. },
  38. };