on distance2d (me,aPoint1,aPoint2)
vVector = vector( aPoint1[1] - aPoint2[1], aPoint1[2] - aPoint2[2], 0)
return vVector.magnitude
end
on distance2dFast (me,aPoint1,aPoint2)
-- Remember the returned distance is squared the actual distance!
-- it about 5-10% faster than distance2d
d1 = aPoint1[1] - aPoint2[1]
d2 = aPoint1[2] - aPoint2[2]
return (d1*d1) + (d2*d2)
end
-- add 512 for proper rounding
return ( bitshiftright( approx + 512, 10 ) )
end
on vector2d (me,aPoint1,aPoint2)
return aPoint2 - aPoint1
end
on normalize2d (me,aPoint)
vVector = vector( the loch of aPoint, the locv of aPoint, 0)
vVector.normalize()
return point( vVector[1], vVector[2])
end
on magnitude2d me, aPoint
vVector = vector( aPoint[1], aPoint[2], 0)
return vVector.magnitude
end
on magnitude2dFast me, aPoint
-- Remember the returned distance is squared the actual distance!
-- it about 5-10% faster than magnitude2d
a = aPoint[1]
b = aPoint[2]
return (a*a) + (b*b)
end
on get2dNormal me, aVector
-- the resulting vector is the normal, but it is not normalized.
-- all that happens is a rotate by 90 degrees.
on vectorToDegree (me,aVector)
--Lazy use of atan
return me.radToDegree( atan(aVector.locv, aVector.loch) )
end
on vectorToAngle (me,aVector)
--Lazy use of atan
return atan(aVector.locv, aVector.loch)
end
on angleToVector (me, aTheta)
return point( cos(aTheta), sin(aTheta) )
end
on dotproduct2d (me, a ,b)
return dotproduct( vector( a[1],a[2],0), vector( b[1],b[2],0) )
end
on lineToQuad (me, aA, aB, aLineWidth, aEndLineWidth)
-- makes a quad, to use for example with copyPixels, then you can draw lines with the ability to blend it.
-- aEndLineWidth is optional
on isPointInQuad(me, aQuad, aPoint)
--clockwize quad
vNextPoint = [2,3,4,1]
repeat with vVertexNum = 1 to 4
vArea = me.TriangleAreaFast(aPoint, aQuad[ vVertexNum ], aQuad[ vNextPoint[ vVertexNum ] ] )
if vArea < 0 then return 0
end repeat
return 1
end
on TriangleAreaFast(me, p, a, b )
--This function does not produce an accurate area of an triangle, but fast results determing order of points. used in isPointInQuad,
--if this result is negative: the points are counterclockwize, therefore the p lies outside of the line a-b
return (a.loch-p.loch) * (b.locv-p.locv) - (b.loch-p.loch)*(a.locv-p.locv)
end
on terminate me
end
on GetFarAngle (me,c,a,b)
--
-- |
-- |x
-- a | b
-- |___
-- c
--
-- return the radian angle of the far side of a triangle with known lengths
-- the corner of the far side of c
-- the triangle does not need to be a "right triangle"
-- CosineStatement: a2 = b2 + c2 - 2bc · cos vA
--
-- x = a*a + b*b - c*c
-- x = x / float(2*a*b)
-- x = me.InvCos(x)
--
-- return x