我正在尝试将下面的函数转换为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);
我知道它返回一个数组,射线,但它究竟是用方向和系数做的?有人可以向我解释发生了什么事。任何帮助将不胜感激。
答案 0 :(得分:3)
ray
是返回值。 python版本将是
def create_ray(point1, direction):
...
return ray
Matlab代码中ray
为function [
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