@Override public void setModel(LinePolar2D_F32 lineParam) { UtilLine2D_F32.convert(lineParam,line); theta = lineParam.angle; }
/** * Compute the parameterized coordinate for the line */ public void lineToCoordinate(LineParametric2D_F32 line , Point2D_F64 coordinate ) { line = line.copy(); line.p.x -= originX; line.p.y -= originY; LinePolar2D_F32 polar = new LinePolar2D_F32(); UtilLine2D_F32.convert(line,polar); if( polar.angle < 0 ) { polar.distance = -polar.distance; polar.angle = UtilAngle.toHalfCircle(polar.angle); } int w2 = transform.width/2; coordinate.x = (int)Math.floor(polar.distance*w2/r_max) + w2; coordinate.y = polar.angle*transform.height/Math.PI; }
private static void mergeIntoA( LineSegment2D_F32 a , LineSegment2D_F32 b ) { LineParametric2D_F32 paraA = UtilLine2D_F32.convert(a,(LineParametric2D_F32)null); Point2D_F32 pts[] = new Point2D_F32[4]; float t[] = new float[4]; pts[0] = a.a; pts[1] = a.b; pts[2] = b.a; pts[3] = b.b; for( int i = 0; i < 4; i++ ) t[i] = ClosestPoint2D_F32.closestPointT(paraA,pts[i]); float min = t[0]; float max = min; int indexMin = 0; int indexMax = 0; for( int i = 1; i < 4; i++ ) { float v = t[i]; if( v < min ) { min = v; indexMin = i; } if( v > max ) { max = v; indexMax = i; } } // set the first line to the extreme points on each line a.a.set(pts[indexMin]); a.b.set(pts[indexMax]); }
/** * Lines are found in polar form and this coverts them into line segments by finding * the extreme points of points on the line. * * @param matchSet Set of points belonging to the line. * @param model Detected line. * @return Line segement. */ private LineSegment2D_F32 convertToLineSegment(List<Edgel> matchSet, LinePolar2D_F32 model) { float minT = Float.MAX_VALUE; float maxT = -Float.MAX_VALUE; LineParametric2D_F32 line = UtilLine2D_F32.convert(model,(LineParametric2D_F32)null); Point2D_F32 p = new Point2D_F32(); for( Edgel e : matchSet ) { p.set(e.x,e.y); float t = ClosestPoint2D_F32.closestPointT(line,e); if( minT > t ) minT = t; if( maxT < t ) maxT = t; } LineSegment2D_F32 segment = new LineSegment2D_F32(); segment.a.x = line.p.x + line.slope.x * minT; segment.a.y = line.p.y + line.slope.y * minT; segment.b.x = line.p.x + line.slope.x * maxT; segment.b.y = line.p.y + line.slope.y * maxT; return segment; }