javascript - drawing a line in google maps perpendicular to two points -


i have 2 coordinates draw perpendicular line of equal length. there either simple google maps offset or clean javascript approach might accomplish this? be?

here have far. can see, plot 2 points markers , attempt draw line between them, except need line perpendicular line between 2 coordinates.

var locations = [     ['', position.coords.latitude, position.coords.longitude, 1],     ['', llat, llng, 2] ];    var marker, i;    ( var = 0; < locations.length; i++ )   {       marker = new google.maps.marker({         position: new google.maps.latlng(locations[i][1], locations[i][2]),         map: map       });   }      var borderplancoordinates = [         new google.maps.latlng(llat, position.coords.longitude),         new google.maps.latlng(position.coords.latitude,llng)     ];      var borderpath = new google.maps.polyline({       path: borderplancoordinates,       strokecolor: "#ff0000",       strokeopacity: 1.0,       strokeweight: 10,       map: map     });     borderpath.setmap(map); 

so have 2 points coordinates (x1,y1) , (x2, y2) , want draw line segment length distance between them, perpendicular bisector of segment connecting them, , bisected said segment?

probably simplest way set cx = (x1 + x2)/2, cy = (y1+y2)/2), dx = (x2-x1)/2, dy = (y2-y1)/2 , draw line (cx-dy, cy+dx) (cx+dy, cy-dx).

this works because (cx, cy) midpoint of segment want, , you're taking vector midpoint (x2,y2) , rotating plus , minus 90 degrees find endpoints of segment want draw.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -