classdef Sphere < handle % Simple sphere object. % Used to be fitted to glenoid points. % % This class could be used elsewhere and the constructor % access might be widen. properties center = []; radius = []; residuals = []; R2 = []; RMSE = []; end methods function obj = Sphere(varargin) if nargin == 2 obj.center = varargin{1}; obj.radius = varargin{2}; end end function fitTo(obj,points) [center,radius,residuals,R2] = fitSphere(points); obj.center = center'; obj.radius = radius; obj.residuals = residuals; obj.R2 = R2; obj.RMSE = norm(residuals)/sqrt(length(residuals)); end function output = isempty(obj) output = any(cellfun(@(field)isempty(obj.(field)),fields(obj))); end function output = polarTangentPoint(obj, polePoint, slicePlaneNormal,... polarPointOrientation) poleToCenter = Vector(polePoint, obj.center); assert(poleToCenter.norm > obj.radius, "Pole point is inside sphere and doesn't have any tangent."); poleToCenterPerpendicular = poleToCenter.cross(slicePlaneNormal).orientToward(polarPointOrientation).direction; tangentPointAngle = acos(obj.radius/poleToCenter.norm); polarTangentPoint = obj.center + ... obj.radius*sin(tangentPointAngle)*poleToCenterPerpendicular + ... obj.radius*cos(tangentPointAngle)*(-poleToCenter.direction); output = polarTangentPoint; end function exportPly(obj, filename) sphereToExport = BinarySphere(round(obj.radius), round(obj.center)); sphereToExport.exportPly(filename); end end end