如何将函数作为参数传递给其他函数?我的代码如下

等待

这是 RRT 算法的代码

import sys import pygame import random, math from math import sqrt, atan2, cos, sin from pygame.locals import *

类 RRT(对象):

x = 0
y = 0
X_dimension = 0
Y_dimension = 0
Window_size = 0
EPS         = 0
Max_nodes   = 0 
nodes       = list()
K_ESCAPE    = True
KEYUP       = True
QUIT        = True

def __init__(self,x,y):
    self.x = x
    self.y = y

#parameters
    self.X_dimension = 1280                                #length of the window
    self.Y_dimension = 1280                                  #breadth of the window
    self.Window_size = [self.X_dimension, self.Y_dimension]  #Window size
    self.EPS         =  7000                                #EPSILON or Incremental Distance 
    self.Max_nodes   = 100                                  #maximum number of nodes
    self.nodes       = list()
    self.QUIT        = QUIT
    self.KEYUP       = KEYUP
    self.K_ESCAPE    = K_ESCAPE


#function for calculating euclidean distance
def Calculate_Distance(self,x,y):

    x = [10,20]
    y = [15,30]  
    return sqrt((x[0]-y[0])*(x[0]-y[0])+(x[1]-y[1])*(x[1]-y[1]))

    pass 

def Initiate_Sampling(self,x,y):

    self.EPS = 7000 

    if Calculate_Distance(x,y) < 7000:
        return y
    else:
        theta = atan2(y[1]-x[1], y[0]-x[0])
        return x[0] + self.EPS*cos(theta), x[1] + self.EPS*sin(theta)

#Function for displaying the output
def Start_The_Game(self):

    pygame.init()

    screen = pygame.display.set_node(Window_size)

    caption = pygame.display.set_caption("performing RRT")

    white = 255, 240, 200
    black = 20, 20, 40
    screen.fill(black)

#Main Function
def Node_Generation(self, nodes):
    self.nodes      = []
    self.QUIT       = QUIT
    self.KEYUP      = KEYUP
    self.K_ESCAPE   = K_ESCAPE

    #nodes.append(X_dimension/2.0, Y_dimension/2.0)

    nodes.append(0.0, 0.0)
    pygame.init()

for i in range(Max_nodes):
    rand = random.random()*640.0, random.random()*480.0
    nn = nodes[0]

for p in nodes:
    if dist(p,rand) < dist(nn,rand):
        nn = p
        newnode = step_from_to(nn,rand)
        nodes.append(newnode)
        pygame.draw.line(screen,white,nn,newnode)
        pygame.display.update()
        print (i, "  ", nodes)

for j in pygame.event.get():
    if j.type == QUIT or (j.type == KEYUP and j.key == K_ESCAPE):
        pygame.quit()
        sys.exit("GAME OVER")

路径 = RRT(10,15)

path.Calculate_Distance(10,15)

path.Initiate_Sampling(path.Calculate_Distance(10,15))

path.Start_The_Game()

path.Node_Generation()

#

我的查询 - 我想将 Calculate_Distance 函数作为参数传递给 Initiate_Sampling 函数,以将其与 EPS 进行比较。

八田和也

您可以通过self访问类中其他类成员的相同方式访问成员函数IE

self.Calculate_Distance

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何将函数作为参数传递给其他函数以避免重复代码

Kotlin:如何将具有可变参数的函数作为参数传递给其他函数

如何将参数从函数传递给其他函数

如何将 state 和 setState 作为参数传递给其他函数?

如何将Django过滤器args作为参数传递给其他函数

如何将struct作为参数传递给其他函数进行输入,然后在原始函数处输出回

如何将参数传递给将这些参数传递给用作参数的其他函数的函数

如何将函数作为参数传递给transform()函数?

如何将函数作为参数传递给参数?

我如何将函数作为参数传递给 C++ 中的函数

如何将文件指针传递给其他函数

如何将类作为参数传递给PHP函数

如何将类类型作为参数传递给函数?

如何将通道作为参数传递给函数?

Python:如何将列表作为参数传递给函数?

如何将struct作为参数传递给函数

如何将参数作为函数传递给变量?

如何将列表作为参数传递给函数

如何将元组作为参数传递给divmod()函数

如何将模板作为参数传递给函数

如何将 **kwargs 作为参数传递给 fastAPI 函数

如何将省略号运算符得到的参数传递给其他函数?

如果传递的函数也将函数作为参数,如何将函数作为参数传递给C中的函数?

我们如何将字节作为关键字参数的键传递给函数?

我如何将变量内容传递给函数作为参数

如何在不牺牲性能的情况下将函数作为参数传递给Julia中的其他函数?

将一个函数作为参数传递给其他函数

将字符串作为函数中的参数传递给 R 中的其他函数

如何将代码传递给函数?