MATLAB函数声明

时间:2014-04-26 06:20:29

标签: python matlab

我正在尝试将下面的函数转换为Python,但我不确定发生了什么。

function [ray]=create_ray(point1,direction)
ray.direction.x=direction.x;
ray.coefficients.x=(point1.x);
ray.direction.y=direction.y;
ray.coefficients.y=(point1.y);
ray.direction.z=direction.z;
ray.coefficients.z=(point1.z);

我知道它返回一个数组,射线,但它究竟是用方向和系数做的?有人可以向我解释发生了什么事。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:3)

ray是返回值。 python版本将是

    def create_ray(point1, direction):
        ...
        return ray

Matlab代码中rayfunction [ ray ]=create_ray(point1,direction)

BTW,ray将由Python中的class定义。所以最终的代码可以是

class Direction(object):
    x, y, z = None, None, None

class Coefficients(object):
    x, y, z = None, None, None

class Ray(object):
    direction = Direction()
    coefficients = Coefficients()

def create_ray(point1, direction):
    ray = Ray()
    ray.direction.x = direction.x;
    ray.coefficients.x = point1.x;
    ray.direction.y = direction.y;
    ray.coefficients.y = point1.y;
    ray.direction.z = direction.z;
    ray.coefficients.z = point1.z;
    return ray