[OpenLayers-Users] Get point on line?

shane_china xiaying4415139 at 163.com
Sun May 10 02:55:29 EDT 2009


Bill Thoen, Thank you very much. With the help of the wiki page you give, I
success finish the function. The following is my code
function getPointOnLineByDistance(p1, p2, distance) {
	var ppp1 = new Point(p1.x, p1.y);
	var ppp2 = new Point(p2.x, p2.y);
	var bearing = ppp1.geoBearingTo(ppp2);
	var ppp3 = ppp1.geoWaypoint(distance, bearing);
	return new OpenLayers.Geometry.Point(ppp3.x, ppp3.y);
}
Many points tested, this function works well. But I don't understand the
bearing. What is the bearing meaning? In the wiki page, it describes bearing
is the angle that p1 to p2 along a great circle route. So can a bearing
determine a great circle route? If it can't, how does this
function(geoWaypoint) work? On earth, there are many points to p1 have the
same distance.


Bill Thoen wrote:
> 
> I put an article about great circle algorithms in the wiki some time ago 
> that might help you.  The links to the demos are down right now (that 
> server needs a power supply I think) but the algorithms and formulas are 
> shown on the wiki page at 
> http://trac.openlayers.org/wiki/GreatCircleAlgorithms. Hopefully that 
> will give you enough help to complete your task.
> 
> Unfortunately, I'm swamped with my own OpenLayers problems right now, so 
> I don't have any free time to help you much more than that. JavaScript 
> and OpenLayers is so much fun that it's all too easy to program yourself 
> into places you have no business being. 
> 
> But if you got the answers to all your problems immediately, your heart 
> wouldn't become purified by the long quest.
> 
> Good luck!
> 
> - Bill Thoen
> 
> 
> shane_china wrote:
>> Hi, Bill Thoen, I go to the website and find the formulary I want. As
>> following:
>> Point(s) known distance from a great circle
>> Let points A and B define a great circle route and D be a third point.
>> Find
>> the points on the great circle through A and B that lie a distance d from
>> D,
>> if they exist. 
>>    A = crs_AD - crs_AB
>>
>> ( crs_AB and crs_AD are the initial GC bearings from A to B and D,
>> respectively. Compute using Course between points) 
>>
>>    b = dist_AD
>>
>> (dist_AD is the distance from A to D. Compute using Distance between
>> points) 
>>
>>    r=(cos(b)^2+sin(b)^2*cos(A)^2)^(1/2)
>>
>> (acos(r) is the XTD) 
>>
>>    p=atan2(sin(b)*cos(A),cos(b))
>>
>> (p is the ATD) 
>>
>>    IF (cos(d)^2 > r^2) THEN
>>       No points exist
>>    ELSE
>>       Two points exist
>>      dp = p +- acos(cos(d)/r)
>>    ENDIF
>>
>> dp are the distances of the desired points from A along AB. Their
>> lat/lons
>> can be computed using Lat/lon given radial and distance 
>>
>> But I want to know, Is there any such fomulary in OpenLayers to help me
>> simplify the algorithm? For example, I know
>> "OpenLayers.Util.distVencenty",
>> this method can calculate the distance between two points. Does
>> openlayers
>> also have such functions can help me? Thank you.
>>
>> My math is not so good. Write the algorithm in js all by myself is so
>> difficult for me.
>>
>>
>>
>>
>> Bill Thoen wrote:
>>   
>>> Yes, it's a little different for the spherical (Lon/Lat) case. For those 
>>> formulas, check out Ed Williams' Aviation Formulary website at 
>>> http://williams.best.vwh.net/avform.htm. What you're looking for is 
>>> determining waypoint locations, i think.
>>>
>>> - Bill Thoen
>>>
>>> shane_china wrote:
>>>     
>>>> 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
>>>>>     
>>>>>         
>>>> 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.
>>>>   
>>>>       
>>> _______________________________________________
>>> Users mailing list
>>> Users at openlayers.org
>>> http://openlayers.org/mailman/listinfo/users
>>>
>>>
>>>     
>>
>>   
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
> 
> 

-- 
View this message in context: http://n2.nabble.com/Get-point-on-line--tp2739966p2853044.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.




More information about the Users mailing list