Reputation: 2091
I've been looking around for a while, but I can't seem to find something that describes and answers the problem I've been having. Namely, I have a function being defined in a ball
class that checks to see if it and another ball are intersecting (due to the balls being kept on the same z-plane and the radius being the same for all of them, I've simplified the problem to that of intersecting circles). This function is as follows (where both obj
and other
are of the class ball
, and where the ball
class contains a position vector of length 3):
function intersected = ball_intersection(obj, other)
intersected = (obj.position(1)-other.position(1))^2+(obj.position(2)-other.position(2))^2 <= (2*ball.radius)^2;
end
I get the following error:
Undefined variable other.
Error in ball/ball_intersection (line 29)
intersected = (obj.position(1)-other.position(1))^2+(obj.position(2)-other.position(2))^2 <= (2*ball.radius)^2;
Error in ball/move (line 56)
if ball_intersection(other)
Error in finalproject (line 41)
cueball.move(0.0001, 0, 0, 9.32, 4.65, otherball);
For some reason, Matlab thinks that a function parameter is undefined, and I don't know how to make it know that it is in fact defined right there.
Any and all help is appreciated - thanks for reading!
Upvotes: 0
Views: 190
Reputation: 74940
ball_intersection
has to be called with two input arguments.
Most likely, you want to change line 56 of ball
to if ball_intersection(obj,other)
, or if obj.ball_intersection(other)
.
Upvotes: 1