Contact position

I read the codeas in built manual on contact position but I didn’t get it. What I want to do is create an ellipse near the contact position.
I tried this but didn’t work. How exactly do you find the contacts position.

``````
--# Main
function setup()
w = physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT))
b = physics.body(CIRCLE,10)
b.x = WIDTH/2
b.y = HEIGHT/2
b.linearVelocity = vec2(-200,0)
b.gravityScale = 0
end

function draw()
background(0, 0, 0, 255)
fill(255, 0, 0, 255)
stroke(255, 0, 0, 255)
strokeWidth(5)
ellipse(b.x,b.y,20)
line(0,0,0,HEIGHT)
end

function collide(contact)
fill(255,0,0,255)
ellipse(contact.position.x + 100,contact.position.y + 100,40)
end
``````

And one more thing how can I find the unit vector along a certain a direction. I know the direction of vector v3 as v3=v1-v2 and I know v1 and v2. They are position vectors. I tried v3/math.abs(v3) but it only gives a positive or negative 1 which is right mathematically but in physics that’s how we find the unit vector. So is there a way to find the unit vector along v3

Try this. The ellipse command should be placed in draw function. It doesn’t get shown when it’s in the collide function

``````
--# Main
function setup()
cx=0
cy=0
w = physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT))
b = physics.body(CIRCLE,10)
b.x = WIDTH/2
b.y = HEIGHT/2
b.linearVelocity = vec2(-200,0)
b.gravityScale = 0
end

function draw()
background(0, 0, 0, 255)
fill(255, 0, 0, 255)
stroke(255, 0, 0, 255)
strokeWidth(5)
ellipse(b.x,b.y,20)
line(0,0,0,HEIGHT)
if cx>0 and cy>0 then
ellipse(cx,cy,40)
end
end

function collide(contact)
fill(255,0,0,255)
cx=contact.position.x
cy=contact.position.y
end

``````