I draw the line on Canvas and want to merge svg image on line based it's position. How can I find the angle between start and end points of draw line?
Edit
This function for get Angle of Line
public angleOfWall(p1,p2){
var angleDeg = Math.atan2(p2.y - p1.y, p2.x - p1.x) * 180 / Math.PI;
return angleDeg;
}
var angleOfWall = this.angleOfWall(closestWall.getStart(), closestWall.getEnd());
After find the angle, I want to merge img to on it.
for (let i = 0; i < this.model.floorplan.items.length; i++) {
item = this.model.floorplan.items[i];
var hover = item===this.viewmodel.activeItem;
var itemWidth = item.width|32;
var itemHeight = item.height|32;
if (!item.el) {
item.el = document.createElement('img');
// draw door line on that position
item.el.src = this.model.floorplan.items[i].model_url_2d;
item.el.onload = (( /** image **/ ) => {
this.context.drawImage(item.el,
this.viewmodel.convertX(item.xpos * item.scale_x) - itemWidth/2.,
this.viewmodel.convertY(item.zpos * item.scale_z) - itemHeight/2.,
itemWidth, itemHeight);
} .("model_url2d" is SVG image's url )
private rotateSVG(rotateSVG) {
var innerArrow = document.getElementById("#add-items");
innerArrow.setAttribute("transform", rotateSVG);
}
Is it right way to follow line rotate position? Just Im new in JS side so need some help. thanks
here What I have now but want to rotate img angle as line's angle