jw_cad 外部変形 - (689) パワーシェルでソリッド図形の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
  $p =(0,
      ( ($tw/2)   ,($a/2-$tf-$r*0)),
      ( ($tw/2+$r),($a/2-$tf-$r)),
      ( ($tw/2+$r),($a/2-$tf)),
      ( ($b/2)  ,($a/2-$tf)),
      ( ($b/2)  ,($a/2)),0,0,0,0,0,0,0,0,0,0,
                        0,0,0,0,0,0
      )
  $v = 5
  for ($j = 2; $j -le 4; $j++)
  {
    for ($i = 1; $i -le $v; $i++)
    {
      $x,$y = $p[$i+($j-2)*$v]
      $p[$j*$v-$i+1] = ($x*[math]::pow(-1,$j-1)),($y*[math]::pow(-1,$j))
    }
  }
  $p[0] = $p[20]

  $red,$green,$blue = 0,128,128
  "lc10 $($red+$green*256+$blue*256*256)"

  "pl"
  for ($i = 0; $i -le 20; $i++)
  {
    $arc = 1
    $pp = ptrot ($hk*[math]::PI/180) $p[$i] $p0
    if ($i%10 -eq 2)
    {
      $d = ($v%4)*90
      $v -= 1
    }
    else
    {
      if ($i%10 -eq 9)
      {
        $d = ($v%4)*90
        $v -= 1
      }
      else
      {
        $arc = 0
      }
    }
    $x,$y = $pp
    if ($arc -eq 1)
    {
      "sc $x $y $r 1 $($hk*[math]::PI/180) $($d*[math]::PI/180) $([math]::PI/2) -1"
    }
    $p[$i] = $pp
  }
  "sl $([string]::join(' ',$p[1]+$p[10]+$p[11]+$p[20]))"
  "sl $([string]::join(' ',$p[4]+$p[5]+$p[6]+$p[7]))"
  "sl $([string]::join(' ',$p[14]+$p[15]+$p[16]+$p[17]))"
  "#"
}
gc jwc_temp.txt | %{
  switch -regex -case ($_)
  {
    '^hk (.+)' { $hk = [double] $matches[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 は 文末に必ず空白行を置いてください