angleTo funciton returning nan

angleTo funciton returning nan

Joshua.mursic
Advocate Advocate
516 Views
3 Replies
Message 1 of 4

angleTo funciton returning nan

Joshua.mursic
Advocate
Advocate

Hello, I am having an issue with the angleTo() funciton, it is returning 'nan'. Am I doing something wrong?

# Define Stock
stockCenter = adsk.core.Vector3D.create(0,0,0)


# Define Part
partBox = partBoundingBox.copy()
partMax = partBox.maxPoint
partMin = partBox.minPoint
partCenterX = partMax.x - ((partMax.x - partMin.x)/2)
partCenterY = partMax.y - ((partMax.y - partMin.y)/2)
partCenterZ = partMax.z - ((partMax.z - partMin.z)/2)
partCenter = adsk.core.Vector3D.create(partCenterX,partCenterY,partCenterZ)
angle = stockCenter.angleTo(partCenter)

 

0 Likes
Accepted solutions (1)
517 Views
3 Replies
Replies (3)
Message 2 of 4

Jorge_Jaramillo
Collaborator
Collaborator
Accepted solution

Hi @Joshua.mursic ,

 

I believe that your problem is with the definition of the stockCenter vector, which defined as (0,0,0) does NOT have magnitude; (it is like a point instead), so no way you can determine the angle to the other vector you build later.

 

Try changing (0,0,0) by (1,0,0) just to try if you get some value from your code.

Then decide how it should be really calculated.

 

Hope this help.

 

Regards,

Jorge Jaramillo

 

Message 3 of 4

Joshua.mursic
Advocate
Advocate

This was exactly correct, thank you.

0 Likes
Message 4 of 4

MichaelT_123
Advisor
Advisor

.... what about saving on compute time and keyboard strokes ...

 

from ...

partCenterX = partMax.x - ((partMax.x - partMin.x)/2)

to

partCenterX =  (partMax.x + partMin.x)/2.

 

😉

 

 

MichaelT
0 Likes