[OpenLayers-Users] Get point on line?
shane_china
xiaying4415139 at 163.com
Wed Apr 29 11:15:19 EDT 2009
Bill Thoen wrote:
>
> shane_china wrote:
>> In openlayers,
>> I have a straight line with two endpoints. How could I get a point on the
>> line with given distance to one endpoint? Thank you.
>>
>
> You can find a point anywhere on a line by using a ratio calculation.
> Start with the distance to your point divided by the total distance of
> your line, then your new X coordinate = the difference between the X
> coordinates of the endpoints times the ratio (plus the X coordinate of
> the starting line endpoint. For example, if your endpoints are at
> coordinates (X0, Y0) and (X1,Y1) then the Cartesian distance is
>
> D = sqrt((X1-X0)*(X1-X0) + (Y1-Y0)*(Y1-Y0))
>
> Then if the ratio between this and the distance to your point is d, your
> new point's coordinates will be:
>
> X= X0+(X1-X0)*d/D
> Y=Y0+(Y1-Y0)*d/D
>
> HTH,
> - Bill Thoen
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
>
So thank you for your answer. Your advise is in X-Y coodinates. Does this
method also apply to lon lat coodinates? Our earth is a ball, so is it
different?
I haven't demonstrate it yet.
--
View this message in context: http://n2.nabble.com/Get-point-on-line--tp2739966p2741167.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list