Some years ago I worked for a year for a chemical company. My entire work consisted of trying to find a formula that would be enough like a patented formula to achieve the same results but would be enough different to "not violate" their patent.
The question here is could the same be done with copyright & if so how different?

E.g. the person who published a Harry Potter glossary did not in fact copy any of the original stories but was still accused of copyright violation.