I am developing a Building Plan Drawing Application in HTML5. For that I needed to place the doors and windows on walls. Usually, the walls (lines) are not straight. How can I find if my mouse has touched the walls (lines) while moving the door Image. Moreover, I should find the X, Y and angle of the door to be drawn. Please help...
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
Here's one way:
Save all your line segments (walls) in an array.
When you are dragging your window into place, compare the mouse position to the nearest point on every line segment (wall). Place the window on whichever wall is closest to the mouse.
This function will give you the closest point to the mouse on any given line segment:
And this function will return the distance between 2 points (those 2 points being the mouse position and the calculated point on a wall).
Finally, google the built-in javascript
Math.atan2
to get the angle of your wall to use as the angle of your window.Good luck with your project!