View Full Version : Trouble with infinate / indeterminate floats.
11 November 2004, 02:09 PM
Ok Im kinda new to maxscript.
The code below basically takes 4 x point3 values and tests for an intersection between 2 lines. It then returns a point3 value of the point of intersection or undefined if the lines dont intersect.
fn pointintersect point1 point2 point3 point4 =
result = undefined
if point1 != point2 and point2 != point3 and point3 != point4 and point4 != point1 and point1 != point3 and point2 != point4 then
b1 = ((point2.y)-(point1.y))/((point2.x)-(point1.x))
b2 = ((point4.y)-(point3.y))/((point4.x)-(point3.x))
a1 = (point1.y)-b1*(point1.x)
a2 = (point3.y)-b2*(point3.x)
xi = 0
xi = xi - (a1-a2)/(b1-b2)
yi = a1+b1*xi
if ((point1.x)-xi)*(xi-(point2.x))>=0 AND ((point3.x)-xi)*(xi-(point4.x))>=0 AND ((point1.y)
yi)*(yi-(point2.y))>=0 AND ((point3.y)-yi)*(yi-(point4.y))>=0 then
result = [xi,yi,0]
result = undefined
else result = undefined
The problem is sometimes I get a point3 return of [-.#IND,-.#IND,0] in max 4.
Max 6 seems to treat this as undefined. This happens when there should be an intersection.
The only help I could find on #IND in the maxscript reference is the small part you see below.
Quoted from maxscript reference.
"A Float in MAXScript has an absolute value range of is 1.18E-38 to 3.40E38, with a precision of one part in 1.0E7. If you perform calculations that result in floats with an absolute value less than this range, the result will be stored as 0.0. If you perform calculations that result in floats with an absolute value larger than this range, the result will be stored as a special value that represents infinity, 1.#INF. Adding, subtracting, or multiplying a number by 1.#INF results in a value of 1.#INF. Dividing a number by 1.#INF results in a value of 0.0. Dividing 0.0 by 0.0 or 1.#INF by 1.#INF, multiplying 1.#INF by 0, or 1.#INF from 1.#INF results in a special value that represents an indeterminate number, -1.#IND. Adding, subtracting, multiplying, or dividing a number by -1.#IND results in a value of -1.#IND."
It seems that part of the intersection formula generates an infinate float which then at some point becomes an indeterminate number. I'n not sure where to look. How would I be creating an infinate number.
I hope someone here can help me. I will keep looking around the net for resources and report back on any finds.
11 November 2004, 07:08 PM
I would suggest calculating and printing out intermediate results for all parts of all calculations you are performing and then watching the results. Just like you built intermediate values b1,b2, a1,a2, you can split the divisions into even smaller blocks and use print or format statements to output them and watch in the Listener.
Most probably you will have to add IF checks against divisions by zero everywhere you are dividing by a calculated value, and substitute the otherwise Indeterminate value with 0 or whatever is logical in that case...
11 November 2004, 04:27 AM
I'll try that.
11 November 2004, 01:06 PM
It all clicked with me today.
Of course it would return an infinate number.
Not sure whether to test for intermediate results of 0 and replace with something like .00000001, to replace the results of the division with 0, or to write some more code to deal with intersections of lines where one line has two coordinates with the same value.
I thought I would show what I am trying to do, Its exciting for me.
The idea of the script is to first draw shapes using the mouse like this.
And then convert those shapes into polygons like this.
I still have a lot to sort out. The infinate number problem means that sometimes it doesnt detect an intersection. There is a lot of speed optimization to do. Also I want to add some small features such as previewing and deleting of strokes.
11 November 2004, 01:20 PM
looks very interesing mr3dguy
11 November 2004, 03:14 PM
I'd like to know what approch you are following to convert the mouse storke to geometry?
I.e your algorithm and flow chart.
11 November 2004, 11:59 PM
Feel free to have a look at the source.
Please remember this is copyright, If you modify it for your personal use please post back here so others can have a look.
I am hoping to include an example of the script in my showreel. Do you guys think I should?
Im kind of "cheating" in that im using a surface modifier to convert splines into geometry. I was going to write code to create the polys, but it would take longer than the surface modifier and would probably just be a waste of time writing it.
It records mouse strokes as arrays then compares the points in those arrays to test for an intersection. If there is an intersection it creates a knot in a spline at that point.
11 November 2004, 11:04 AM
Fixed the infinate number bug. It works how its meant to.
Also added a progress bar.
I put If statements to check for zeros which means it takes longer to calculate now.
So speed optimizations are needed more so.
01 January 2006, 01:00 AM
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.