[Closed] Object Intersection
Hey Guys,
I have been trying to make a script to avoid the intersection of the objects. I want to find the largest distance between the point position of the two objects, now I am struck here. The only command I could find to measure the distance b/w the objects is ‘intersectRay’, which is also not giving me the desired result (its giving the shortest dist). Am I missing something here :shrug: ? Does anybody know a better alternate for it?
Hi,
http://forums.cgsociety.org/archive/index.php/t-1026448.html
distance()
MaxScript Help
-Node Common Bounding Box Methods
-nodeGetBoundingBox()
hope that helps…
Thank you for your reply BuzzD :).
distance() will only return me the distance between two objects (currently in the case it will calculate the distance between the pivots of the two objects), whereas in what I am looking for, is the largest distance between the points of the two objects. The image below might explain it more.
That’s going to depend a lot on what type of objects you’re measuring … and how fast you want this to run.
Let’s say it’s 2 boxes…
Personally I’d put the function into a struct so that I could just initialise that struct with 2 objects and then refer to the distance later.
The properties within that struct would allow you to verify it’s contents later: ie which objects were distance tested? What is the distance now that the meshes have moved?
I’m not sure where you are with your max scripting; or what unit setup you’re using so to be clear you only need to place the body of code below once.
The last line; GetDistance… can be called repeatedly on different object variables. You could even use it within a sort function if you needed. I’ve provided 2 boxes as a sample. My units setup is CM / CM so I get MaxDistance:92.0598 MinDistance:35.0 as an answer.
Struct STRdistance
(
Obj1,
Obj2,
MaxDistance = 0.0,
MinDistance,
fn GetSubObjDistance =
(
if isValidNode obj1 and isValidNode obj2 then
(
local Snapshot1 = snapshot obj1
local Snapshot2 = snapshot obj2
VertArray1 = for vertINT = 1 to snapshot1.numverts collect meshop.getVert SnapShot1 vertINT-- node:<node=unsupplied>
VertArray2 = for vertINT = 1 to snapshot2.numverts collect meshop.getVert SnapShot2 vertINT-- node:<node=unsupplied>
--MaxDistance
for vert1INT = 1 to VertArray1.count do
(
for vert2INT = 1 to VertArray2.count do
(
local TheDistance = distance VertArray1[Vert1INT] VertArray2[Vert2INT]
if TheDistance > MaxDistance then MaxDistance = TheDistance
)
)
MinDistance = MaxDistance
for vert1INT = 1 to VertArray1.count do
(
for vert2INT = 1 to VertArray2.count do
(
local TheDistance = distance VertArray1[Vert1INT] VertArray2[Vert2INT]
if TheDistance < MinDistance then MinDistance = TheDistance
)
)
)
),
OnStart = GetSubObjDistance()
)
GetDistance = STRdistance obj1:(box pos:[30,0,0]) obj2:(box pos:[-30,0,0])
Also;
I just realised that while my script does what your drawing requests there are another few concerns:
[ul]
[li]It will get a higher minimum distance if the objects intersect, than if they are immediately adjacent.[/li][li]‘snapshot’ may not be the most efficient way to get vertex position data:[/li][/ul][ol]
[li]If your objects are already meshes then there is no need to make a snapshot[/li][li]I forgot to delete the snapshots from the scene![/li][li]I didn’t test for objects that can be turned into a snapshot, that don’t have verts, nor if the verts have faces.[/li][/ol]
Thank you for the reply senor freebie
I tried your script, while it is returning the max distance, the distance is between the verts diagonally (there is no control here to check for the angle as well, say if we consider the image I posted earlier, I am just looking for the value of the red line, this ray would be 90 deg from the tangent).
And like you said in your last post, these limitations will be there if we go this way :argh: . Is there any other expression/command we might be overlooking? :shrug:
The direction in relation to what?
Are you looking to get the direction from the normal?
That seems like the most logical because with that you could exclude negative normals in a test (ignoring intersections).
If I have two objects, say two spheres, now I want the distance between the two from A to B (the largest between the intersecting part). Now if we flip the normals of the two spheres, could we get the distance somehow? I am just interested about the overlapping part…
So long as you’re dealing with spheres exclusively and you only want to know if they intersect why don’t you just test the distance from Sphere B’s vert to Sphere A’s center against the radius of Sphere A.
If distance Sphere B vert to Sphere A center < Sphere A radius then ‘Spheres intersect’.
No I won’t be dealing with just the spheres, I just took them as an example. And If I just need to know about whether two objects intersect or not the expression ‘intersects <node> <node>’ works pretty well.
The thing I do not know yet is how do I get the AB distance…?