package com.zy.asrs.utils; import com.core.common.Arith; import com.core.common.Cools; import com.zy.core.properties.SlaveProperties; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; /** * Created by vincent on 2020/8/27 */ public class Utils { private static final DecimalFormat fmt = new DecimalFormat("##0.00"); public static float scale(Float f){ if (f == null || f == 0f || Float.isNaN(f)) { return 0f; } return (float) Arith.multiplys(2, f, 1); } public static String zerofill(String msg, Integer count){ if (msg.length() == count){ return msg; } else if (msg.length() > count){ return msg.substring(0, 16); } else { StringBuilder msgBuilder = new StringBuilder(msg); for (int i = 0; i= start && b <= end) { double t = (b - start) / (end - start); // 根据不同类型计算坐标 switch (type) { case 0: // 直线 return linearInterpolation(interval, t); case 1: // 贝塞尔曲线 return bezierInterpolation(interval, t); case 2: // 圆弧 return circularInterpolation(interval, t); } } } return new double[]{0, 0}; } // 直线插值 private static double[] linearInterpolation(Object[] interval, double t) { double x1 = (Double) interval[3]; double y1 = (Double) interval[4]; double x2 = (Double) interval[5]; double y2 = (Double) interval[6]; return new double[]{ x1 + t * (x2 - x1), y1 + t * (y2 - y1) }; } // 贝塞尔曲线插值 private static double[] bezierInterpolation(Object[] interval, double t) { double x0 = (Double) interval[3]; double y0 = (Double) interval[4]; double x2 = (Double) interval[5]; double y2 = (Double) interval[6]; double cx = (Double) interval[7]; double cy = (Double) interval[8]; return new double[]{ Math.pow(1-t, 2)*x0 + 2*(1-t)*t*cx + t*t*x2, Math.pow(1-t, 2)*y0 + 2*(1-t)*t*cy + t*t*y2 }; } // 圆弧插值(新增) private static double[] circularInterpolation(Object[] interval, double t) { // 参数解析 double startX = (Double) interval[3]; double startY = (Double) interval[4]; double endX = (Double) interval[5]; double endY = (Double) interval[6]; double centerX = (Double) interval[7]; double centerY = (Double) interval[8]; // 计算起始角度和终止角度 double startAngle = Math.atan2(startY - centerY, startX - centerX); double endAngle = Math.atan2(endY - centerY, endX - centerX); // 角度插值 double currentAngle = startAngle + t * (endAngle - startAngle); double radius = Math.hypot(startX - centerX, startY - centerY); return new double[]{ centerX + radius * Math.cos(currentAngle), centerY + radius * Math.sin(currentAngle) }; } public static void main(String[] args) { SlaveProperties slaveProperties = new SlaveProperties(); slaveProperties.setDoubleDeep(true); List list = new ArrayList<>(); list.add(1);list.add(4);list.add(5);list.add(8);list.add(9);list.add(12); slaveProperties.setDoubleLocs(list); slaveProperties.setGroupCount(4); Integer deepRow = getDeepRow(slaveProperties, 6); System.out.println(deepRow); } }