スキップしてメイン コンテンツに移動

三角錐 底面なし 描画成功 blender 3.4.1 python


blender 3.4.1 python で 底面が半径1の円錐で 底面のない円錐を 冒頭で import math 付け加えて書いて


以下は、Blender 3.4.1でPythonを使用して、半径1の底面を持つ円錐から底面がない円錐を作成する方法の例です。このコードを実行する前に、Blenderで新しいファイルを作成し、Pythonコンソールを開いてください。


import bpy
import math

# 円錐の高さと半径
height = 2.0
radius = 1.0

# 頂点座標を計算する
vertices = []
for i in range(32):
    theta = 2 * math.pi * i / 32
    x = radius * math.cos(theta)
    y = radius * math.sin(theta)
    vertices.append((x, y, 0))
vertices.append((0, 0, height))

# 面を作成する
faces = []
for i in range(32):
    faces.append((i, (i + 1) % 32, 32))

# メッシュを作成する
mesh = bpy.data.meshes.new('Cone')

# メッシュに頂点と面を追加する
mesh.from_pydata(vertices, [], faces)

# メッシュをオブジェクトに変換する
obj = bpy.data.objects.new('Cone', mesh)

# オブジェクトをシーンに追加する
bpy.context.scene.collection.objects.link(obj)





このコードを実行すると、底面が半径1の円錐が作成されます。この円錐の高さと半径は、heightradius変数の値を変更することで調整できます。また、円錐の側面の解像度を変更するには、verticesリストを計算する際に、range関数の引数を調整してください。



円錐の側面の解像度を変更するには、verticesリストを計算する際に、range関数の引数を調整 仕方を詳しく説明して


円錐の側面の解像度を変更するには、円周をどれだけ細かく分割するかを決定することが重要です。解像度が高いほど、円錐の側面がより滑らかになります。ただし、より多くの頂点を使用すると、メッシュがより詳細になり、処理時間が増加するため、適切な値を見つける必要があります。

以下は、側面の解像度をresolution変数で調整する方法の例です。ここでは、resolutionの値を32に設定しています。


import bpy
import math

# 円錐の高さと半径
height = 2.0
radius = 1.0

# 解像度
resolution = 32

# 頂点座標を計算する
vertices = []
for i in range(resolution):
    theta = 2 * math.pi * i / resolution
    x = radius * math.cos(theta)
    y = radius * math.sin(theta)
    vertices.append((x, y, 0))
vertices.append((0, 0, height))

# 面を作成する
faces = []
for i in range(resolution):
    faces.append((i, (i + 1) % resolution, resolution))

# メッシュを作成する
mesh = bpy.data.meshes.new('Cone')

# メッシュに頂点と面を追加する
mesh.from_pydata(vertices, [], faces)

# メッシュをオブジェクトに変換する
obj = bpy.data.objects.new('Cone', mesh)

# オブジェクトをシーンに追加する
bpy.context.scene.collection.objects.link(obj)


ここでは、側面の解像度を調整するために、resolution変数を導入し、その値をrange関数の引数に渡しています。range(resolution)は、resolutionの値に応じて0から31までの範囲を生成し、その値を使用して各頂点の座標を計算しています。また、facesリストを生成する際にも、resolutionの値を使用しています。

したがって、側面の解像度を変更するには、resolution変数の値を調整するだけで済みます。しかし、適切な解像度を見つけるために、いくつかの試行と誤りが必要になるかもしれません。


以下テスト 試み

ああああああああああああああああああああああああああ


最初に作った 底面なしの円錐スクリプトに 3x3の平面を描いて この平面中心には1x1の穴を作って 底面なしの円錐底面円周に 穴が重なる


以下は、Blender 3.4.1のPython APIを使用して、底面なしの円錐に穴のある平面を追加するスクリプトです。このスクリプトは、最初に作成したスクリプトをベースにしています。

import bpy
import math

# 円錐の高さと半径
height = 2.0
radius = 1.0

# 解像度
resolution = 32

# 頂点座標を計算する
vertices = []
for i in range(resolution):
    theta = 2 * math.pi * i / resolution
    x = radius * math.cos(theta)
    y = radius * math.sin(theta)
    vertices.append((x, y, 0))
vertices.append((0, 0, height))

# 面を作成する
faces = []
for i in range(resolution):
    faces.append((i, (i + 1) % resolution, resolution))

# 平面を作成する
bpy.ops.mesh.primitive_plane_add(size=3)

# 平面を移動する
plane = bpy.context.active_object
plane.location[2] = -height/2

# 穴を作成する
bpy.ops.mesh.primitive_circle_add(radius=0.5, fill_type='NGON')

# 穴を移動する
hole = bpy.context.active_object
hole.location[2] = -height/2 + 0.001
hole.location[0] = hole.location[1] = 1.5

# 重なりをチェックする
bm1 = bmesh.new()
bm1.from_mesh(plane.data)
bm2 = bmesh.new()
bm2.from_mesh(hole.data)
bm1.faces.ensure_lookup_table()
bm2.faces.ensure_lookup_table()
result = bmesh.ops.bisect_plane(
    bm1, 
    geom=bm1.faces[:], 
    plane_co=(0, 0, -height/2), 
    plane_no=(0, 0, 1)
)
for f in result['geom_cut']:
    if hole in f.verts:
        hole.location[2] += 0.001
        break
