Detect whether there is an obstacle between objects

Detect whether there is an obstacle between objects

yokota_t
Not applicable
590 Views
11 Replies
Message 1 of 12

Detect whether there is an obstacle between objects

yokota_t
Not applicable

[ FlexSim 22.0.4 ]

Hello all,

I'm trying to simulate radio communication in FlexSim.

I need to detect whether there is an obstacle between objects.

Specifically, I want to detect whether there is an object that overlaps the line connecting the centers of the wireless terminal objects. The CAD shape of the object can be ignored and assumed to be rectangular a cuboid.

What would be the best way to do this?

Thank you.

0 Likes
Accepted solutions (1)
591 Views
11 Replies
Replies (11)
Message 2 of 12

jason_lightfoot_adsk
Autodesk
Autodesk
In 3D? Line intersecting cuboid?
0 Likes
Message 3 of 12

yokota_t
Not applicable
Yes, in 3D. I'll fix my post.
0 Likes
Message 4 of 12

moehlmann_fe
Collaborator
Collaborator
Accepted solution

The line goes through the coboid if it intersects with any of its faces. Each face defines a plane in 3D space. The intersection point of the line with that plane (if not parallel) can be calculated relatively easily. You then have to check whether that point is part of the surface.

The math is summarized pretty well under the following link:

https://www.wikiwand.com/en/Line%E2%80%93plane_intersection

If you take the vectors that define the plane to be equal to the edges of the object (vectors between corner points) then the line intersects the face if 0 <= u <= 1 and 0 <= v <= 1, as mentioned on the linked page.
1656416156877.png1656416212328.pngpnm is the vector between the points pm and pn, same goes for lab.

In the Flexsim the Vec3 Class offers all necessary methods for these calculations. The 'getLocation()' method can be used to get the corner points of the object, serving as p0, p1 and p2.

Message 5 of 12

yokota_t
Not applicable

Thank you for your response.

I understood the mathematical theory.

So, should I use this decision method to all objects that can intersect the radio communication path?

0 Likes
Message 6 of 12

moehlmann_fe
Collaborator
Collaborator

Depends on how many objects there are. In general, I would recommend to first to a rough check (distance from object center to line) to see if an intersection is possible. Only then do the check above to improve performance.

The distance can be gotten quite easily:

|pxp0| = |p1p0| * sin(α), where p1 and p2 define the line and p0 ist the objects center

1656484639945.png

0 Likes
Message 7 of 12

yokota_t
Not applicable

I see. That's a smart way.

Thank you for your great answer!

0 Likes
Message 8 of 12

jason_lightfoot_adsk
Autodesk
Autodesk

In the attached model is the approach listed above as a user command called findIntersectionsBetweenPoints() that takes two points in model space and returns a list of objects it crosses and a list of intersection points. It's called in the onDraw of the cylinder, which then draws the intersection points as green spheres on a line between two flow items that are circulating on the conveyors.

1656806931850.png

/**Custom Code*/
Vec3 L1=param(1);   //The first point of the line in model space
Vec3 L2=param(2);    // The second point of the line in model space
Array omit=param(3);   //The array of objects to omit from tests.
Vec3 L12 =L2-L1;       // The vector between the two points on the line
double lineMag=L12.magnitude;   //length of the line
Vec3 L21=L12*-1;       // The reverse vector of the line
Vec3 mid=Vec3(0.5,0.5,0.5);
Object o=model().last;
Vec3 oCen;
Vec3 L1toCen;
double dist=0;
string pathstr;
double objDiagLen;
Array objects=[];
Array intersections=[];
forobjecttreeunder(model()){
  if (getdatatype(a)==DATATYPE_OBJECT&& omit.indexOf(a)==-1){
    pathstr=nodetopath(a,1);
    if (not(pathstr.startsWith("MODEL:/Tools"))){
      o=a;
      oCen=o.getLocation(mid);  //get the centre point of the object's oriented bounding box (OBB)
      L1toCen=oCen-L1;          // the vector from the start of our line to the object centre
      dist=L1toCen.cross(L12).magnitude/lineMag;   // distance of the centre to out line at the shortest point
      objDiagLen=sqrt(sqr(o.size.x)+sqr(o.size.y)+sqr(o.size.z));  // the length of the OBB diagnonal.
      int possIntersect=dist<objDiagLen/2;   //  could it intersect the line  1/0
      if (possIntersect){  
        int intersected=0;
        Vec3 pa0=o.getLocation(0,0,0).project(o.up,model());
        Vec3 pa1=o.getLocation(1,0,0).project(o.up,model());
        Vec3 pa2=o.getLocation(0,1,0).project(o.up,model());
        Vec3 pa3=o.getLocation(0,0,1).project(o.up,model());
        Vec3 pb0=o.getLocation(1,1,1).project(o.up,model());
        Vec3 pb1=o.getLocation(0,1,1).project(o.up,model());
        Vec3 pb2=o.getLocation(1,0,1).project(o.up,model());
        Vec3 pb3=o.getLocation(1,1,0).project(o.up,model());
        Array planes=   [[pa0,pa1-pa0,pa2-pa0] 
                        ,[pa0,pa1-pa0,pa3-pa0] 
                        ,[pa0,pa2-pa0,pa3-pa0] 
                        ,[pb0,pb1-pb0,pb2-pb0] 
                        ,[pb0,pb1-pb0,pb3-pb0] 
                        ,[pb0,pb2-pb0,pb3-pb0]];
        for (int n=6;n>0;n--){   //  Use  n>0&&!intersected  if you don't want all the intersection points
          Vec3 p0=planes[1];   //common corner point in model space
          Vec3 p01=planes[2];   //vector along edge1
          Vec3 p02=planes[3];    //vector along edge2
          double denom=L21.dot(p01.cross(p02));
          if (denom==0) //no solution
            continue;
          double t=p01.cross(p02).dot(L1-p0)/denom;
          double u=p02.cross(L21).dot(L1-p0)/denom;
          double v=L21.cross(p01).dot(L1-p0)/denom;
          if (u>=0&&u<=1&&v>=0&&v<=1&&t>=0&&t<=1) {    //solution is in this plane of the OBB
            intersected=1;
            objects.push(o);
            intersections.push(L1+L12*t);
          }
        }
      }
    }
  }
}
return [objects, intersections];

ObjectsBetweenTwoPoints.fsm

0 Likes
Message 9 of 12

joerg_vogel_HsH
Mentor
Mentor

@Yokota T , @Jason Lightfoot , @Felix Möhlmann I thought I share an idea to this subject to you. If think it is matter of raytracing of a light source. If I am not totally wrong, the math is already part of raytracing property.
@Phil BoBo, is there a possibility to get access to results of raytracing graphic engine to identify surface result coordinates?

0 Likes
Message 10 of 12

philboboADSK
Autodesk
Autodesk

The OptiX ray tracing engine that is used by RTX Mode is specifically implemented in the Engine to render the 3D view. It isn't accessible generally to a modeler to use for arbitrary calculations.

You could use the Module SDK or DLL Maker to implement a ray tracer to do arbitrary calculations if you wanted, but it's probably simpler to just write a mathematical function to calculate what you want.



Phil BoBo
Sr. Manager, Software Development
Message 11 of 12

yokota_t
Not applicable
@Jason Lightfoot , Thank you for your very interesting model! It will definitely be helpful.
0 Likes
Message 12 of 12

yokota_t
Not applicable
@Joerg Vogel , @Phil BoBo Thank you for the interesting idea! But I am not used to using SDK. I will write a function in FlexScript.
0 Likes