double * calculateUserPositionEpta(double *xs, double *ys, double *accs) { double *result = (double *)malloc(sizeof(double) * DIMENSIONS); Points beacons = createPoints(xs, ys, accs); int iterations = 0; while (1) { if (++iterations > MAX_ITERATIONS) { return result; } int intersectionCount = 0; Points intersections = getIntersectionPoints(beacons, MIN_BEACONS, &intersectionCount); if (intersectionCount == 0) { return result; } int commonCount = 0; Points common = getCommonPoints(intersections, intersectionCount, beacons, &commonCount); if (commonCount == 2 || commonCount == 3) { Points center = getCenter(common, commonCount); result[0] = center[0].x; result[1] = center[0].y; return result; } enlargeAccuracies(beacons); } return result; }
float Circle::getIntersectionArea( const Circle &c ) const { Vector2D pos1, pos2, pos3; float d, h, dArea; AngDeg ang; d = getCenter().distanceTo( c.getCenter() ); // dist between two centers if( d > c.getRadius() + getRadius() ) // larger than sum radii return 0.0; // circles do not intersect if( d <= fabs(c.getRadius() - getRadius() ) ) // one totally in the other { float dR = min( c.getRadius(), getRadius() );// return area smallest circle return M_PI*dR*dR; } int iNrSol = getIntersectionPoints( c, &pos1, &pos2 ); if( iNrSol != 2 ) return 0.0; // the intersection area of two circles can be divided into two segments: // left and right of the line between the two intersection points p1 and p2. // The outside area of each segment can be calculated by taking the part // of the circle pie excluding the triangle from the center to the // two intersection points. // The pie equals pi*r^2 * rad(2*ang) / 2*pi = 0.5*rad(2*ang)*r^2 with ang // the angle between the center c of the circle and one of the two // intersection points. Thus the angle between c and p1 and c and p3 where // p3 is the point that lies halfway between p1 and p2. // This can be calculated using ang = asin( d / r ) with d the distance // between p1 and p3 and r the radius of the circle. // The area of the triangle is 2*0.5*h*d. pos3 = pos1.getVector2DOnLineFraction( pos2, 0.5 ); d = pos1.distanceTo( pos3 ); h = pos3.distanceTo( getCenter() ); ang = asin( d / getRadius() ); dArea = ang*getRadius()*getRadius(); dArea = dArea - d*h; // and now for the other segment the same story h = pos3.distanceTo( c.getCenter() ); ang = asin( d / c.getRadius() ); dArea = dArea + ang*c.getRadius()*c.getRadius(); dArea = dArea - d*h; return dArea; }
ROIData ROITool::computeVoxelValues(const QList<Line3D> &polygonSegments, Point3D sweepLineBeginPoint, Point3D sweepLineEndPoint, double sweepLineEnd, int inputNumber) { // We get the pointer of the pixel data to obtain voxels values from VolumePixelData *pixelData = m_2DViewer->getCurrentPixelDataFromInput(inputNumber); if (!pixelData) { return ROIData(); } OrthogonalPlane currentView = m_2DViewer->getView(); int yIndex = currentView.getYIndex(); double currentZDepth = m_2DViewer->getCurrentDisplayedImageDepthOnInput(inputNumber); double spacing[3]; pixelData->getSpacing(spacing); double verticalSpacingIncrement = spacing[yIndex]; int phaseIndex = 0; if (currentView == OrthogonalPlane::XYPlane && m_2DViewer->doesInputHavePhases(inputNumber)) { phaseIndex = m_2DViewer->getCurrentPhaseOnInput(inputNumber); } // ROI voxel data to be obtained from the sweep line ROIData roiData; while (sweepLineBeginPoint.at(yIndex) <= sweepLineEnd) { // We get the intersections bewteen ROI segments and current sweep line QList<double*> intersectionList = getIntersectionPoints(polygonSegments, Line3D(sweepLineBeginPoint, sweepLineEndPoint), currentView); // Adding the voxels from the current intersections of the current sweep line to the voxel values list addVoxelsFromIntersections(intersectionList, currentZDepth, currentView, pixelData, phaseIndex, roiData); // Shift the sweep line the corresponding space in vertical direction sweepLineBeginPoint[yIndex] += verticalSpacingIncrement; sweepLineEndPoint[yIndex] += verticalSpacingIncrement; } return roiData; }
/** * \return True if this shape intersects with the given shape. */ bool RShape::intersectsWith(const RShape& other, bool limited) const { return !getIntersectionPoints(other, limited).isEmpty(); }
/** * \return The intersection point(s) between this shape and the given * other shape. */ QList<RVector> RShape::getIntersectionPoints(const RShape& other, bool limited, bool same) const { return getIntersectionPoints(*this, other, limited, same); }