外部変形は データのやり取りをテキストファイルで行うので プログラム言語は 自由に選ぶことができます。図形は機能的かつシンプルなため、数多くのユーザーに受け入れられています。
javaで矩形に内接する楕円を描く(ov)
:javaで矩形に内接する楕円を描く(ov)
@echo off
if not exist %~dp0OvalDraw.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 -Dfile.encoding=shift_jis -classpath %~dp0 OvalDraw > jwc_temp.txt
goto:eof
REM #jww
REM #1-%d 楕円が内接する矩形の始点を指示してください
REM #2%d 対頂点を指示してください
REM #e
#!この次の行からプログラムを書いてください
import java.io.*;
import java.util.regex.Pattern;
class OvalDraw {
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 x, y, x1, y1, x2, y2, d, co, si, ww, hh, r, w;
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;
r = Math.sqrt(ww * ww) / 2;
w = Math.sqrt( (hh / ww) * (hh / ww));
x = (x1 + x2) / 2;
y = (y1 + y2) / 2;
System.out.printf("ci %f %f %f 0 360 %f %f%n", x, y, r, w, hk);
} catch (IOException e) {
System.out.println(e);
}
}
}