A permanent magnet in which the magnetization direction varies with location to optimize or restrict a magnetic field property in a selected direction at a selected point. The magnetic field property may be, for example, the transverse magnetic field, axial magnetic field, axial gradient of the transverse magnetic field, transverse gradient of the transverse magnetic field, axis gradient of the axial magnetic field, transverse gradient of the axial magnetic field, the product of the transverse magnetic field and the transverse gradient of the transverse magnetic field, the product of the transverse magnetic field and the axial gradient of the transverse magnetic field, the product of the axial magnetic field and the transverse gradient of the axial magnetic field, or the product of the axial magnetic field and the axial gradient of the axial magnetic field. The magnet may be formed of one or more segments in which the magnetization direction varies smoothly and continuously, or the magnet may be formed of a plurality of segments in which the magnetization direction is constant. A method of making and using such magnets is also disclosed.