Sg2.0
Offsetting Points
Recent RSS
Offsetting Points
From:  Thijs
Date:  16. May 2007, 11:16
Hey all,

I've got another question. I'm trying to offset points from a path, with an equal distance from the path. To accomplish this I need to know the angle(direction) of the point. Is there an easy way to get to know this? I do think it's possible to get to know the direction, by measuring the distance between two points that are very close together, but I was wondering if there is an easier (better) way. I've attached an image.

Thanks in advance!

Thijs.
Re: Offsetting Points
From:  Lehni
Date:  17. May 2007, 00:39
There is indeed a better way to do this:

Look at the curve object. It has methods to retrieve tangent and normal vectors at any given point of the curve. The values are exact, as there is a way to mathematically calculate these without any approximation.
Re: Offsetting Points
From:  Thijs
Date:  17. May 2007, 08:39
Thanks once again for the help!
Re: Offsetting Points
From:  neverblink
Date:  17. May 2007, 12:53
the Stitch-script on this site uses getNormal() and normalize() for this.

example:

var art = new Path();
art.moveTo(500,500);
art.curveTo(500,250,250,500,250,500);
var art_copy = art.clone();
art_copy.curvesToPoints(50);

/* 
curvesToPoints() used for this example, 
but this doesn't give you a nice distribution 
of points along the path.
*/

var count = art_copy.curves.length;
for (var k = 0; k < count; k++) {
	var res = new Path();
        var bezier = art_copy.curves[k];
        var pt = bezier.getPoint(0);
	res.moveTo(pt);
    	var n = bezier.getNormal(0).normalize(10); 
    	// normalize(10) = offset from shape : 10 pts
	if(n.x != 0 || n.y != 0){
        	res.segments.add(pt.add(n));
	}
}
art_copy.remove();
activeDocument.redraw();
 
Scripts
13.10.08, 01:28
03.10.08, 00:01
18.09.08, 20:43
16.09.08, 21:36
14.09.08, 18:50
Posts
03.01.09, 20:57
02.01.09, 20:40
29.12.08, 18:05
29.12.08, 10:20
27.12.08, 14:28
crowdomatic0.2 01.03.08
by gs
If you use Scriptographer regularly, please consider making a donation via PayPal: $$$ €€€ £££ CHF