1

enter image description hereI created a shape. It will be a room.

here is the code:

        room = new Sprite();
        room.graphics.beginFill(0xFFFF00, 1);
        room.graphics.moveTo(0, 0);
        room.graphics.lineTo(0, 500);
        room.graphics.lineTo(500, 500);
        room.graphics.lineTo(500, 250);
        room.graphics.lineTo(300, 250);
        room.graphics.lineTo(300, 0);
        room.graphics.endFill();
        addChild(room);

and i have a red rectangle at the middle. I wanna know which wall and two point is close to this rectangle. For example: in this screenshot left wall is nearest.

Thank you

Ahmet Alsan
  • 624
  • 1
  • 5
  • 10

1 Answers1

3

This is not an actionscript question at all. You need just an algorithm.

Simple solution: find center of the object and then use any line distance algorithm you can find to check this center point distance to all room edges.

For example this: Shortest distance between a point and a line segment

Community
  • 1
  • 1
Petr
  • 3,214
  • 18
  • 21
  • 1
    I would add to this that to be able to check your room and red rectangle you need to store it as collection of points which then you will be able to run through and compare. – Lukasz 'Severiaan' Grela Oct 04 '12 at 11:55