0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

windows11で、sketchup6 その93

Posted at

概要

windows11に、sketchup6を入れてみた。
rubyで、3Dを書く。
式を評価して、グラフを描く、スクリプト見つけたのでやってみた。

写真

image.png

サンプルコード

def graph_3d
	model = Sketchup.active_model
	model.start_operation "k_tools"
	entities = model.active_entities
	group = entities.add_group
	entities = group.entities
	Sketchup::set_status_text("Dessiner une surface 3D sur le plan XY", SB_PROMPT)
	xbeg = -1.0 if not xbeg
	xend = 1.0 if not xend
	stepx = 0.1 if not stepx
	ybeg= -1.0 if not ybeg
	yend= 1.0 if not yend
	stepy = 0.1 if not stepy
	prompts = ["Valeur X mini ", "Valeur X maxi ", "Valeur du pas X ", "Valeur Y mini ", "Valeur Y maxi ", "Valeur du pas Y "]
	values = [xbeg, xend, stepx, ybeg, yend, stepy]
	results = inputbox prompts, values, "Intervalle et resolution"
	xbeg, xend, stepx, ybeg, yend, stepy = results
	formula = "x*y" if not formula
	prompts = ["z = "]
	values = [formula]
	results = inputbox prompts, values, "Formule mathematique"
	formula = results.to_s
	$style = "Facetise" if not $style
	style_list = %w[Grille Triangle_Grille Facetise].join("|")
	dropdowns= [style_list]
	prompts = ["Style: "]
	values = [$style]
	results = inputbox prompts, values, dropdowns, "Visualisation"
	$style = results[0].chomp
	xbeg.step(xend - stepx, stepx) do |i|
	ybeg.step(yend - stepy, stepy) do |j|
	x1 = i
	x = x1
	y1 = j
	y = y1
		begin
			z1 = eval(formula)
		rescue
			z1 = 0
		end
		z1 = 100000000 if z1 > 100000000
		z1 = -100000000 if z1 < -100000000
		x2 = i + stepx
		x = x2
		y2 = j
		y = y2
		begin
			z2 = eval(formula)
		rescue
			z2 = 0
		end
		z2 = 100000000 if z2 > 100000000
		z2 = -100000000 if z2 < -100000000
		x3 = i
		x = x3
		y3 = j + stepy
		y = y3
		begin
			z3 = eval(formula)
		rescue
			z3 = 0
		end
		z3 = 100000000 if z3 > 100000000
		z3 = -100000000 if z3 < -100000000
		x4 = i + stepx
		x = x4
		y4 = j + stepy
		y = y4
		begin
			z4 = eval(formula)
		rescue
			z4 = 0
		end
		z4 = 100000000 if z4 > 100000000
		z4 = -100000000 if z4 < -100000000
		pt1 = [x1.m, y1.m, z1.m]
		pt2 = [x2.m, y2.m, z2.m]
		pt3 = [x3.m, y3.m, z3.m]
		pt4 = [x4.m, y4.m, z4.m]
		if $style == "Facetise" then
			face3d= entities.add_face(pt1, pt2, pt3)
			face3d= entities.add_face(pt2, pt3, pt4)
		else
			polyline3d = entities.add_line(pt1, pt2)
			polyline3d = entities.add_line(pt1, pt3)
			polyline3d = entities.add_line(pt2, pt4)
			polyline3d = entities.add_line(pt3, pt4)
			if $style == "Triangle_Grille" then
				polyline3d = entities.add_line(pt2, pt3)
			end
		end
	end
	end
	view = model.active_view.zoom_extents
	model.commit_operation
end

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?