jw_cad 外部変形 - (1154) javaでソリッド図形の円環を描く -

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

 

javaでソリッド図形の円環を描く

:javaでソリッド図形の円環を描く
@echo off
if not exist %~dp0CircleSoDraw.class (
  for /f "delims=:" %%n in ('findstr /n "^#!" %0') do (
    more +%%n %0 > %~dpn0.java
    javac -encoding shift_jis %~dpn0.java
  )
)
set c=%*
if defined c call:set %c%
if exist %~dpn0.txt (
  for /f "tokens=*" %%a in (%~dpn0.txt) do call:set %%a
)
if not defined w set w=1
if not defined r2 set r2=0.5
if defined c (
  echo %w% %r2% > %~dpn0.txt
)

set r=0
set g=128
set b=128
set /a rgb=r+256*g+256*256*b

copy jwc_temp.txt myfiles > nul
java -Dfile.encoding=shift_jis -classpath %~dp0 CircleSoDraw > jwc_temp.txt
goto:eof

REM #jww
REM #1-%d 円の中心を指示してください
REM #2%d 円周上の点を指示してください
REM #c 扁平率(0.1~10.0) w, 内円半径比 r2/r =
REM #e

:set
if not defined w set w=%1
if not defined r2 set r2=%2
goto:eof

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

class CircleSoDraw {
  public static void main(String args) {
    double w = Double.parseDouble(System.getenv("w"));
    double r2 = Double.parseDouble(System.getenv("r2"));
    int rgb = Integer.parseInt(System.getenv("rgb"));
    try {
      BufferedReader f = new BufferedReader(new FileReader("myfiles"));
      String line;
      double hk = 0;
      int i = 0;
      String
hp = new String[10];
      while ( (line = f.readLine()) != null) {
        if (Pattern.compile("^hk").matcher(line).find()) {
          String str = line.split(" ", 2);
          hk = Double.parseDouble(str[1].trim());
        }
        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, d;
      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);
      d = hk * Math.PI / 180.0;
      System.out.printf("lc10 %d%n", rgb);
      System.out.printf("so %.15f %.15f %.15f %.15f %.15f %d %.15f %.15f%n", x1, y1, r, w, d, 0, Math.PI * 2, r * r2);
    } catch (IOException e) {
      System.out.println(e);
    }
  }
}