jw_cad 外部変形 - (688) パワーシェルでH形鋼断面を描く -

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

 

パワーシェルでH形鋼断面を描く

:パワーシェルでH形鋼断面を描く
@echo off
set s=%*
if defined s (
  echo ^%*> %~dpn0.txt
) else (
  if exist %~dpn0.txt (
    for /f "tokens=*" %%a in (%~dpn0.txt) do set s=%%a
  )
)
if not defined s set s=400 200 8 13 16
for /f "delims=:" %%n in ('findstr /n "^#!" %0') do (
  more +%%n %0 | powershell -command -
)
goto:eof

REM #jww
REM #0 位置を指示して下さい
REM #c H B T1 T2 R =
REM #e

#!ここから more +n %0 の n 行目:最初の行は 0 行
function int ($x)
{
  [math]::floor([math]::abs($x))*[math]::sign($x)
}
function ptrot ($d,$x,$y)
{
  $co = [math]::cos($d)
  $si = [math]::sin($d)
  $x1,$y1,$x2,$y2 = $x+$y
  return ( ($x1+$x2)*$co-($y1+$y2)*$si),( ($x1+$x2)*$si+($y1+$y2)*$co)
}
function offset ($w,$h,$pt,$opt=5)
{
  $i1 = int ( (9-$pt)/3)
  $i2 = int ( (9-$opt)/3)
  $i = $i1-$i2
  return ($w*( (9-$pt)%3-(9-$opt)%3)/2),($h*$i/2)
}
function jish ($a,$b,$tw,$tf,$r,$pt=5)
{
  $p0 = offset $b $a $pt
  $d = $hk*[math]::PI/180
  $p =(
      ( ($tw/2)   ,($a/2-$tf-$r)),
      ( ($tw/2+$r),($a/2-$tf-$r)),
      ( ($tw/2+$r),($a/2-$tf)),
      ( ($b/2)  ,($a/2-$tf)),
      ( ($b/2)  ,($a/2))
      )
  $u = $v = 5
  for ($j = 0; $j -le 3; $j++)
  {
    for ($i = 0; $i -lt $u; $i++)
    {
      if ($j%2 -eq 0) { $k=$i } else { $k=$u-$i-1 }
      $x,$y = $p[$k]
      if ($j%3 -ne 0) { $px=-$x } else { $px=$x }
      if ($j -gt 1) { $py=-$y } else { $py=$y }
      $pc = ptrot $d ($px,$py) $p0
      if ( ($k -eq 1) -and ($r -gt 0))
      {
        $a = ($v%4)*90
        $pc = "ci",$pc[0],$pc[1],$r,$a,($a+90),1,$hk
        $v -= 1
      }
      "$pc"
    }
  }
  "$(ptrot $d $p[0] $p0)"
}
gc jwc_temp.txt | %{
  switch -regex -case ($_)
  {
    "^hk" {
      $hk = [double] ([regex]::split($_,' +')[1])
    }
  }
}
$s = [string] $env:s
$F = [regex]::split($s,' +')
$a,$b,$t1,$t2,$r = ($F[0..($F.length-1)] | %{ [double] $_ })
jish $a $b $t1 $t2 $r 5 | sc jwc_temp.txt

#ここまで powershell は 文末に必ず空白行を置いてください