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 その94

Posted at

概要

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

写真

image.png

サンプルコード

def graph_3sp
	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 Sphere 3D r = f(p,t)", SB_PROMPT)
	pbeg = 0.0 if not pbeg
	pend = 3.14159265 if not pend
	stepp = 0.314159265 if not stepp
	tbeg = 0.0 if not tbeg
	tend = 6.28318531 if not tend
	stept = 0.314159265 if not stept
	prompts = ["Intervalle p mini", "Intervalle p maxi", "Valeur du pas p", "Intervalle t mini", "Intervalle t maxi", "Valeur du pas t"]
	values = [pbeg, pend, stepp, tbeg, tend, stept]
	results = inputbox prompts, values, "Intervalle et resolution"
	pbeg, pend, stepp, tbeg, tend, stept = results
	formula = "p*t" if not formula
	prompts = ["r = "]
	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
	pbeg.step(pend - stepp, stepp) do |i|
		tbeg.step(tend - stept, stept) do |j|
			p1 = i
			p = p1
			t1 = j
			t = t1
			begin
				r1 = eval(formula)
			rescue
				r1 = 0
			end
			r1 = 100000000 if r1 > 100000000
			r1 = -100000000 if r1 < -100000000
			p2 = i + stepp
			p = p2
			t2 = j
			t = t2
			begin
				r2 = eval(formula)
			rescue
				r2 = 0
			end
			r2 = 100000000 if r2 > 100000000
			r2 = -100000000 if r2 < -100000000
			p3 = i
			p = p3
			t3 = j + stept
			t = t3
			begin
				r3 = eval(formula)
			rescue
				r3 = 0
			end
			r3 = 100000000 if r3 > 100000000
			r3 = -100000000 if r3 < -100000000
			p4 = i + stepp
			p = p4
			t4 = j + stept
			t = t4
			begin
				r4 = eval(formula)
			rescue
				r4 = 0
			end
			r4 = 100000000 if r4 > 100000000
			r4 = -100000000 if r4 < -100000000
			x1 = Math::cos(t1) * r1 * Math::sin(p1)
			y1 = Math::sin(t1) * r1 * Math::sin(p1)
			z1 = Math::cos(p1) * r1
			x2 = Math::cos(t2) * r2 * Math::sin(p2)
			y2 = Math::sin(t2) * r2 * Math::sin(p2)
			z2 = Math::cos(p2) * r2
			x3 = Math::cos(t3) * r3 * Math::sin(p3)
			y3 = Math::sin(t3) * r3 * Math::sin(p3)
			z3 = Math::cos(p3) * r3
			x4 = Math::cos(t4) * r4 * Math::sin(p4)
			y4 = Math::sin(t4) * r4 * Math::sin(p4)
			z4 = Math::cos(p4) * r4
			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
				begin
					face3d = entities.add_face(pt1, pt2, pt3)
				rescue
					begin
						face3d = entities.add_face(pt1, pt3, pt2)
					rescue
					end
				end
				begin
					face3d = entities.add_face(pt2, pt3, pt4)
				rescue
					begin
						face3d = entities.add_face(pt2, pt4, pt3)
					rescue
					end
				end
			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?