jw_cad 外部変形 - (502) javaで円を描く -

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

 

javaで円を描く

:javaで円を描く
@echo off
if not exist %~dp0CircleDraw.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 CircleDraw > jwc_temp.txt
goto:eof

REM #jww
REM #1-%d 円の中心を指示してください
REM #2%d 円周上の点を指示してください
REM #e

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

class CircleDraw {
  public static void main(String args) {
    try {
      BufferedReader f = new BufferedReader(new FileReader("myfiles"));
      String line;
      int i = 0;
      String
hp = new String[10];
      while ( (line = f.readLine() ) != null) {
        if (Pattern.compile("^hp[1-9][0-9]*").matcher(line).find()) {
          String str = line.split(" ", 2);
          i = Integer.parseInt(str[0].replaceAll("^hp|-$", ""));
          hp[i] = str[1].trim();
        }
      }
      f.close();
      double x1, y1, x2, y2, r;
      String
p = hp[1].split(" ");
      x1 = Double.parseDouble(p[0]);
      y1 = Double.parseDouble(p[1]);
      String[] q = hp[2].split(" ");
      x2 = Double.parseDouble(q[0]);
      y2 = Double.parseDouble(q[1]);
      r = Math.hypot(x2 - x1, y2 - y1);
      System.out.printf("ci %s %.15f%n", hp[1], r);
    } catch (IOException e) {
      System.out.println(e);
    }
  }
}