Jw_cad 情報交換室−その3New

 JWW についての情報交換の場としてお使いください
初心者の方などのご相談は Jw_cad 相談 室−その2をご利用ください
なお、情報交換室と相談室の両方に同じ内容を投稿するのはご遠慮ください

2009年9月以前の発言過去ログのページからご覧ください。

それ以降の過去ログは消失しています。
申し訳ありませんが、復活の予定はありません。


新規投稿 ┃ツリー表示 ┃スレッド表示 ┃一覧表示 ┃トピック表示 ┃番号順表示 ┃検索 ┃設定 ┃過去ログ ┃ホーム
15 / 387 ツリー    ←次へ | 前へ→

外変(網掛けハッチング) momochi 26/3/7(土) 17:09
Re:外変(網掛けハッチング) momochi 26/3/8(日) 19:04

外変(網掛けハッチング)
 momochi  - 26/3/7(土) 17:09 -
外変「circlehatch」(網掛けハッチング)をアップします。 2本の境界線の間に小円(ドット)を配置する外変です。 台形や三角形の境界内にも配置できます。 (Geminiで作成) 境界線1をクリック 境界線2をクリック [選択確定]で実行 興味のある方はどうぞ 【動作しない場合】 コピーしたコードを Gemini や ChatGPT などのAIに貼り付け、次の指示を出してください。直る場合があります。 AIへの指示: 「この Jw_cad 外部変形のスクリプトを Ruby として正しく動作するよう修復してください。HTMLエンティティ(&#39; など)や全角スペースはすべて半角に修正し、文法エラーがない状態にしてください。ロジック(計算内容)は変更しないでください。」 +++++++++++++++++++++++++++++++++++++++++++ circlehatch.bat @echo off setlocal goto EXE REM circle hatch REM #jww REM #cd REM #g0 REM #gn REM #1ln 1st line REM #2ln 2nd line REM #hr REM #e :EXE pushd "%~dp0" >nul set "SCRIPT=%~dp0circlehatch.rb" if exist "C:\Ruby33-x64\bin\ruby.exe" ( "C:\Ruby33-x64\bin\ruby.exe" -Ks "%SCRIPT%" ) else if exist "C:\Ruby32-x64\bin\ruby.exe" ( "C:\Ruby32-x64\bin\ruby.exe" -Ks "%SCRIPT%" ) else if exist "C:\Ruby31-x64\bin\ruby.exe" ( "C:\Ruby31-x64\bin\ruby.exe" -Ks "%SCRIPT%" ) else if exist "C:\Ruby30-x64\bin\ruby.exe" ( "C:\Ruby30-x64\bin\ruby.exe" -Ks "%SCRIPT%" ) else ( ruby -Ks "%SCRIPT%" ) popd >nul endlocal exit /b 0 ++++++++++++++++++++++++++++++++++++++++++++++ circlehatch.rb # encoding: Windows-31J # circlehatch.rb Dir.chdir(File.dirname(__FILE__)) input_file = "jwc_temp.txt" # --- 設定値 --- RADIUS_MM = 0.25 INTERVAL_MM = 2.5 # -------------- scale = 1.0 selected_lines = [] if File.exist?(input_file) src = File.read(input_file, encoding: "Windows-31J") hs_vals = [] group = 0 src.each_line do |line| l = line.strip if l =~ /^hs\s+(.+)/ hs_vals = $1.split.map(&:to_f) elsif l =~ /^lg([0-9a-f])/ group = $1.hex scale = hs_vals[group] if hs_vals && hs_vals[group] elsif l =~ /^[ \t]*(-?\d+\.?\d*)\s+(-?\d+\.?\d*)\s+(-?\d+\.?\d*)\s+(-?\d+\.?\d*)/ selected_lines << [$1.to_f, $2.to_f, $3.to_f, $4.to_f] end end end exit if selected_lines.size < 2 l1, l2 = selected_lines[-2], selected_lines[-1] p1, p2 = [l1[0], l1[1]], [l1[2], l1[3]] p3, p4 = [l2[0], l2[1]], [l2[2], l2[3]] dist_p1_p3 = (p1[0]-p3[0])**2 + (p1[1]-p3[1])**2 dist_p1_p4 = (p1[0]-p4[0])**2 + (p1[1]-p4[1])**2 if dist_p1_p3 < dist_p1_p4 poly = [p1, p2, p4, p3] else poly = [p1, p2, p3, p4] end def inside?(px, py, poly) ins = false; j = poly.size - 1 poly.size.times do |i| if ((poly[i][1] > py) != (poly[j][1] > py)) && (px < (poly[j][0] - poly[i][0]) * (py - poly[i][1]) / (poly[j][1] - poly[i][1]) + poly[i][0]) ins = !ins end j = i end ins end half, step = RADIUS_MM * scale, INTERVAL_MM * scale rad1, rad2 = 45.0 * Math::PI / 180.0, -45.0 * Math::PI / 180.0 u = [Math.cos(rad1) * step, Math.sin(rad1) * step] v = [Math.cos(rad2) * step, Math.sin(rad2) * step] xs, ys = poly.map{|p|p[0]}, poly.map{|p|p[1]} xmin, xmax, ymin, ymax = xs.min, xs.max, ys.min, ys.max cx_mid, cy_mid = (xmin + xmax) / 2.0, (ymin + ymax) / 2.0 num = (Math.sqrt((xmax-xmin)**2 + (ymax-ymin)**2) / step).ceil + 5 File.open(input_file, "w") do |file| file.write "h#circle hatch\n" (-num..num).each do |i| (-num..num).each do |j| px, py = cx_mid + i * u[0] + j * v[0], cy_mid + i * u[1] + j * v[1] # 判定を4点に絞って高速化 pts = [[px, py - half], [px, py + half], [px - half, py], [px + half, py]] if pts.all? { |pt| inside?(pt[0], pt[1], poly) } file.write "ci %.6f %.6f %.6f\n" % [px, py, half] end end end file.write "hr\n" end
引用なし

パスワード


<Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36@sni104-red.in.shared-server.net>
・ツリー全体表示

Re:外変(網掛けハッチング)
 momochi  - 26/3/8(日) 19:04 -
ハッチ範囲の不具合を修正しました。他も何かあるかも知れません。 circlehatch.bat @echo off setlocal goto EXE REM circle hatch REM #jww REM #cd REM #g0 REM #gn REM #1ln 1st line REM #2ln 2nd line REM #hr REM #e :EXE pushd "%~dp0" >nul set "SCRIPT=%~dp0circlehatch.rb" if exist "C:\Ruby34-x64\bin\ruby.exe" ( "C:\Ruby34-x64\bin\ruby.exe" -Ks "%SCRIPT%" ) else if exist "C:\Ruby33-x64\bin\ruby.exe" ( "C:\Ruby33-x64\bin\ruby.exe" -Ks "%SCRIPT%" ) else if exist "C:\Ruby32-x64\bin\ruby.exe" ( "C:\Ruby32-x64\bin\ruby.exe" -Ks "%SCRIPT%" ) else if exist "C:\Ruby31-x64\bin\ruby.exe" ( "C:\Ruby31-x64\bin\ruby.exe" -Ks "%SCRIPT%" ) else if exist "C:\Ruby30-x64\bin\ruby.exe" ( "C:\Ruby30-x64\bin\ruby.exe" -Ks "%SCRIPT%" ) else ( ruby -Ks "%SCRIPT%" ) popd >nul endlocal exit /b 0 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ circlehatch.rb # encoding: Windows-31J Dir.chdir(File.dirname(__FILE__)) input_file = "jwc_temp.txt" RADIUS_MM = 0.25 INTERVAL_MM = 2.5 scale = 1.0 selected_lines = [] if File.exist?(input_file) src = File.read(input_file, encoding: "Windows-31J") hs_vals = [] group = 0 src.each_line do |line| l = line.strip if l =~ /^hs\s+(.+)/ hs_vals = $1.split.map(&:to_f) elsif l =~ /^lg([0-9a-f])/ group = $1.hex scale = hs_vals[group] if hs_vals && hs_vals[group] elsif l =~ /^[ \t]*(-?\d+\.?\d*)\s+(-?\d+\.?\d*)\s+(-?\d+\.?\d*)\s+(-?\d+\.?\d*)/ selected_lines << [$1.to_f, $2.to_f, $3.to_f, $4.to_f] end end end exit if selected_lines.size < 2 l1, l2 = selected_lines[-2], selected_lines[-1] p1, p2 = [l1[0], l1[1]], [l1[2], l1[3]] p3, p4 = [l2[0], l2[1]], [l2[2], l2[3]] v1 = [p2[0] - p1[0], p2[1] - p1[1]] v2 = [p4[0] - p3[0], p4[1] - p3[1]] dot_product = v1[0] * v2[0] + v1[1] * v2[1] p3, p4 = p4, p3 if dot_product < 0 poly = [p1, p2, p4, p3] def inside?(px, py, poly) ins = false; j = poly.size - 1 poly.size.times do |i| if ((poly[i][1] > py) != (poly[j][1] > py)) && (px < (poly[j][0] - poly[i][0]) * (py - poly[i][1]) / (poly[j][1] - poly[i][1]) + poly[i][0]) ins = !ins end j = i end ins end half, step = RADIUS_MM * scale, INTERVAL_MM * scale rad1, rad2 = 45.0 * Math::PI / 180.0, -45.0 * Math::PI / 180.0 u = [Math.cos(rad1) * step, Math.sin(rad1) * step] v = [Math.cos(rad2) * step, Math.sin(rad2) * step] xs, ys = poly.map{|p|p[0]}, poly.map{|p|p[1]} xmin, xmax, ymin, ymax = xs.min, xs.max, ys.min, ys.max cx_mid, cy_mid = (xmin + xmax) / 2.0, (ymin + ymax) / 2.0 num = (Math.sqrt((xmax-xmin)**2 + (ymax-ymin)**2) / step).ceil + 5 File.open(input_file, "w") do |file| file.write "h#circle hatch\n" (-num..num).each do |i| (-num..num).each do |j| px, py = cx_mid + i * u[0] + j * v[0], cy_mid + i * u[1] + j * v[1] pts = [[px, py - half], [px, py + half], [px - half, py], [px + half, py]] if pts.all? { |pt| inside?(pt[0], pt[1], poly) } file.write "ci %.6f %.6f %.6f\n" % [px, py, half] end end end file.write "hr\n" end
引用なし

パスワード


<Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36@sni107-red.in.shared-server.net>
・ツリー全体表示

15 / 387 ツリー    ←次へ | 前へ→
新規投稿 ┃ツリー表示 ┃スレッド表示 ┃一覧表示 ┃トピック表示 ┃番号順表示 ┃検索 ┃設定 ┃過去ログ ┃ホーム
 1640486
ページ:  ┃  記事番号:  

C-BOARD Moyuku v1.03b5
Jw_cad Copyright (C)1997-2021 Jiro Shimizu & Yoshifumi Tanaka