Home > track > getCollidedCells.m

getCollidedCells

PURPOSE ^

SYNOPSIS ^

function [cce1, cce2] =getCollidedCells (mergeCell,ce1,ce2)

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function  [cce1, cce2] =getCollidedCells (mergeCell,ce1,ce2)
0002 
0003 
0004 x0 = mergeCell.Col;
0005 y0 = mergeCell.Row;
0006 % fx = x0 + BFD(1);
0007 % fy = y0 + BFD(2);
0008 % theta_p = atan2(fx - x0,fy - y0);
0009 theta_p = mergeCell.Shape(1)*pi/180;
0010 majorAxis = mergeCell.Shape(2)/2;
0011 minorAxis = mergeCell.Shape(3)/2;
0012 % Including area as a way to refine position
0013 
0014 area1 = (ce1.Area/ (ce1.Area + ce2.Area) )* mergeCell.Area;
0015 area2 = (ce2.Area/ (ce1.Area + ce2.Area) )* mergeCell.Area;
0016 
0017 % d1 = sqrt(area1/pi);
0018 % d2 = sqrt(area2/pi);
0019 d1 = sqrt( (majorAxis*minorAxis) / (1+ (area1/area2)));
0020 d2 = sqrt( (majorAxis*minorAxis) / (1+ (area2/area1)));
0021 
0022 x1_offset = d2*cos(theta_p);
0023 y1_offset = d2*sin(theta_p);
0024 x2_offset = d1*cos(theta_p);
0025 y2_offset = d1*sin(theta_p);
0026 
0027 
0028 
0029 p1x = x0 + x1_offset;
0030 p1y = y0 - y1_offset;    
0031 
0032 
0033 p2x = x0 - x2_offset;
0034 p2y = y0 + y2_offset;    
0035  
0036 
0037 
0038 dis1 = sqrt((p1x - ce1.Col)^2 + (p1y - ce1.Row)^2) + ...
0039        sqrt((p2x - ce2.Col)^2 + (p2y - ce2.Row)^2) ;
0040 dis2 = sqrt((p2x - ce1.Col)^2 + (p2y - ce1.Row)^2) + ...
0041        sqrt((p1x - ce2.Col)^2 + (p1y - ce2.Row)^2) ;
0042    
0043 % dis1 = abs(p1x - ce1.Col) + abs(p1y - ce1.Row) + ...
0044 %        abs(p2x - ce2.Col) + abs(p2y - ce2.Row) ;
0045    
0046 
0047 % dis2 = abs(p2x - ce1.Col) + abs(p2y - ce1.Row) + ...
0048 %        abs(p1x - ce2.Col) + abs(p1y - ce2.Row) ;
0049 
0050 
0051 if dis1 <= dis2
0052     cce1 = WBC(mergeCell.Frame, mergeCell.Id, p1y, p1x, ce1.Area, 0);
0053     cce2 = WBC(mergeCell.Frame, mergeCell.Id, p2y, p2x, ce2.Area, 0);
0054 else
0055     cce1 = WBC(mergeCell.Frame, mergeCell.Id, p2y, p2x, ce1.Area, 0);
0056     cce2 = WBC(mergeCell.Frame, mergeCell.Id, p1y, p1x, ce2.Area, 0);
0057 end
0058 
0059 cce1.Type = ce1.Type;
0060 cce1.Status = ce1.Status;
0061 cce2.Type = ce2.Type;
0062 cce2.Status = ce2.Status;
0063 
0064 
0065 %--------- ONLY IF THE QUADRANT THING-----------------------------------
0066 % if (fx * fy) > 0
0067 %     % Quarant I and III
0068 %     p1x = x0 + x1_offset;
0069 %     p1y = y0 - y1_offset;
0070 %     p2x = x0 - x1_offset;
0071 %     p2y = y0 + y1_offset;
0072 %
0073 %     p3x = x0 - x2_offset;
0074 %     p3y = y0 + y2_offset;
0075 %     p4x = x0 + x2_offset;
0076 %     p4y = y0 - y2_offset;
0077 %
0078 % else
0079 %     % Quarant II and IV
0080 %     p1x = x0 + x1_offset;
0081 %     p1y = y0 + y1_offset;
0082 %     p2x = x0 - x1_offset;
0083 %     p2y = y0 - y1_offset;
0084 %
0085 %     p3x = x0 - x2_offset;
0086 %     p3y = y0 - y2_offset;
0087 %     p4x = x0 + x2_offset;
0088 %     p4y = y0 + y2_offset;
0089 % end
0090 %
0091 % dis1 = abs(p1x - ce1.Col) + abs(p1y - ce1.Row) + abs(p3x - ce2.Col) + abs(p3y - ce2.Row);
0092 % dis2 = abs(p2x - ce1.Col) + abs(p2y - ce1.Row) + abs(p4x - ce2.Col) + abs(p4y - ce2.Row);
0093 %
0094 % if dis1 < dis2
0095 %     cce1 = WBC(mergeCell.Frame, mergeCell.Id, p1y, p1x, area1, 0);
0096 %     cce2 = WBC(mergeCell.Frame, mergeCell.Id, p3y, p3x, area2, 0);
0097 % else
0098 %     cce1 = WBC(mergeCell.Frame, mergeCell.Id, p2y, p2x, area1, 0);
0099 %     cce2 = WBC(mergeCell.Frame, mergeCell.Id, p4y, p4x, area2, 0);
0100 % end
0101 %--------- ONLY IF THE AREA ARE THE SAME-----------------------------------
0102 % area = mergeCell.Area;
0103 % d = sqrt(area/pi)/2;
0104 % x_offset = d*cos(theta_p);
0105 % y_offset = d*sin(theta_p);
0106 %
0107 % if (fx * fy) > 0
0108 %     % Quarant I and III
0109 %     p1x = x0 + x_offset;
0110 %     p1y = y0 - y_offset;
0111 %
0112 %     p2x = x0 - x_offset;
0113 %     p2y = y0 + y_offset;
0114 %
0115 %
0116 % else
0117 %     % Quarant II and IV
0118 %     p1x = x0 + x_offset;
0119 %     p1y = y0 + y_offset;
0120 %
0121 %     p2x = x0 - x_offset;
0122 %     p2y = y0 - y_offset;
0123 %
0124 % end
0125 %
0126 %
0127 % dis1 = abs(p1x - ce1.Col) + abs(p1y - ce1.Row) + abs(p2x - ce2.Col) + abs(p2y - ce2.Row);
0128 % dis2 = abs(p1x - ce2.Col) + abs(p1y - ce2.Row) + abs(p2x - ce1.Col) + abs(p2y - ce1.Row);
0129 %
0130 % if (dis1 < dis2)
0131 %     p1 = [p1x p1y];
0132 %     p2 = [p2x p2y];
0133 % else
0134 %     p1 = [p2x p2y];
0135 %     p2 = [p1x p1y];
0136 % end
0137 %--------------------END---------------------------------------------------
0138 end

Generated on Thu 17-Mar-2011 14:45:51 by m2html © 2005