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

Posted at

概要

windows11に、sketchup6を入れてみた。
rubyで、3Dを書く。
練習問題、やってみた。

練習問題

カプセルを描く、RUBYスクリプトを書け。

写真

image.png

サンプルコード


def latheShape(rad, segs, edges)
	faces = []
	inc = 360.0 / segs
	0.step(360.0, inc) { |r|
		for e in edges
			t1 = Geom::Transformation.new(ORIGIN, Z_AXIS, r.degrees)
			t2 = Geom::Transformation.new(ORIGIN, Z_AXIS, (r + inc).degrees)
			pa = [e.vertices[0].position.transform!(t1), e.vertices[1].position.transform!(t1), e.vertices[1].position.transform!(t2), e.vertices[0].position.transform!(t2)]
			#puts f
			pa.uniq!
			faces.push(pa)
		end
	}
	return (faces)
end



def create_capsule(rad, hei, segs)
	grp = Sketchup.active_model.active_entities.add_group()
	ents = grp.entities
	arc1 = ents.add_arc([0, 0, rad], [1, 0, 0], [0, 1, 0], rad, 0.degrees, 90.degrees)
	arc2 = ents.add_arc([0, 0, hei - rad], [1, 0, 0], [0, 1, 0], rad, 270.degrees, 360.degrees)
	line1 = ents.add_line(arc1[0].vertices[0], arc2[arc2.length - 1].vertices[1])
	edges = arc1 + arc2 + [line1]
	faces = latheShape(rad, segs, edges)
	for face in faces
		begin
			f = ents.add_face(face)
		rescue
			face.delete_at(1)
			f = ents.add_face(face)
		end
		f.edges.each { |edge|
			edge.smooth = true;
			edge.hidden = true
		}
	end
	grp.name = "capsule"
	return(grp)
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?