Object Intersection

 03 March 2013 #1 Unik Frequenter portfolio Nikita Saini New Delhi, India   Join Date: Feb 2009 Posts: 198 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 ? Does anybody know a better alternate for it? __________________ --Nikita Saini http://www.nikitasaini.co.nr/ share quote
 03 March 2013 #2 BuzzD New Member portfolio Melk Karne Yoghurtdorp, NE   Join Date: Feb 2012 Posts: 18 Hi, http://forums.cgsociety.org/archive.../t-1026448.html distance() MaxScript Help -Node Common Bounding Box Methods -nodeGetBoundingBox() hope that helps... share quote
 03 March 2013 #3 Unik Frequenter portfolio Nikita Saini New Delhi, India   Join Date: Feb 2009 Posts: 198 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. __________________ --Nikita Saini http://www.nikitasaini.co.nr/ share quote
 03 March 2013 #4 senor freebie Frequenter James Rowlands Technical Artist Melbourne, Australia   Join Date: Sep 2003 Posts: 224 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: VertArray2 = for vertINT = 1 to snapshot2.numverts collect meshop.getVert SnapShot2 vertINT-- node: --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]) `````` __________________ http://blog.senorfreebie.com My own self-interested promotion of technical ramblings and portfolio updates. share quote
 03 March 2013 #5 senor freebie Frequenter James Rowlands Technical Artist Melbourne, Australia   Join Date: Sep 2003 Posts: 224 Also; I just realised that while my script does what your drawing requests there are another few concerns:It will get a higher minimum distance if the objects intersect, than if they are immediately adjacent.'snapshot' may not be the most efficient way to get vertex position data:If your objects are already meshes then there is no need to make a snapshotI forgot to delete the snapshots from the scene!I didn't test for objects that can be turned into a snapshot, that don't have verts, nor if the verts have faces. __________________ http://blog.senorfreebie.com My own self-interested promotion of technical ramblings and portfolio updates. share quote
 03 March 2013 #6 Unik Frequenter portfolio Nikita Saini New Delhi, India   Join Date: Feb 2009 Posts: 198 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 . Is there any other expression/command we might be overlooking? __________________ --Nikita Saini http://www.nikitasaini.co.nr/ share quote
 03 March 2013 #7 senor freebie Frequenter James Rowlands Technical Artist Melbourne, Australia   Join Date: Sep 2003 Posts: 224 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). __________________ http://blog.senorfreebie.com My own self-interested promotion of technical ramblings and portfolio updates. share quote
 03 March 2013 #8 Unik Frequenter portfolio Nikita Saini New Delhi, India   Join Date: Feb 2009 Posts: 198 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.. __________________ --Nikita Saini http://www.nikitasaini.co.nr/ share quote
 03 March 2013 #9 senor freebie Frequenter James Rowlands Technical Artist Melbourne, Australia   Join Date: Sep 2003 Posts: 224 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'. __________________ http://blog.senorfreebie.com My own self-interested promotion of technical ramblings and portfolio updates. share quote
 03 March 2013 #10 Unik Frequenter portfolio Nikita Saini New Delhi, India   Join Date: Feb 2009 Posts: 198 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 ' works pretty well. The thing I do not know yet is how do I get the AB distance...? __________________ --Nikita Saini http://www.nikitasaini.co.nr/ share quote
 03 March 2013 #11 AlexeyGapon Veteran   portfolio Alexey Gapon Kiev, Ukraine   Join Date: Mar 2013 Posts: 41 It is very hard for me to explain it in english but i will try. First of all you have to understand that there is no simple solution to this task. I understand that it is necessary to carry out the calculations for any two objects not only for simple objects like boxes or spheres. And the script also should calculate how much distance one object intersected with another object. For this I would use voxels. Imagine that your object is recreated with boxes or spheres. Less size of the box or a sphere then the recreated object would be more like your one. But in programming you just need to use a point and a distnce to closest point but the distance should be the same for all points. For example crystal lattice of carbon is the most accurate voxel object. But you don`t need to build the voxel model you can create an array with coordinates of this points. share quote
 03 March 2013 #12 AlexeyGapon Veteran   portfolio Alexey Gapon Kiev, Ukraine   Join Date: Mar 2013 Posts: 41 I think you should use voxels. I would create virual voxel models and compare them. share quote
 05 May 2013 #13 KingMax02 Veteran portfolio iSport TA XPEC SuZhou, Taiwan   Join Date: Jun 2006 Posts: 50 AlexeyGapon: How to build voxel models? __________________ mailTo:kingmax.res@gmail.com share quote
 05 May 2013 #14 CGTalk Moderation Expert   Join Date: Sep 2003 Posts: 1,066,473 Thread automatically closed 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. share quote

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off CGSociety Society of Digital Artists www.cgsociety.org Powered by vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.