3 Replies Latest reply on Apr 25, 2010 6:11 PM by xero

    Determining the angle of a line segment.

    xero

      I drew a line segment with the pen tool. How can I determine the angle of the segment drawn?

        • 1. Re: Determining the angle of a line segment.
          Michael L Hale Level 5

          Something like this...

           

             measureLine = function(path){
             var res = new Array;
             var lineStart = path.subPathItems[0].pathPoints[0].anchor; 
             var lineEnd = path.subPathItems[0].pathPoints[1].anchor;
             var a = Math.max(lineStart[0],lineEnd[0])-Math.min(lineStart[0],lineEnd[0]);
             var o = Math.max(lineStart[1],lineEnd[1])-Math.min(lineStart[1],lineEnd[1]);
             var c = Math.round(Math.sqrt((a*a)+(o*o)));
             res.push(c);
             var ang = (180/Math.PI) * Math.atan2(o,a);
             if(lineStart[1] < lineEnd[1]){//negative angle 
                ang = -ang; 
             };
             res.push(ang);
             return res;
             }
          
          
          //the above is for the pen tool. If the path was made with the line tool replace pathPoints[1] with pathPoints[3]
          
          • 2. Re: Determining the angle of a line segment.
            xero Level 1

            Thank you for the script, but where do I insert in photoshop??

            • 3. Re: Determining the angle of a line segment.
              Michael L Hale Level 5

              That was just a function to get the lenght and angle of a path.

              Here is an example sscript showing how to call that function. You save the script anywhere as plain text. If you want it to show up in the scripts menu you save it in the app/presets/scripts folder.

               

              Then with a simple line path as the work path you run the script by Choosing FIle-Scripts-nameOfScript if you saveed it in the scripts folder or File-Scripts-Browse if you saved it somewhere else.

               

              var p = app.activeDocument.pathItems.getByName('Work Path');
              alert(measureLine(p)[1]);// alert just the angle.
              function measureLine(path){
                 var res = new Array;
                 var lineStart = path.subPathItems[0].pathPoints[0].anchor; 
                 var lineEnd = path.subPathItems[0].pathPoints[1].anchor;
                 var a = Math.max(lineStart[0],lineEnd[0])-Math.min(lineStart[0],lineEnd[0]);
                 var o = Math.max(lineStart[1],lineEnd[1])-Math.min(lineStart[1],lineEnd[1]);
                 var c = Math.round(Math.sqrt((a*a)+(o*o)));
                 res.push(c);
                 var ang = (180/Math.PI) * Math.atan2(o,a);
                 if(lineStart[1] < lineEnd[1]){//negative angle 
                    ang = -ang; 
                 };
                 res.push(ang);
                 return res;
              }