Sg2.9
Offsetting Points
Recent RSS
Offsetting Points
From:  Thijs Gadiot
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:  Jürg 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 Gadiot
Date:  17. May 2007, 08:39

Thanks once again for the help!

Re: Offsetting Points
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
08.08.14, 15:24
15.05.14, 14:23
02.03.14, 19:16
18.11.13, 14:48
22.03.13, 03:05
22.02.13, 15:45
Posts
10.01.17, 16:37
19.02.16, 06:03
19.02.16, 06:00
17.01.16, 11:00
12.01.16, 13:10
25.11.15, 08:19
Script of the Moment
Mosaic Staple Raster 24.03.10