###

» Sun Jun 03, 2012 5:25 pm

you could put your points in a family fpoint

and then

[code]Global alignement = 0

+[pick the three points you want to check with the object type point]

+[pick the three points you want to check with the family fpoint]

+system: pick point at random

local number a1 = 0 // angle between point and the first fpoint

local number a2 = 0 // angle between point and the second fpoint

+system: for each fpoint

+system: point.UID != fpoint.UID // don't pick itself

+loopindex = 0

->system: set a1 to angle(point.X,point.Y,fpoint.X,fpoint.Y)

+loopindex = 1

->system: set a2 to angle(point.X,point.Y,fpoint.X,fpoint.Y)

-> System: set alignement to min(1,abs(cos(a1)*cos(a2)+sin(a1)*sin(a2)))[/code]

Basically it should look at one of your 3 points and calculate the angle between the other two.

So if the point randomly picked is at one extremity, the angle between this point and the two others should be the same.

If the point randomly picked is the middle one, the angle should be opposite.

To compare alignement between two direction (or vectors) there's a neat operation called dot product.

If done on unit vectors (the ones with length = 1) you get a number from -1 to 1:

* 1 = aligned and pointing toward the same direction

* -1 = aligned and pointing toward opposite direction

* 0 = perpendicular

and between these values it would be a "percentage of alignement"

The formulat is:

given two vectors v1(x1,y1) and v2(x2,y2)

the dot product v1.v2 = x1*x2+y1*y2

If you have an angle 'a', the corresponding unit vector would be (cos(a),sin(a))

That's why cos(a1)*cos(a2)+sin(a1)*sin(a2) should give you the dot product.

the abs() is to have values from 0 to 1 that should give you a percentage of alignement.

you then just have to check if 'alignement' is greater than something lik 0.9 and you're done (:

Yann2012-06-03 17:28:28