0

我正在使用empet plotly 社区表单中的以下函数绘制一个椭圆体:

def ellipse(x_center=0, y_center=0, ax1 = [1, 0],  ax2 = [0,1], a=1, b =1,  N=100):
    # x_center, y_center the coordinates of ellipse center
    # ax1 ax2 two orthonormal vectors representing the ellipse axis directions
    # a, b the ellipse parameters
    if np.linalg.norm(ax1) != 1 or np.linalg.norm(ax2) != 1:
        raise ValueError('ax1, ax2 must be unit vectors')
    if  abs(np.dot(ax1, ax2)) > 1e-06:
        raise ValueError('ax1, ax2 must be orthogonal vectors')
    t = np.linspace(0, 2*pi, N)
    #ellipse parameterization with respect to a system of axes of directions a1, a2
    xs = a * cos(t)
    ys = b * sin(t)
    #rotation matrix
    R = np.array([ax1, ax2]).T
    # coordinate of the  ellipse points with respect to the system of axes [1, 0], [0,1] with origin (0,0)
    xp, yp = np.dot(R, [xs, ys])
    x = xp + x_center 
    y = yp + y_center
    return x, y

但是,我在线条周围得到了不完美的椭圆体。有关更多说明,请参阅所附图片。我们如何更新函数以考虑线的旋转轴并围绕线绘制完美的椭圆体?

调用函数并绘制椭球的代码如下:

x22 = tw2_df['x']
z22 = tw2_df['z']

x5 = tw5_df['x']
z5 = tw5_df['z']

# Create figure
fig = go.Figure()

# Add scatter traces
fig.add_trace(go.Scatter(x=x22, y=z22, name="line-2", mode="markers", marker_color='gray'))
fig.add_trace(go.Scatter(x=x5, y=z5, name="line-3", mode="markers", marker_color='gray'))

# well-2
x_center=h2
y_center=k2
x22, y22 = ellipse(x_center=x_center, y_center=y_center, 
                   ax1 =[cos(pi/2), sin(pi/2)],  ax2=[-sin(pi/2),cos(pi/2)],
                   a=a2, b =b2)

fig.add_scatter(
            x=x22,
            y=y22,
            mode = 'lines')

# well-5
x_center=h5
y_center=k5
x5, y5 = ellipse(x_center=x_center, y_center=y_center, 
                   ax1 =[cos(pi/2), sin(pi/2)],  ax2=[-sin(pi/2),cos(pi/2)],
                   a=a5, b =b5)

fig.add_scatter(
            x=x5,
            y=y5,
            mode = 'lines')

fig.update_layout(showlegend=True)
fig.show()

Plotly 点表示线和椭球

数据:h2=540.05,k2=-54.75,a2=36.67,b2=577.62 h5=550.28,k5=-246.58,a5=43.17,b5=590.69

这是将 x 和 y 数据作为 CSV 文件的链接。 https://drive.google.com/drive/folders/1JGKdnfqu9aZy8YFtL_2kL-NnJ-fJHcMM?usp=sharing

对此的任何帮助将不胜感激!

4

1 回答 1

0

我发现的解决方案之一是在创建椭圆体时包含旋转角度。以下是角度的更新版本:

def ellipse(x_center=0, y_center=0, ax1 = [1, 0],  ax2 = [0,1], a=1, b =1,  N=100):
   # x_center, y_center the coordinates of ellipse center
   # ax1 ax2 two orthonormal vectors representing the ellipse axis directions
   # a, b the ellipse parameters
   if np.linalg.norm(ax1) != 1 or np.linalg.norm(ax2) != 1:
       raise ValueError('ax1, ax2 must be unit vectors')
   if  abs(np.dot(ax1, ax2)) > 1e-06:
       raise ValueError('ax1, ax2 must be orthogonal vectors')
   #rotation matrix   
   R = np.array([ax1, ax2]).T
   if np.linalg.det(R) <0: 
       raise ValueError("the det(R) must be positive to get a  positively oriented ellipse reference frame")
   t = np.linspace(0, 2*pi, N)
   #ellipse parameterization with respect to a system of axes of directions a1, a2
   xs = a * cos(t)
   ys = b * sin(t)
   
   # coordinate of the  ellipse points with respect to the system of axes [1, 0], [0,1] with origin (0,0)
   xp, yp = np.dot(R, [xs, ys])
   x = xp + x_center 
   y = yp + y_center
   return x, y

此外,当我们调用该函数时,我们将旋转角度定义如下: 示例 1:注意我们定义了 pi/1.93,这将导致我的模型中的旋转角度。这将由用户定义并由用户直观地验证。

# well-4 
x_center = h4
y_center = k4
angel_4 = pi/1.93
x, y = ellipse(x_center=x_center, y_center=y_center, ax1 =[cos(angel_4), sin(angel_4)],  ax2=[-sin(angel_4),cos(angel_4)], a=a4, b =b4)
fig.add_scatter(x=x, y=y, mode = 'lines', name='Zone-1 - well-4', fill='toself', opacity=0.5)

示例 2:请注意,我们定义 pi/1.935 来旋转椭圆。

# well-5
x_center = h5
y_center = k5
angel_5 = pi/1.935
x, y = ellipse(x_center=x_center, y_center=y_center, ax1 =[cos(angel_5), sin(angel_5)],  ax2=[-sin(angel_5),cos(angel_5)], a=a5-20, b =b5-140)
fig.add_scatter(x=x, y=y, mode = 'lines', name='Zone-1 - well-5', fill='toself', opacity=0.5)

示例 3 请注意,我们定义 pi/1.921 来旋转椭圆。

# well-6
x_center=h6
y_center=k6
angel_6 = pi/1.921
x, y = ellipse(x_center=x_center, y_center=y_center, ax1 =[cos(angel_6), sin(angel_6)],  ax2=[-sin(angel_6),cos(angel_6)], a=a6-25, b =b6-140)
fig.add_scatter(x=x, y=y, mode = 'lines', name='Zone-1 - well-6', fill='toself', opacity=0.8)

请以附图为例。

在此处输入图像描述

于 2021-10-14T12:54:33.553 回答