Quantcast
Channel: Adobe Community: Message List
Viewing all articles
Browse latest Browse all 83883

Re: Convert 'almost smooth' and 'actually sharp' points to real ones

$
0
0

in function the angle is a radian measurement.

6.28319 radians = approx 360 deg

so 3.14 or Pi = 180 deg

so 1 degree is approx 0.0174533 radians.

 

with a handle rotated 1 degree off smooth (179deg)

set t = 0.018 to get isSmooth to return false

set t = 0.017 to get isSmooth to return true


I did not mean to put a 1 in there.

it should have been much smaller...


making the 2 line up and be smooth is a little tricky.

which 1 do you move, which do you keep still, or do you move both a little?

this will affect the path and change the shape.

this math hurts me a little even if it is quite basic.


switched it up a bit, make it simpler to implement

it's missing the code to actually straighten handles to exactly 180 degrees.


try this:

// by Qwertyfly...




//this is not complete!


// angle tolerance for isSmooth function
/*
    tolerance is in radians    0.0174533 = apporx 1 degree
*/
var t = 0.018;


function isSmooth(P){
    var angle = Math.abs(Math.atan2(P.leftDirection[1]-P.anchor[1],P.leftDirection[0]-P.anchor[0])                       -Math.atan2(P.rightDirection[1]-P.anchor[1],P.rightDirection[0]-P.anchor[0]));    if(angle==Math.PI){return "smooth";}else{return(angle > Math.PI - t && angle < Math.PI + t);}
}


var doc = app.activeDocument;
var sel = doc.selection;
alert(sel[0].pathPoints.length);
for(var i=0; i<sel[0].pathPoints.length; i++){    var P = sel[0].pathPoints[i];       if(isSmooth(P)=="smooth"){        if(P.pointType == PointType.SMOOTH){            alert('super smooth');        }else{            alert('locking handles to smooth');            P.pointType = PointType.SMOOTH;        }    }else if(isSmooth(P)){ //true        alert('as good as smooth\nneed to straighten to 180 & lock handles to smooth');        P.pointType = PointType.SMOOTH;        //straighten code goes here    }else{ //false        alert('smooth as bitumen\nleaving as a corner');    }
}



Viewing all articles
Browse latest Browse all 83883

Trending Articles