adanhancock

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]

)

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.

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.