外部変形は データのやり取りをテキストファイルで行うので プログラム言語は 自由に選ぶことができます。図形は機能的かつシンプルなため、数多くのユーザーに受け入れられています。
javaで矩形を描く
:javaで矩形を描く
@echo off
if not exist %~dp0RectDraw.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 RectDraw > jwc_temp.txt
goto:eof
REM #jww
REM #1-%d 矩形の始点を指示してください
REM #2%d 対頂点を指示してください
REM #e
#!この次の行からプログラムを書いてください
import java.io.*;
import java.util.regex.Pattern;
class RectDraw {
public static void main(String args) {
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, d, co, si, ww, hh;
String p3, p4;
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]);
d = hk * Math.PI / 180.0;
co = Math.cos(d);
si = Math.sin(d);
ww = (x2 - x1) * co + (y2 - y1) * si;
hh =-(x2 - x1) * si + (y2 - y1) * co;
p3 = String.format("%.15f %.15f", x1 - hh * si, y1 + hh * co);
p4 = String.format("%.15f %.15f", x1 + ww * co, y1 + ww * si);
System.out.printf("%s%n%s%n%s%n%s%n%s%n", hp[1], p3, hp[2], p4, hp[1]);
} catch (IOException e) {
System.out.println(e);
}
}
}