|
@@ -54,40 +54,26 @@ public class LaserMeterToDxfUtil {
|
|
DxfDocWriter dxfDocWriter = new DxfDocWriter();
|
|
DxfDocWriter dxfDocWriter = new DxfDocWriter();
|
|
HashSet<Vector3> pointSet= new HashSet<>();
|
|
HashSet<Vector3> pointSet= new HashSet<>();
|
|
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 透视投影 模拟人眼视角,将三维点投影到二维平面,常用于计算机图形学。公式为:
|
|
|
|
- * x1 = x/z ,y1=y/z
|
|
|
|
- *
|
|
|
|
- * 正交投影 忽略z
|
|
|
|
- */
|
|
|
|
for (Object obj : jsonArray) {
|
|
for (Object obj : jsonArray) {
|
|
JSONObject jsonObject = (JSONObject) (obj);
|
|
JSONObject jsonObject = (JSONObject) (obj);
|
|
JSONArray points = jsonObject.getJSONArray("points");
|
|
JSONArray points = jsonObject.getJSONArray("points");
|
|
- JSONObject point1 = (JSONObject) (points.get(0));
|
|
|
|
- JSONObject point2 = (JSONObject) (points.get(1));
|
|
|
|
- Vector3 point3d1 = new Vector3(point1.getDouble("x"),point1.getDouble("y"),point1.getDouble("z"));
|
|
|
|
- Vector3 point3d2 = new Vector3(point2.getDouble("x"),point2.getDouble("y"),point2.getDouble("z"));
|
|
|
|
-
|
|
|
|
- //Vector3 startPoint = new Vector3((point1.getDouble("x") /point1.getDouble("z")) * 100 ,(point1.getDouble("y")/point1.getDouble("z")) * 100,0);
|
|
|
|
- //Vector3 endPoint = new Vector3((point2.getDouble("x") /point2.getDouble("z")) * 100 ,(point2.getDouble("y")/point2.getDouble("z")) * 100,0);
|
|
|
|
- Vector3 startPoint = new Vector3((point1.getDouble("x") ) * 100 ,(point1.getDouble("y")) * 100,0);
|
|
|
|
- Vector3 endPoint = new Vector3((point2.getDouble("x") ) * 100 ,(point2.getDouble("y")) * 100,0);
|
|
|
|
- pointSet.add(startPoint);
|
|
|
|
- pointSet.add(endPoint);
|
|
|
|
- drawLinePoint(startPoint,endPoint,dxfDocWriter);
|
|
|
|
- BigDecimal bigDecimal = BigDecimal.valueOf(distanceTo(point3d1, point3d2) * 100).setScale(5, RoundingMode.UP);
|
|
|
|
- int d = bigDecimal.divide(new BigDecimal(100),2, RoundingMode.UP).intValue();
|
|
|
|
- DxfText dxfText = new DxfText();
|
|
|
|
- Vector3 vector3 = new Vector3((endPoint.getX() + startPoint.getX()) /2 ,
|
|
|
|
- (endPoint.getY() + startPoint.getY() )/2 ,
|
|
|
|
- 0);
|
|
|
|
- dxfText.setStartPoint(vector3);
|
|
|
|
- dxfText.setText(bigDecimal.toString()+"cm");
|
|
|
|
- dxfText.setAngle(angleBetween(startPoint,endPoint));
|
|
|
|
- dxfText.setHigh(d *2);
|
|
|
|
- dxfText.setColor(new Color(255,255,255));
|
|
|
|
- dxfDocWriter.addEntity(dxfText);
|
|
|
|
|
|
+ String type = jsonObject.getString("type");
|
|
|
|
+ if(type.contains("AREA")){
|
|
|
|
+ for (int i = 0 ;i < points.size();i ++){
|
|
|
|
+ JSONObject point1 = (JSONObject) points.get(i);
|
|
|
|
+ JSONObject point2 = (JSONObject) points.get( i+1 >= points.size()? 0 :i+1 );
|
|
|
|
+ drawLine(point1,point2,pointSet,dxfDocWriter);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ if(type.equals("LINE")){
|
|
|
|
+ JSONObject point1 = (JSONObject) (points.get(0));
|
|
|
|
+ JSONObject point2 = (JSONObject) (points.get(1));
|
|
|
|
+ drawLine(point1,point2,pointSet,dxfDocWriter);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -106,6 +92,35 @@ public class LaserMeterToDxfUtil {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 透视投影 模拟人眼视角,将三维点投影到二维平面,常用于计算机图形学。公式为:
|
|
|
|
+ * x1 = x/z ,y1=y/z
|
|
|
|
+ *
|
|
|
|
+ * 正交投影 忽略z
|
|
|
|
+ */
|
|
|
|
+ public static void drawLine(JSONObject point1, JSONObject point2, HashSet<Vector3> pointSet,DxfDocWriter dxfDocWriter){
|
|
|
|
+ Vector3 point3d1 = new Vector3(point1.getDouble("x"),point1.getDouble("y"),point1.getDouble("z"));
|
|
|
|
+ Vector3 point3d2 = new Vector3(point2.getDouble("x"),point2.getDouble("y"),point2.getDouble("z"));
|
|
|
|
+ Vector3 startPoint = new Vector3((point1.getDouble("x") ) * 100 ,(point1.getDouble("y")) * 100,0);
|
|
|
|
+ Vector3 endPoint = new Vector3((point2.getDouble("x") ) * 100 ,(point2.getDouble("y")) * 100,0);
|
|
|
|
+ pointSet.add(startPoint);
|
|
|
|
+ pointSet.add(endPoint);
|
|
|
|
+ drawLinePoint(startPoint,endPoint,dxfDocWriter);
|
|
|
|
+ BigDecimal bigDecimal = BigDecimal.valueOf(distanceTo(point3d1, point3d2) * 100).setScale(5, RoundingMode.UP);
|
|
|
|
+ int d = bigDecimal.divide(new BigDecimal(100),2, RoundingMode.UP).intValue();
|
|
|
|
+ DxfText dxfText = new DxfText();
|
|
|
|
+ Vector3 vector3 = new Vector3((endPoint.getX() + startPoint.getX()) /2 ,
|
|
|
|
+ (endPoint.getY() + startPoint.getY() )/2 ,
|
|
|
|
+ 0);
|
|
|
|
+ dxfText.setStartPoint(vector3);
|
|
|
|
+ dxfText.setText(bigDecimal.toString()+"cm");
|
|
|
|
+ dxfText.setAngle(angleBetween(startPoint,endPoint));
|
|
|
|
+ dxfText.setHigh(d *2);
|
|
|
|
+ dxfText.setColor(new Color(255,255,255));
|
|
|
|
+ dxfDocWriter.addEntity(dxfText);
|
|
|
|
+ }
|
|
|
|
+
|
|
public static void drawLinePoint(Vector3 point,Vector3 point2,DxfDocWriter dxfDocWriter){
|
|
public static void drawLinePoint(Vector3 point,Vector3 point2,DxfDocWriter dxfDocWriter){
|
|
DxfLine dxfLine = new DxfLine();
|
|
DxfLine dxfLine = new DxfLine();
|
|
dxfLine.setStartPoint(new Vector3(point.getX(), point.getY(), 0));
|
|
dxfLine.setStartPoint(new Vector3(point.getX(), point.getY(), 0));
|
|
@@ -138,7 +153,7 @@ public class LaserMeterToDxfUtil {
|
|
}
|
|
}
|
|
|
|
|
|
public static void main(String[] args) throws Exception{
|
|
public static void main(String[] args) throws Exception{
|
|
- String inPath ="D:\\cad\\work\\111\\3.json";
|
|
|
|
|
|
+ String inPath ="D:\\cad\\work\\111\\6.json";
|
|
String outPath ="D:\\cad\\work\\111\\"+new Date().getTime()+".dxf";
|
|
String outPath ="D:\\cad\\work\\111\\"+new Date().getTime()+".dxf";
|
|
LaserMeterToDxfUtil.toDxf(new File(inPath),outPath);
|
|
LaserMeterToDxfUtil.toDxf(new File(inPath),outPath);
|
|
}
|
|
}
|