bm1.to_mesh(plane.data)
bm1.free()

# メッシュを作成する
mesh = bpy.data.meshes.new('Cone')

# メッシュに頂点と面を追加する
mesh.from_pydata(vertices, [], faces)

# メッシュをオブジェクトに変換する
obj = bpy.data.objects.new('Cone', mesh)

# オブジェクトをシーンに追加する
bpy.context.scene.collection.objects.link(obj)


このスクリプトでは、まず円錐の頂点と面を計算する部分は先程のスクリプトと同様です。次に、平面を作成し、位置を円錐の底面と合わせます。その後、穴を作成し、位置を平面の中心に調整します。最後に、平面と穴の重なりをチェックし、穴が円錐の底面円周に重なるように位置を調整します。

なお、穴の位置を微調整する際










togetter.com/t/c2022meetzionad
togetter.com/t/b2022meetzionad




twitter 新着検索 Dürer & 測距儀


aaa
bbb




ccc twitter zionadchat
twitter に追い出されたら 連絡先は Gettr https://gettr.com/user/zionadchat
twitter サブアカウント https://twitter.com/2022zionad

old page いいい
new page いいい

目次 2022の目次 単純トリック hatena zionadchat
いいいいいいいい

このブログの人気の投稿

球体で カシオペア座の5つの恒星 その3次元 宇宙内の相対位置を再現して

import bpy from random import randint # 球体を作成する関数 def create_sphere(x, y, z, radius):     bpy.ops.mesh.primitive_uv_sphere_add(location=(x, y, z), radius=radius) # ランダムな座標を返す関数 def random_location():     x = randint(-5, 5)     y = randint(-5, 5)     z = randint(-5, 5)     return (x, y, z) # 5つの球体を作成 for i in range(5):     location = random_location()     create_sphere(location[0], location[1], location[2], 1) ランダムではなく、 カシオペア座の5つの恒星 その3次元 宇宙内の相対位置を再現して カシオペア座の5つの恒星の相対位置を再現するためには、各恒星の座標を知る必要があります。これらの座標を手動で入力することもできますが、以下のように、座標データを使用することもできます。 import bpy # カシオペア座の5つの恒星の座標 coordinates = [(4.23, 56.87, 13.04),                 (3.19, 61.75, -0.28),                 (1.62, 58.75, -18.45),                 (0.11, 59.15, 16.52),                 (1....

Chat 20230115

  "Exploited" in English means to use or take advantage of someone or something for one's own benefit, often in an unjust or cruel manner. It can also mean to use something to its full potential or to take advantage of an opportunity. Examples of this could be an employer exploiting their workers for higher profits, or a developer exploiting natural resources for their own gain. 機関車トーマス 英語版 事故が起きるよ youtube 教えて I'm sorry, but I'm not able to find any specific information about a "Thomas the Tank Engine accident" on YouTube. It's possible that you may be mistaken or that there is no such content available. ad jazzion 歌です I apologize for the confusion. The song you may be looking for is called "Accidents Will Happen" from the Thomas the Tank Engine & Friends TV series and it's available on YouTube. You can find it by searching for the title of the song or by searching for "Thomas the Tank Engine Accidents Will Happen" on YouT...

blenderzionad Googledrive 配布リンク 20230307 tue

3D Viewport 座標空間の色設定は 配布ファイルに入っていません 座標空間 色設定は ここで  blender 2023 初歩の初歩 006 長方体 cuboid に 3D Viewport 内で 色付け マテリアルわからなくて https://togetter.com/li/2088806 #Togetter 座標空間の色設定 保存は ここで blender 2023 初歩の初歩 007 3D Viewport 色設定保存 https://togetter.com/li/2097575 #Togetter あ 21個の球体を1単位毎に配置し、中央の球体を赤色に塗るPythonコード https://englishjazzionad.blogspot.com/2023/03/211python.html 配布リンク https://drive.google.com/file/d/1pJYEaFjAHNDuiRkCQ70zk5AIhxuG58EZ/view?usp=share_link 36個の球体 円周 https://englishjazzionad.blogspot.com/2023/03/blog-post_6.html 配布リンク https://drive.google.com/file/d/1IzkiO84ilwbzm4JuKuEuYPeR5oWxOIFW/view?usp=share_link 20230307 合体36個の球体 & 21個の球体  配布01 配布リンク https://drive.google.com/file/d/1UXP20HnTFKOcaSbXDrp6Rix-s6lZsBKu/view?usp=share_link ああああああああ あああああああああああああああ トーラス3つ と 立方体の 円柱空洞 2023 03 06 14h51 59 https://youtu.be/a6uxWUL0n7c   トーラス 3つ in 3次元空間 https://englishjazzionad.blogspot.com/2023/03/blog-post_5.html 配布リンク https://drive.google.com/file/d/1Pi6NDO1RHfI403BBm_OBPljUPGwcp526/v...