PDA

View Full Version : Strange results from a simple if statement?


Wrench
12-03-2008, 03:49 PM
Hi all

I am very new to maxscript and am receiving really wierd results from a simple if statement, I cannot understand what I am doing wrong so forgive me if this may seem trivial to you.

What I am doing is generating a random amount of faces, some that are perpendicular to the z-axis and others that are not. Problem is, at random intervals the statement returns false when in actual fact it should be returning true. This is happening even if all face normals are exactly the same.

for i=1 to faceNum do
(
p = polyOp.getFaceNormal $ i
if p == [0, 0, 1] then
(
print "true"
)
else
(
print "false"
)
)

At the moment p = [0,0,1] at every increment of i and yet I am still getting falses every now and again. What am I doing wrong?

Thanks in advance
Luca

PiXeL_MoNKeY
12-03-2008, 03:56 PM
Returns the face normal of the face. If <poly> is a node, or if <poly> is an Editable Poly and <node> is specified, the direction vector returned is in the current coordinate system context. If <poly> is an Editable Poly and <node> is not specified, the return value is in the poly's local coordinate system.According to the help the direction returned is the current coordinate system, so what coordinate system are you working in?

-Eric

Wrench
12-03-2008, 04:03 PM
Thanks for the speedy reply Pixel_monkey.

Well I havent specified node so I would pressume it is the poly's local co-ordinate system that I am working in. What confuses me is that for every instance that I print 'p' ( about 500 times) it returns constantly a value equal to [0,0,1] and yet it returns random false statements when in effect that should never be happening.

drdubosc
12-03-2008, 04:51 PM
Hi, it's not a problem with the 'if', it's a precision and display problem. For example you can do this in the listener:


f = 1.000001
1.0
p = [0,0,f]
[0,0,1]
p == [0,0,1]
false

Check out Bobo's answers to this thread (http://forums.cgsociety.org/showthread.php?f=98&t=690027) for a good explanation

Wrench
12-03-2008, 04:59 PM
aaahhh, thanks so much for the help dr. I really appreciate it.

CGTalk Moderation
12-03-2008, 04:59 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.