computePointToPointDistance() public method

public computePointToPointDistance ( Point3d otherPoint ) : double
otherPoint Point3d
return double
Beispiel #1
0
        //---------------------------------PRIVATES-------------------------------------//

        /**
         * Sets an end as vertex (starting point if none end were defined, ending point otherwise)
         *
         * @param vertex the vertex that is an segment end
         * @return false if all the ends were already defined, true otherwise
         */
        private bool setVertex(Vertex vertex)
        {
            //none end were defined - define starting point as VERTEX
            if (index == 0)
            {
                startVertex = vertex;
                startType   = VERTEX;
                startDist   = line.computePointToPointDistance(vertex.getPosition());
                startPos    = startVertex.getPosition();
                index++;
                return(true);
            }
            //starting point were defined - define ending point as VERTEX
            if (index == 1)
            {
                endVertex = vertex;
                endType   = VERTEX;
                endDist   = line.computePointToPointDistance(vertex.getPosition());
                endPos    = endVertex.getPosition();
                index++;

                //defining middle based on the starting point
                //VERTEX-VERTEX-VERTEX
                if (startVertex.equals(endVertex))
                {
                    middleType = VERTEX;
                }
                //VERTEX-EDGE-VERTEX
                else if (startType == VERTEX)
                {
                    middleType = EDGE;
                }

                //the ending point distance should be smaller than  starting point distance
                if (startDist > endDist)
                {
                    swapEnds();
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
        /**
         * Classifies the face based on the ray trace technique
         *
         * @param object object3d used to compute the face status
         */
        public void rayTraceClassify(Object3D obj)
        {
            //creating a ray starting starting at the face baricenter going to the normal direction
            Point3d p0 = new Point3d();

            p0.X = (v1.X + v2.X + v3.X) / 3.0f;
            p0.Y = (v1.Y + v2.Y + v3.Y) / 3.0f;
            p0.Z = (v1.Z + v2.Z + v3.Z) / 3.0f;
            Line ray = new Line(getNormal(), p0);

            bool    success;
            double  dotProduct, distance;
            Point3d?intersectionPoint;
            Face    closestFace = null;
            double  closestDistance;

            do
            {
                success         = true;
                closestDistance = Double.MaxValue;
                //for each face from the other solid...
                for (int i = 0; i < obj.getNumFaces(); i++)
                {
                    Face face = obj.getFace(i);
                    //dotProduct = face.getNormal().dot(ray.getDirection());

                    dotProduct = Vector3d.Dot(face.getNormal(), ray.getDirection());

                    intersectionPoint = ray.computePlaneIntersection(face.getNormal(), face.v1.getPosition());


                    //if ray intersects the plane...
                    if (intersectionPoint != null)
                    {
                        distance = ray.computePointToPointDistance(intersectionPoint.Value);

                        //if ray lies in plane...
                        if (Math.Abs(distance) < TOL && Math.Abs(dotProduct) < TOL)
                        {
                            //disturb the ray in order to not lie into another plane
                            ray.perturbDirection();
                            success = false;
                            break;
                        }

                        //if ray starts in plane...
                        if (Math.Abs(distance) < TOL && Math.Abs(dotProduct) > TOL)
                        {
                            //if ray intersects the face...
                            if (face.hasPoint(intersectionPoint.Value))
                            {
                                //faces coincide
                                closestFace     = face;
                                closestDistance = 0;
                                break;
                            }
                        }

                        //if ray intersects plane...
                        else if (Math.Abs(dotProduct) > TOL && distance > TOL)
                        {
                            if (distance < closestDistance)
                            {
                                //if ray intersects the face;
                                if (face.hasPoint(intersectionPoint.Value))
                                {
                                    //this face is the closest face untill now
                                    closestDistance = distance;
                                    closestFace     = face;
                                }
                            }
                        }
                    }
                }
            } while (success == false);

            //none face found: outside face
            if (closestFace == null)
            {
                status = OUTSIDE;
            }
            //face found: test dot product
            else
            {
                //dotProduct = closestFace.getNormal().dot(ray.getDirection());
                dotProduct = Vector3d.Dot(closestFace.getNormal(), ray.getDirection());

                //distance = 0: coplanar faces
                if (Math.Abs(closestDistance) < TOL)
                {
                    if (dotProduct > TOL)
                    {
                        status = SAME;
                    }
                    else if (dotProduct < -TOL)
                    {
                        status = OPPOSITE;
                    }
                }

                //dot product > 0 (same direction): inside face
                else if (dotProduct > TOL)
                {
                    status = INSIDE;
                }

                //dot product < 0 (opposite direction): outside face
                else if (dotProduct < -TOL)
                {
                    status = OUTSIDE;
                }
            }
        }
Beispiel #3
0
        /**
         * Classifies the face based on the ray trace technique
         *
         * @param object object3d used to compute the face status
         */
        public void rayTraceClassify(Object3D obj)
        {
            //creating a ray starting starting at the face baricenter going to the normal direction
            Point3d p0 = new Point3d();
            p0.x = (v1.x + v2.x + v3.x) / 3d;
            p0.y = (v1.y + v2.y + v3.y) / 3d;
            p0.z = (v1.z + v2.z + v3.z) / 3d;
            Line ray = new Line(getNormal(), p0);

            bool success;
            double dotProduct, distance;
            Point3d intersectionPoint;
            Face closestFace = null;
            double closestDistance;

            do
            {
                success = true;
                closestDistance = Double.MaxValue;
                //for each face from the other solid...
                for (int i = 0; i < obj.getNumFaces(); i++)
                {
                    Face face = obj.getFace(i);
                    dotProduct = face.getNormal().dot(ray.getDirection());
                    intersectionPoint = ray.computePlaneIntersection(face.getNormal(), face.v1.getPosition());

                    //if ray intersects the plane...
                    if (intersectionPoint != null)
                    {
                        distance = ray.computePointToPointDistance(intersectionPoint);

                        //if ray lies in plane...
                        if (Math.Abs(distance) < TOL && Math.Abs(dotProduct) < TOL)
                        {
                            //disturb the ray in order to not lie into another plane
                            ray.perturbDirection();
                            success = false;
                            break;
                        }

                        //if ray starts in plane...
                        if (Math.Abs(distance) < TOL && Math.Abs(dotProduct) > TOL)
                        {
                            //if ray intersects the face...
                            if (face.hasPoint(intersectionPoint))
                            {
                                //faces coincide
                                closestFace = face;
                                closestDistance = 0;
                                break;
                            }
                        }

                                    //if ray intersects plane...
                                    else if (Math.Abs(dotProduct) > TOL && distance > TOL)
                        {
                            if (distance < closestDistance)
                            {
                                //if ray intersects the face;
                                if (face.hasPoint(intersectionPoint))
                                {
                                    //this face is the closest face untill now
                                    closestDistance = distance;
                                    closestFace = face;
                                }
                            }
                        }
                    }
                }
            } while(success == false);

            //none face found: outside face
            if (closestFace == null)
            {
                status = OUTSIDE;
            }
            //face found: test dot product
            else
            {
                dotProduct = closestFace.getNormal().dot(ray.getDirection());

                //distance = 0: coplanar faces
                if (Math.Abs(closestDistance) < TOL)
                {
                    if (dotProduct > TOL)
                    {
                        status = SAME;
                    }
                    else if (dotProduct < -TOL)
                    {
                        status = OPPOSITE;
                    }
                }

                    //dot product > 0 (same direction): inside face
                    else if (dotProduct > TOL)
                {
                    status = INSIDE;
                }

                    //dot product < 0 (opposite direction): outside face
                    else if (dotProduct < -TOL)
                {
                    status = OUTSIDE;
                }
            }
        }