Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

intersectRay confussion help please

intersectRay confussion help please

remainz
Advocate Advocate
792 Views
5 Replies
Message 1 of 6

intersectRay confussion help please

remainz
Advocate
Advocate

Help

I dont understand why I dont get a point3 out of intersectRay?

MyRay = ray $Camera001.pos $Box001.pos
intersection = intersectRay $Plane001 MyRay
$Box001.pos = intersection

 return

OK
(ray [-225.949,-153.093,273.755] [-0.0378324,0.989376,0.140368])
(ray [-250.611,491.859,365.258] [-0.612372,-0.612373,0.5])
-- Error occurred in anonymous codeblock; filename: ; position: 187; line: 8
-- Unable to convert: (ray [-250.611,491.859,365.258] [-0.612372,-0.612373,0.5]) to type: Point3

 thanks for you time

0 Likes
793 Views
5 Replies
Replies (5)
Message 2 of 6

remainz
Advocate
Advocate
It needs $Box001.pos = intersection.pos
0 Likes
Message 3 of 6

denisT.MaxDoctor
Advisor
Advisor

The error message says 8 lines, but you only show three lines of code.., where is the rest? 😉

0 Likes
Message 4 of 6

remainz
Advocate
Advocate

Thanks guys. I was getting confused about the code because the intersectRay was not working properly.
When I move the $Box001 to the intersect point it is nowhere near where it is supposed to be.
I was using a plane and all I was getting was errors so I got confused.

When I use a sphere the code works but shows that its so off target that a plane could not work.
See pics of issue where before the code the $Box is in shot 
  

remainz_0-1718636818067.jpeg

 

but after using the intersectRay position it moves way out of shot.

remainz_1-1718636818057.jpeg

 

MyRay = ray $Camera001.pos $Box001.pos
intersection = intersectRay $GeoSphere001 MyRay
$Box001.pos = intersection.pos

Is this normal behavior?

I've tried it on previous version of Max and it was the same!  

0 Likes
Message 5 of 6

denisT.MaxDoctor
Advisor
Advisor

 

delete objects
gc()

bx = box width:30 length:30 height:30 pos:[0,-15,-30]
sp = converttomesh (geosphere name:#mesh segments:8 radius:20 wirecolor:orange) + bx
delete bx

cm = targetCamera pos:[0,-200,100] target:(targetObject()) 
i_point = point name:#intersection cross:on axistripod:on wirecolor:green	
	
fn check_intersect = 
(	
	intersection = intersectray sp (ray cm.pos -cm.dir)
	if intersection != undefined do 
	(
		i_point.pos = intersection.pos -- intersection point
		i_point.dir = intersection.dir -- mesh's normal in intersection point
	)
	intersection
)
	

deleteAllChangeHandlers id:#intersect_test
when transform #(sp,cm) changes id:#intersect_test obj do (check_intersect())
	
	
check_intersect()	
	
	

 

 

here's a snippet of code that should help you understand how things work.

 

Message 6 of 6

remainz
Advocate
Advocate
Awesome thanks a lot!
I learned a lot.
 
Idiots version

 

intersection = intersectray $Plane001 (ray $Camera001.pos -$Camera001.dir)
$Box001.pos = intersection.pos

 

Note "-$" not "- $"

0 Likes