jw_cad 外部変形 - (448) コマンドプロンプトで円を描く -

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

 

コマンドプロンプトWindowsを操作あるいは設定するスクリプトツールです。

 

円を描く(1)

gcc を併用する

:円を描く(1)
@echo off
if not exist %~dp0ci.exe (
  for /f "delims=:" %%n in ('findstr /n "^#!" %0') do (
    more +%%n %0 > %~dp0ci.c
    gcc %~dp0ci.c -o %~dp0ci.exe -s
  )
)
for /f "tokens=1*" %%1 in (jwc_temp.txt) do (
  if %%1 == hp1- set p1=%%2
  if %%1 == hp2  set p2=%%2
)
%~dp0ci %p1% %p2% > jwc_temp.txt
goto:eof

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

#!gcc
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double ptdist(double *p1, double *p2)
{
  return sqrt(pow(p2[0] - p1[0], 2) + pow(p2[1] - p1[1], 2));
}
int main(int argc, char *argv)
{
  if (argc > 4) {
    double p1
= {atof(argv[1]), atof(argv[2])};
    double p2[] = {atof(argv[3]), atof(argv[4])};
    printf("ci %.15g %.15g %.15g\n", p1[0], p1[1], ptdist(p1, p2));
  } else {
    printf("%d\n", 0);
  }
  return 0;
}

 

円を描く(2)

jscript を併用する

@if(0==1) //円を描く(2)
@echo off
for /f "tokens=1*" %%i in (jwc_temp.txt) do (
  if %%i == hp1- set p1=%%j
  if %%i == hp2  set p2=%%j
)
cscript //nologo //e:jscript %~f0 %p1% %p2% > jwc_temp.txt
goto:eof

REM #jww
REM #1-%d 円の中心を指示してください (L)free (R)Read
REM #2%d 円周上の点を指示してください (L)free (R)Read
REM #e
@end

with( WScript ){
  F = arguments
  dx = F(2) - (x = F(0))
  dy = F(3) - (y = F(1))
  echo("ci", x, y, Math.sqrt(dx * dx + dy * dy))
}

 

円を描く(3)

jscript を使う

@if(0==1) //円を描く(3)
@echo off
copy jwc_temp.txt myfiles > nul
cscript //nologo //e:jscript %0 < myfiles > jwc_temp.txt
goto:eof

REM #jww
REM #1-%d 円の中心を指示してください (L)free (R)Read
REM #2%d 円周上の点を指示してください (L)free (R)Read
REM #e
@end

f = WScript.StdIn
while (! f.AtEndOfStream) {
  $F = ($_ = f.ReadLine()).split(/\s+/)
  if (/^hp1-/i .test($_)) p1 = $F.slice(1, 3)
  if (/^hp2 /i .test($_)) p2 = $F.slice(1, 3)
}
with (Math) {
  x1 = p1[0] * 1.0; y1 = p1[1] * 1.0
  x2 = p2[0] * 1.0; y2 = p2[1] * 1.0
  x = (x1 + x2) / 2
  y = (y1 + y2) / 2
  r = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)) / 2
}
g = WScript.StdOut
g.WriteLine(["ci", x, y, r].join(" "))

 

 

コマンドプロンプトは実数計算ができないので gcc や jscript を利用しました。

 

参考までに jw.rb なら

:円を描く(jw.rb)

@echo off

ruby -x %0

goto:eof

 

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

 

#!ruby -Ks -rjw

jww

plot ci hp 1, 2

__END__