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 int getRow(String locNo) {
|
if (!Cools.isEmpty(locNo)) {
|
return Integer.parseInt(locNo.substring(0, 2));
|
}
|
throw new RuntimeException("库位解析异常");
|
}
|
|
/**
|
* 通过库位号获取 排
|
*/
|
public static int getBay(String locNo) {
|
if (!Cools.isEmpty(locNo)) {
|
return Integer.parseInt(locNo.substring(2, 5));
|
}
|
throw new RuntimeException("库位解析异常");
|
}
|
|
/**
|
* 通过库位号获取 排
|
*/
|
public static int getLev(String locNo) {
|
if (!Cools.isEmpty(locNo)) {
|
return Integer.parseInt(locNo.substring(5, 7));
|
}
|
throw new RuntimeException("库位解析异常");
|
}
|
|
public static void main(String[] args) {
|
double[] lev = RingThroughXY(183.0, 1830.0);
|
System.out.printf("点的坐标为: (%.2f, %.2f)%n", lev[0], lev[1]);
|
}
|
|
public static double[] RingThroughXY(double a,double b) {
|
// while (true){
|
// if (b>=a){
|
// b=b-a;
|
// }else {
|
// break;
|
// }
|
// }
|
double l = b/a;
|
// 已知数据
|
double circumference = 314; // 圆周长
|
double arcLength = 314*l; // 给出的弧长
|
|
// 计算圆的半径
|
double radius = circumference / (2 * Math.PI);
|
|
// 圆心坐标
|
double centerX = 50;
|
double centerY = 50;
|
|
// 求弧度
|
double theta = arcLength / radius;
|
|
// 计算点的坐标
|
double x = 100-(centerX + radius * Math.cos(theta));
|
double y = centerY + radius * Math.sin(theta);
|
|
return new double[]{x,y};
|
}
|
|
public static double[] RingThroughXYRgv(double a,double b) {
|
double l = b / a;
|
|
// 圆的已知参数
|
double radius = 47.52; // 半径为48
|
// double circumference = ; // 计算圆周长
|
double arcLength = 2 * Math.PI * radius * l; // 给出的弧长
|
|
// 圆心坐标
|
double centerX = 50;
|
double centerY = 50;
|
|
// 求弧度
|
double theta = arcLength / radius;
|
|
// 计算点的坐标
|
double x = 100-(centerX + radius * Math.cos(theta));
|
double y = centerY + radius * Math.sin(theta);
|
|
return new double[]{x, y};
|
}
|
|
public static double[] RingThroughXYSta(double a,double b) {
|
double l = b / a;
|
|
// 圆的已知参数
|
double radius = 50; // 半径为48
|
// double circumference = ; // 计算圆周长
|
double arcLength = 2 * Math.PI * radius * l; // 给出的弧长
|
|
// 圆心坐标
|
double centerX = 55;
|
double centerY = 45;
|
|
// 求弧度
|
double theta = arcLength / radius;
|
|
// 计算点的坐标
|
double x = 100-(centerX + radius * Math.cos(theta));
|
double y = centerY + radius * Math.sin(theta);
|
|
return new double[]{x, y};
|
}
|
public static double[] getRgvPosNew(Integer devNo,double a, double b) {
|
double[] rgvPosNew = getRgvPosNew(a, b);
|
switch (devNo){
|
case 101:
|
case 102:
|
case 103:
|
case 104:
|
case 105:
|
case 106:
|
case 107:
|
case 108:
|
case 109:
|
case 110:
|
case 111:
|
rgvPosNew[0] = rgvPosNew[0] - 30;
|
rgvPosNew[1] = rgvPosNew[1];
|
break;
|
case 112:
|
case 113:
|
case 114:
|
case 115:
|
rgvPosNew[0] = rgvPosNew[0] + 30;
|
rgvPosNew[1] = rgvPosNew[1];
|
break;
|
case 116:
|
case 117:
|
case 118:
|
case 119:
|
case 120:
|
case 121:
|
case 122:
|
case 123:
|
case 124:
|
case 125:
|
case 126:
|
case 127:
|
case 128:
|
case 129:
|
case 130:
|
case 131:
|
case 132:
|
case 133:
|
rgvPosNew[0] = rgvPosNew[0];
|
rgvPosNew[1] = rgvPosNew[1] + 30;
|
break;
|
case 134:
|
rgvPosNew[0] = rgvPosNew[0];
|
rgvPosNew[1] = rgvPosNew[1] - 30;
|
break;
|
}
|
return rgvPosNew;
|
|
}
|
public static double[] getRgvPosNew(double a, double b) {
|
// 定义区间及对应的几何参数(新增圆弧参数)
|
// 结构:{start, end, 类型, 参数...}
|
// 类型说明:0-直线,1-圆弧(需要圆心坐标)
|
Object[][] intervals = {
|
// 直线区间(0-134400)
|
{0.0, 120000.0, 0, 390.0, 775.0, 25.0, 775.0},
|
// // 弧线区间!!!直线区间!!!
|
{120000.0, 127500.0, 0, 25.0, 775.0, 45.0, 822.0},
|
// 弧线区间!!!直线区间!!!
|
{127500.0, 134900.0, 0, 45.0, 822.0, 65.0, 882.0},
|
// 直线区间
|
{134900.0, 680103.0,0, 65.0, 882.0, 1115.0, 882.0},
|
|
// // 弧线区间(拐点116-115),控制点假设为(1125, 882)
|
// {680103, 731550, 1115, 882, 1215, 775, 1125, 882},
|
|
// 圆弧区间(拐点116-115)新参数:圆心(1115,775)
|
{680103.0, 731550.0, 2, 1115.0, 882.0, 1215.0, 775.0, 1115.0, 775.0}, // 修正终点坐标
|
|
// 直线区间
|
{731550.0, 972950.0,0, 1215.0, 775.0, 1215.0, 125.0},
|
// 弧线区间(拐点112-顶点),控制点假设为(1215, 80)!!!直线区间!!!
|
{972950.0, 1016193.0,0, 1215.0, 125.0, 1164.0, 80.0},
|
// 弧线区间(拐点-顶点-111),控制点假设为(1164, 125)!!!直线区间!!!
|
{1016193.0, 1063563.0,0, 1164.0, 80.0, 1115.0, 125.0},
|
// 直线区间
|
{1063563.0, 1315250.0,0, 1115.0, 150.0, 1115.0, 720.0},
|
// 弧线区间(拐点101-转弯),控制点假设为(1115, 750)
|
{1315250.0, 1322829.0,0, 1115.0, 720.0, 1100.0, 750.0},
|
// 直线区间
|
{1322829.0, 1737000.0,0, 1090.0, 775.0, 390.0, 775.0},
|
};
|
|
for (Object[] interval : intervals) {
|
double start = (Double) interval[0];
|
double end = (Double) interval[1];
|
int type = (Integer) interval[2];
|
|
if (b >= 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)
|
};
|
}
|
|
}
|