首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何连接点和吸收动量?

如何连接点和吸收动量?
EN

Stack Overflow用户
提问于 2018-07-11 15:22:05
回答 2查看 132关注 0票数 1

我目前正在使用像这样的显示激光设备。设备接收2D点的列表,然后显示。在内部,有一个电流计控制反射镜投射激光点。

假设我想显示5个激光点(A,B,C,D,E)。由于激光设备不喜欢在较短的时间间隔内进行长距离旅行,因此必须增加中间点,称为消隐点(激光沿这些空白点行进时关闭)。这一程序实现了不过分强调电流计的目的。

我目前正在用一个简单的最近邻算法计算5个点之间的“最短路径”,最后是直线(下图中的红色虚线)。

通过这种优化,我已经取得了相当好的效果。但我想更进一步。电流计在运动时有一些物理动量。当做急转弯时,例如从C->D和D->E出发,它确实会对激光装置产生压力。

所以我想通过引入弯曲的消隐线来吸收一些物理动量,而不是直线(cp )。要在上面的插图“解决方案”中最后显示图像)。

知道怎么做到吗?

指向某些算法资源和/或一些伪代码或C#将是有帮助的。谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-07-11 17:10:35

正如其他人所提到的,您需要使用某种三次样条插值。

一旦你知道每个关键点的访问时间和每个关键点的速度,你就可以计算出一个分段三次Hermite样条,它以选定的速度通过关键点。请参阅:样条

由于对速度没有任何特殊的要求,所以您可能想使用一个经典的三次样条(是的,这些东西的名称是模棱两可的):http://mathworld.wolfram.com/CubicSpline.html这种形式的样条确定速度,以确保一阶导数(速度)和二阶导数(加速度)沿着整个路径平稳地变化。

由于对于到达每个关键点的确切时间也没有任何特殊要求,所以您可能希望为整个路径设置最大时间,然后选择关键点的时间,以最小化最大加速度或类似的情况。我可没有那么简单的方法。我想尝试的是:

首先,使关键点之间的时间与这些点之间的距离成比例。然后,应用几轮:

  1. 调整每段所花的时间,使切线加速度在关键点处为0。
  2. 重新计算样条

但是,如果没有这些优化回合,您可能会非常高兴--最初的猜测不会太糟糕。

票数 3
EN

Stack Overflow用户

发布于 2018-07-11 20:32:24

我认为你要处理的是一个旅行-推销员-问题(TSP) (这里是博士课程的幻灯片,讨论如何解决这个问题。),而最小化激光上的应力的路径是一个最小化力和力的变化的路径,所以它是具有最小曲率的路径,所以我认为最好的方法是在3对点之间用一个圆弧旋转路径。

关于如何计算通过3个点的圆的参数的例子可以找到这里

我不太精通C#,所以我将在C#中添加一个实现,我希望您也能发现它也很有用。

它的思想是,对于点A,B,C的每一个三重奏,我找到了圆的弧线,它代表了这三个点,而这个弧线将是连接B和C的路径。

我还没来得及测试这个,所以可能有一些错误的迹象。

代码语言:javascript
运行
复制
# Initial points 
points = [(1,1),(2,3),(5,3),(-4.1),(12,3)]
#List of point in the order find by the solution of the TSP
spl = tsp_solve(points) # generic function to solve the TSP

# Append the first two point of the list so that I can iterate over the list
# and parse every triplet of points in the same way.
spl = spl + spl[:2]

# The list where will be added every path that connect the points
paths = []

# For each tirplets of sequential points
for A,B,C in zip(spl[:-2],spl[1:-1],spl[2:]):
    # Calculate the angular coefficent of the two line that pass on A,B and B,C
    coeff_ab = (B[1] - A[1]) / (B[0] - A[0])
    coeff_bc = (C[1] - B[1]) / (C[0] - B[0])
    # If the two line have the same coeff then all the 3 point are on the same line
    # and therfore the best path is that line.
    if(coeff_ab == coeff_bc):
        offset_y = A[1] - coeff_ab * A[0]   
        delta_x = C[0] - B[0]            
        paths.append({"type":"Line","coeff":coeff_ab,"offset_y":offset_y,"deta_x":delta_x})
        continue
    # Calculate the x of the center of the circle
    center_x  = coeff_ab *coeff_bc *(C[0]-A[0])
    center_x += coeff_ab *(B[0]+C[0]) 
    center_x -= coeff_bc *(A[0]+B[0])
    center_x /= 2*(coeff_ab - coeff_bc)
    # Calculate the y of the center of the circle
    center_y  = (A[1]+B[1)/2
    center_y -= (center_x - (A[0] + B[0])/2)
    center_y /= coeff_bc

    radius = sqrt(center_x**2 + center_y**2)

    paths.append({"type":"Circle","Radius":radius,"center_x":center_x,"center_y":center_y})

# Function To Calculate the X and Y of the lines and circles.

def calculate_circle_x(circle,time):
    """Function that return the x of a circle at a given time"""
    time = time + circle["time_off"]
    return circle["radius"] * cos(2*pi*time) + circle["center_x"]
def calculate_circle_y(circle,time):
    """Function that return the y of a circle at a given time"""
    time = time + circle["time_off"]
    return circle["radius"] * sin(2*pi*time) + circle["center_y"]

def calculate_line_x(line,time):
    """Function that return the x of a line at a given time"""
    time = (line['delta_x']*time) + line["time_off"]
    return time
def calculate_line_y(line,time):
    """Function that return the y of a line at a given time"""
    time = (line['delta_x']*time) + line["time_off"]
    return time * line["coeff"] + line['offset_y']

def calculate_x(obj,time):
    """Function that return the x of whatever it's passed"""
    if(obj['type'] == 'Circle'):
        return calculate_circle_x(obj,time)
    else:
        return calculate_line_x(obj,time)

def calculate_y(obj,time):
    """Function that return the y of whatever it's passed"""
    if(obj['type'] == 'Circle'):
        return calculate_circle_y(obj,time)
    else:
        return calculate_line_y(obj,time)

# Calculate some sample of the global path to plot it or do whatever with it.
number_of_sample = 100000
path_points = []
number_of_paths = len(paths)

# Calculate some time equidistant point's sample
for i in range(number_of_sample):
    # Calculate the global time
    global_time = i*number_of_paths/number_of_sample
    # Calculate in which path the point it is
    path_number = int(global_time)
    # Calculate which time of the path it is
    local_time  = global_time - path_number
    path = paths[path_number]
    # Calculate the sampled point
    new_point = (calculate_x(path,local_time),calculate_y(path,local_time))
    # Add the sampled point to the path_points list
    path_points.append(new_point)

# Print the result of the path point sampled.
print(path_points)

现在,您有了点,或者至少有了如何计算这些点的示例,并且可以将其转换为C#。我试着对它进行了大量的评论,这样即使不了解Python,您也可以理解它。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51289132

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档