jw_cad 外部変形 - (503) javaで点を打つ -

外部変形は データのやり取りをテキストファイルで行うので プログラム言語は 自由に選ぶことができます。図形は機能的かつシンプルなため、数多くのユーザーに受け入れられています。

 

javaで(線の両端に)点を打つ

:javaで点を打つ
@echo off
if not exist %~dp0PointDraw.class (
  for /f "delims=:" %%n in ('findstr /n "^#!" %0') do (
    more +%%n %0 > %~dpn0.java
    javac -encoding shift_jis %~dpn0.java
  )
)
copy jwc_temp.txt myfiles > nul
java -classpath %~dp0 PointDraw > jwc_temp.txt
goto:eof

REM #jww
REM #1ln 基準線を指示してください
REM #e

#!この次の行からプログラムを書いてください
import java.io.*;
import java.util.regex.Pattern;

class PointDraw {
  public static void main(String args) {
    try {
      BufferedReader f = new BufferedReader(new FileReader("myfiles"));
      String line;
      int i = 1;
      String
ln = new String[10][4];
      while ( (line = f.readLine() ) != null) {
        if (Pattern.compile("^ ").matcher(line).find()) {
          String
p = line.trim().split(" ");
          if (p.length == 4) {
            ln[i++] = p;
          }
        }
      }
      f.close();
      double x1, y1, x2, y2;
      x1 = Double.parseDouble(ln[1][0]);
      y1 = Double.parseDouble(ln[1][1]);
      x2 = Double.parseDouble(ln[1][2]);
      y2 = Double.parseDouble(ln[1][3]);
      System.out.printf("pt %.15f %.15f%n", x1, y1);
      System.out.printf("pt %.15f %.15f%n", x2, y2);
    } catch (IOException e) {
      System.out.println(e);
    }
  }
}