0001 function shape = obtainShapeFromFunctional(collectiveStruct, bnd, lambda, ...
0002 vertexIndex)
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 lambdaVector = [collectiveStruct(:).lambda];
0027 baseIndex = find(lambdaVector <= lambda, 1, 'last');
0028
0029
0030 baseShape = collectiveStruct(baseIndex);
0031 shape.hrep = struct('A', baseShape.hrep.A, 'h', baseShape.hrep.h - ...
0032 (lambda - baseShape.lambda));
0033 shape.lambda = lambda;
0034 shape.edgeLengthVector = baseShape.edgeLengthFunctional(shape.hrep.h);
0035 shape.vrep = baseShape.vrepFunctional(shape.hrep.h);
0036
0037
0038 if ~exist('vertexIndex', 'var') || isempty(vertexIndex) || vertexIndex == 0
0039
0040 shape.distanceVector = computeDistanceFromHrep2D(shape.hrep, shape.vrep, ...
0041 [bnd.cartX; bnd.cartY]);
0042 else
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 originalEdgeFilter = collectiveStruct(1).incidenceMatrix(:, vertexIndex);
0064 originalEdgeNormalMatrix = collectiveStruct(1).hrep.A(originalEdgeFilter, :)';
0065
0066
0067
0068 normalAngleVector = convertCartToPolar(originalEdgeNormalMatrix(1,:), ...
0069 originalEdgeNormalMatrix(2, :));
0070 if diff(normalAngleVector) < pi
0071 meanAngle = mean(normalAngleVector);
0072 shape.angleRatio = (max(normalAngleVector) ...
0073 - min(normalAngleVector)) / 2 / pi;
0074 else
0075 meanAngle = mod(0.5*max(normalAngleVector) + ...
0076 0.5*(min(normalAngleVector)+2*pi), 2*pi);
0077 shape.angleRatio = (min(normalAngleVector) ...
0078 - max(normalAngleVector) + 2*pi) / 2 / pi;
0079 end
0080
0081
0082 scalarProductMatrix = shape.vrep.V * originalEdgeNormalMatrix;
0083 vertexIndex = find(...
0084 (abs(scalarProductMatrix(:, 1) - max(scalarProductMatrix(:, 1))) < 1e-10) & ...
0085 (abs(scalarProductMatrix(:, 2) - max(scalarProductMatrix(:, 2))) < 1e-10) );
0086 if numel(vertexIndex) ~= 1
0087 error('elk:boundary:numericalError', ['Supporting vertex for ' ...
0088 'initially adjacent edges is not found. This should not happen.']);
0089 end
0090 supportingVertex = shape.vrep.V(vertexIndex, :)';
0091
0092
0093 bisectPoint = supportingVertex + lambda*computeNormalFromAngle(meanAngle);
0094 bisectAngle = convertCartToPolar(bisectPoint(1), bisectPoint(2));
0095
0096
0097 closenessVector = abs(bnd.polarAngle - bisectAngle);
0098 bisectIndex = find(closenessVector == min(closenessVector), 1);
0099
0100
0101 halfRange = round(length(bnd.polarAngle)/10/2);
0102 sampleIndexVector = mod(...
0103 ((bisectIndex-halfRange):(bisectIndex+halfRange))-1, ...
0104 length(bnd.polarAngle)) + 1;
0105
0106
0107 shape.distanceVector = computeDistanceFromHrep2D(shape.hrep, shape.vrep, ...
0108 [bnd.cartX(sampleIndexVector); bnd.cartY(sampleIndexVector)]);
0109 end
0110
0111
0112 shape.roughness = max([0 (shape.distanceVector - lambda)]) ...
0113 + max([0 (lambda - shape.distanceVector)]);
0114 shape.squareRoughness = sqrt(max([0 (shape.distanceVector - lambda)])^2 ...
0115 + max([0 (lambda - shape.distanceVector)])^2);
0116 shape.meanSquare = mean((shape.distanceVector - lambda).^2);