You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何计算沿椭圆运动且竖直向下移动物体的x、y坐标

求解兼具竖直向下运动与椭圆约束的物体轨迹坐标

假设某物体以0.5m/s的速度沿Y轴竖直向下运动,同时其位置始终满足椭圆约束:椭圆长半轴半径为100,短半轴半径为25,初始位置为(x,y)=(175,150)。需要求解该物体的x、y坐标,其最终轨迹呈类二维弹簧状结构。


一、椭圆轨迹的基础计算

数学公式

椭圆平移后的x坐标求解公式为:
$$ x = \sqrt{a^2 - \frac{(y-k)^2 \cdot a2}{b2}} + h $$
代入参数(短半轴$a=25$,长半轴$b=100$,椭圆中心$(h,k)=(150,150)$)后,具体公式为:
$$ x = \sqrt{25^2 - \frac{(y-150)^2 \cdot 252}{1002}} + 150 $$

基础椭圆绘制代码

以下Python代码用于生成并绘制椭圆轨迹:

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

t = np.linspace(0,360,360)
x = 150 + 25*np.cos(np.radians(t)) # 150为椭圆中心x坐标,25为短半轴
y = 150 + 100*np.sin(np.radians(t)) # 150为椭圆中心y坐标,100为长半轴

# plt.plot(x,y)
# plt.show()

df = pd.DataFrame(list(zip(x, y)), columns = ['x', 'y'])

# 移除重复行
df = df.drop_duplicates(keep = 'first')

ax = sns.scatterplot(data = df, x = 'x', y = 'y')
ax.set_xlim(0, 400)
ax.set_ylim(0, 300)
plt.grid()

根据y值求解x的函数

该函数可返回对应y值下椭圆两侧的x坐标:

import math

def solve_for_x(y):
    a = 25
    b = 100
    h = 150
    k = 150
    x1 = math.sqrt(a**2 - ( ( (y-k)**2 * a**2 )/b**2 )) + h
    x2 = - math.sqrt(a**2 - ( ( (y-k)**2 * a**2 )/b**2 )) + h
    return x1, x2

二、结合竖直向下运动的轨迹求解

要得到类弹簧状轨迹,需将竖直向下的匀速运动与椭圆上的周期性运动结合,具体实现如下:

核心思路

物体的运动是两种运动的合成:

  1. 竖直方向:以0.5m/s匀速向下,y坐标随时间线性递减
  2. 水平方向:沿椭圆短半轴做周期性摆动,保证位置始终符合椭圆约束

完整实现代码

import numpy as np
import matplotlib.pyplot as plt

# 参数设置
omega = 0.1  # 水平方向摆动的角频率,值越大摆动越频繁
v_y = 0.5    # 竖直向下速度,单位m/s
t_total = 500 # 总模拟时间,单位秒
t = np.linspace(0, t_total, int(t_total*10)) # 时间序列,步长0.1秒

# 计算轨迹坐标
x = 150 + 25 * np.cos(omega * t)
y = 150 + 100 * np.sin(omega * t) - v_y * t

# 绘制轨迹
plt.figure(figsize=(10,8))
plt.plot(x, y, label='弹簧状轨迹')
plt.scatter(175, 150, color='red', label='初始位置')
plt.xlim(100, 200)
plt.ylim(min(y)-50, 250)
plt.xlabel('x坐标')
plt.ylabel('y坐标')
plt.title('兼具竖直向下运动与椭圆约束的物体轨迹')
plt.legend()
plt.grid(True)
plt.show()

说明

  • 调整omega参数可改变水平摆动频率:值越大,轨迹的弹簧“圈数”越多
  • 该实现保证了任意时刻的位置都满足椭圆约束,同时整体轨迹随时间持续向下延伸

内容的提问来源于stack exchange,提问作者n3a5p7s9t1e3r

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 16:06:28