function [d,w] = findelementdistance(centre,radius,elementindex)

%E.g., elementnodes = [11,9,8,10,170,171,168,169]

nodes = dlmread('nodePosition.csv');
elements = dlmread('Tongue Elements.elem');

elementnodes = elements(elementindex,[1:8]);

elementnodepositions = nodes(elementnodes,2:4);

cg = mean(elementnodepositions);

d = sqrt((centre(1)-cg(1)).^2+(centre(2)-cg(2)).^2+(centre(3)-cg(3)).^2);

w = max(0,min(1,(2*radius-d)/radius));