Drawing a line that can't touch itself

I found this beautiful function that allows me to draw a line on the screen with your finger, I’m trying to figure out how to make the line lose its event Listener if it touches itself, a collision. So if you drew a circle and touched the line you are drawing together it would stop drawing from the line colliding with itself. Here is the function, thanks for the help!

[lua]function runTouch(event)
if(event.phase==“began”) then
if(tempLine==nil) then
tempLine=display.newLine(event.x, event.y, event.x, event.y)
tempLine:setColor(math.random(255), math.random(255), math.random(255))
tempLine.name = ‘tempLine’
group:insert(tempLine)
prevX = event.x
prevY = event.y

end
elseif(event.phase==“moved”) then
tempLine:append(event.x,event.y-2)
tempLine.width=tempLine.width+.9
ractgangle_hit[i] = display.newLine(prevX, prevY, event.x, event.y)
ractgangle_hit[i]:setColor(math.random(255), math.random(255), math.random(255))
ractgangle_hit[i].width = 2
ractgangle_hit[i].name = ‘ractgangle_hit[i]’
group:insert(ractgangle_hit[i])

– Creates physic joints for line (Turn on draw mode to see the effects)
local Width = ractgangle_hit[i].width * 0.6
local Height = ractgangle_hit[i].height * 0.2

– Physic body for the line shape
lineShape = {-Width,-Height,Width,-Height,Width,Height,-Width,Height}
lineShape.name = ‘lineShape’
physics.addBody(ractgangle_hit[i], “static”, { bounce = 0, density=0.9, friction=0.7, shape = lineShape})
prevX = event.x
prevY = event.y
i = i + 1
elseif(event.phase==“ended”) then
tempLine.parent.remove(tempLine)
tempLine=nil
Runtime:removeEventListener(“touch”, runTouch)
end
end
Runtime:addEventListener(“touch”, runTouch) [import]uid: 75779 topic_id: 29705 reply_id: 329705[/import]

You need a line intersection function to check a list of all your lines being drawn by the move event, first find a way to make a list of all the lines from the line drawing. Then run the line intersection test against this list for any new line segments being added during the move section of the event… run this test from the oldest segment to new, your more likely to intersect with a older line. Many examples on google search of line intersection testing.

[import]uid: 118379 topic_id: 29705 reply_id: 119216[/import]

Hmmm I was hoping for something a little more specific than a google search, couldn’t really find anything Corona related. Not sure how to make a list of all the lines from the drawing. The code above is plug and play, If anyone would be able to test it out and lead me in the right direction of what to do it would be much appreciated!

russell [import]uid: 75779 topic_id: 29705 reply_id: 119226[/import]