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?

keisan2

Posted at
title.rb

import pandas as pd
import numpy as np

# DataFrameの作成
df = pd.DataFrame(columns=['r', 'theta', 'phi'])

# r, theta, phiの値を生成するリスト内包表記
data = [{'r': r, 'theta': theta, 'phi': phi} 
        for r in range(4, 5)  # rの範囲は1~10
        for theta in range(-60, 62, 2)
        for phi in range(-60, 62, 2)]

sin_th = np.sin(np.radians(df['theta'].astype(float)))
cos_th = np.cos(np.radians(df['theta'].astype(float)))
sin_ph = np.sin(np.radians(df['phi'].astype(float)))
cos_ph = np.cos(np.radians(df['phi'].astype(float)))

# DataFrameにデータを追加
df = df.append(data, ignore_index=True)

df['x'] = df['r'] * np.sin(np.radians(df['theta'].astype(float))) * np.cos(np.radians(df['phi'].astype(float)))
df['y'] = df['r'] * np.sin(np.radians(df['phi'].astype(float))) * np.cos(np.radians(df['theta'].astype(float)))
df['z'] = df['r'] * ((1-(np.sin(np.radians(df['theta'].astype(float)))**2)*(np.cos(np.radians(df['phi'].astype(float)))**2)-(np.sin(np.radians(df['phi'].astype(float)))**2)*(np.cos(np.radians(df['theta'].astype(float)))**2))**0.5)
df['r_check'] = (df['x']**2 + df['y']**2 + df['z']**2)**0.5

print(df['r_check'].unique())
# データフレームを表示
df.tail()

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# 半球のパラメータ
r = 4  # 球の半径
phi, theta = np.mgrid[0:np.pi/2:100j, 0:2*np.pi:100j]  # phiとthetaの範囲を設定

# 極座標から直交座標に変換
x = r * np.sin(phi) * np.cos(theta)
y = r * np.sin(phi) * np.sin(theta)
z = r * np.cos(phi)

# プロット
fig = plt.figure(figsize=(16.0, 12.0))
ax = fig.add_subplot(111, projection='3d')

ax.scatter(df['x'], df['y'], df['z'], alpha=0.2)
# 半球をプロット
ax.plot_surface(x, y, z, alpha=0.2)

# 軸の範囲とラベル設定
ax.set_xlim([-4, 4])
ax.set_ylim([-4, 4])
ax.set_zlim([0, 8])

# 軸の縮尺を等しくする
ax.set_box_aspect([1,1,1])

ax.tick_params(labelbottom=False, labelleft=False, labelright=False, labeltop=False)

# グラフを表示
plt.show()



import numpy as np
import plotly.graph_objs as go

# 半球のパラメータ
r = 4  # 球の半径
phi, theta = np.mgrid[0:np.pi/2:100j, 0:2*np.pi:100j]  # phiとthetaの範囲を設定

# 極座標から直交座標に変換
x = r * np.sin(phi) * np.cos(theta)
y = r * np.sin(phi) * np.sin(theta)
z = r * np.cos(phi)

# 半球をプロット
surface = go.Surface(x=x, y=y, z=z, opacity=0.2, colorscale=[[0, 'rgb(0,0,255)'], [1, 'rgb(0,0,255)']])

# 点をプロット
scatter = go.Scatter3d(x=df['x'], y=df['y'], z=df['z'],mode='markers', opacity=0.5, marker=dict(color='grey', size=2))

# レイアウトの設定
layout = go.Layout(
    scene=dict(
        xaxis=dict(range=[-4, 4], title='X'),
        yaxis=dict(range=[-4, 4], title='Y'),
        zaxis=dict(range=[0, 8], title='Z'),
        aspectmode='cube'
    )
)

# グラフの描画
fig = go.Figure(data=[surface, scatter], layout=layout)
fig.show()


plt.scatter(df['x'], df['z'],alpha = 0.2)

plt.scatter(df['y'], df['z'],alpha = 0.2)

plt.scatter(df['x'], df['y'],alpha = 0.2)
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?