cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

divided by zero

YA_10963798
14-Alexandrite

divided by zero

How I can  tell matcade when the angle is divided by zero consider the value to be zero 

YA_10963798_1-1714388326442.png

 

 

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:YA_10963798)

The problem is not that the first argument is zero - atan2 can handle that and returns + or - pi/2.

Werner_E_0-1714389517703.png

The problem only occurs if BOTH arguments are zero because then the angle is undefined.

 

So you have to ask for both arguments being zero.

Furthermore you should not use "return" as this command terminates the program.

You also must ask for the arguments being both zero BEFORE you call atan2 as otherwise the error would be thrown again.

Don't use "deg" when you define "Angle", use it when you display it!

Here is a way to get what you are looking for:

Werner_E_1-1714389642959.png

If you want to save space you may also use the if-function instead of the if-statement (at the cost of readability and clearness):

Werner_E_3-1714390201943.png

 

 

You may also consider to re-define the atan2 function so that it always will return 0 in the case both arguments are zero.

You can do this at the top of the sheet, maybe in a collapsed region along with other utility functions and definitions.

Werner_E_2-1714389738146.png

When you re-define atan2 you should label it as being "function" so that it really replaces the built-in function with the same name.

 

 

View solution in original post

2 REPLIES 2
Werner_E
25-Diamond I
(To:YA_10963798)

The problem is not that the first argument is zero - atan2 can handle that and returns + or - pi/2.

Werner_E_0-1714389517703.png

The problem only occurs if BOTH arguments are zero because then the angle is undefined.

 

So you have to ask for both arguments being zero.

Furthermore you should not use "return" as this command terminates the program.

You also must ask for the arguments being both zero BEFORE you call atan2 as otherwise the error would be thrown again.

Don't use "deg" when you define "Angle", use it when you display it!

Here is a way to get what you are looking for:

Werner_E_1-1714389642959.png

If you want to save space you may also use the if-function instead of the if-statement (at the cost of readability and clearness):

Werner_E_3-1714390201943.png

 

 

You may also consider to re-define the atan2 function so that it always will return 0 in the case both arguments are zero.

You can do this at the top of the sheet, maybe in a collapsed region along with other utility functions and definitions.

Werner_E_2-1714389738146.png

When you re-define atan2 you should label it as being "function" so that it really replaces the built-in function with the same name.

 

 

YA_10963798
14-Alexandrite
(To:Werner_E)

Thank very very much for your help 

Announcements

Top Tags