PDA

View Full Version : Trouble with infinate / indeterminate floats.

 mr3dguy11-27-2004, 01:09 PMOk 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] ) else result = undefined ) else result = undefined result ) " 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.
Bobo
11-27-2004, 06: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...

mr3dguy
11-28-2004, 03:27 AM
Thanks Bobo

I'll try that.

mr3dguy
11-28-2004, 12: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.

http://www.alexgomersall.com/users/mr3dguy//edgesketch/edgesketch-1.jpg

And then convert those shapes into polygons like this.

http://www.alexgomersall.com/users/mr3dguy/edgesketch/edgesketch-2.jpg

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.

marktsang
11-28-2004, 12:20 PM
looks very interesing mr3dguy

xcvbnm
11-28-2004, 02: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.
Looks interesting...

mr3dguy
11-28-2004, 10:59 PM
Feel free to have a look at the source.

http://www.alexgomersall.com/users/mr3dguy/edgesketch/edgesketch6.ms

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.

mr3dguy
11-29-2004, 10:04 AM
Update:

http://www.alexgomersall.com/users/mr3dguy/edgesketch/edgesketch7.ms

Fixed the infinate number bug. It works how its meant to.