# Trace equation of line in Photoshop

Is there a direct method of using the Photoshop pen tool (or any other tool) to trace the equation of a line in 2D space and create a path from it in a given domain and/or range, provided I define a Cartesian coordinate system with an origin and two axes?

It would be cool if it could do this!

No, there is no native way to do this. There might be a plugin but Photoshop does not have any graphing functionality. You're best bet is to find a graphing application that can export something like .CAD, .SVG, or .EPS.

In fact if looking for plugins you'd probably be better off looking for an Illustrator plugin than a photoshop one as equations of lines are vector in nature. You'll have to look a few up and find which works best for your system.

• Ah, thanks. A graphing program which exports SVG would be perfect, so I'll hunt around for that. – Fela Maslen Jan 14 '14 at 19:52
• MATLAB or Mathematica possibly? – horatio Jan 14 '14 at 21:45
• Sledgehammers and nuts come to mind. – Fela Maslen Jan 14 '14 at 21:50

One could be made. Its not terribly hard if you can make a few approximations. While I agree that mathematica and matlab are the ways to go for pro users. There are still some free alternatives that come to mind:

But if you insist on using a Photoshop as a hammer here you go (who am I to argue):

``````#target photoshop

var doc = app.activeDocument;

//  put t in second array item if  you dont want a  2d parametric plot
function graphMeParametrically(t) {
return new Array(
20 * Math.sin(t) + 30,
20 * Math.cos(t) +30
);
}

// plot half arc centered on 30, 30
plotLinear(0., 3.14/10, 3.14, graphMeParametrically);

// ok so we could do better by estimating the curvature of a continnious function
plotSmooth(0., 3.14/10, 3.14, 0.01, graphMeParametrically);

function plotLinear(start, step, end, func){
var points = new Array();
var index = 0;
for (var t =start;  t <= end; t+=step) {
points.push(new PathPointInfo());
points[index].kind = PointKind.CORNERPOINT;
points[index].anchor = func(t);
points[index].leftDirection = points[index].anchor;
points[index].rightDirection = points[index].anchor;
index+=1;
}
var subPath = new Array();
subPath.push(new SubPathInfo());
subPath.operation = ShapeOperation.SHAPEXOR;
subPath.closed = false;
subPath.entireSubPath = points;
}

// this is a  very dirty and naive estimation
// now updated version
function plotSmooth(start, step, end, delta, func){
var points = new Array();
var index = 0;

for (var t =start;  t <= end; t+=step) {
points.push(new PathPointInfo());
points[index].kind = PointKind.SMOOTHPOINT;

now =  func(t);
next =  func(t + step);
mag = Math.sqrt(Math.pow(next - now, 2) + Math.pow(next - now, 2)) /3;
t1 = func(t + delta);
t2 = func(t - delta);
mag2 = Math.sqrt(Math.pow(t1 - t2, 2) + Math.pow(t1 - t2, 2))
tan1 = new Array(now-mag/mag2*(t2 - t1), now-mag/mag2*(t2 - t1))
tan2 = new Array(now+mag/mag2*(t2 - t1), now+mag/mag2*(t2 - t1))
points[index].anchor = now;
points[index].leftDirection = tan1;
points[index].rightDirection = tan2;
index+=1;
}
var subPath = new Array();
subPath.push(new SubPathInfo());
subPath.operation = ShapeOperation.SHAPEXOR;
subPath.closed = false;
subPath.entireSubPath = points;