我在生成的地圖圖層中的點之間動態生成WKT LineString,以便在OpenLayers中顯示。我想讓曲線之間的線條變成曲線,我希望能夠根據各種輸入變量動態改變曲率。在OpenLayers中創建彎曲的已知文本LineString
這是一個網絡監測應用程序,我們希望基於點之間的延遲時間(不是原始延遲本身,而是在給定時間段內偏離「正常」值)的曲率。
儘管一些GIS應用程序和數據庫支持WKT的CircularString
擴展,但OpenLayers並不知道任何事情。
所以我需要生成一個曲線脫節段:現在
,線串是簡單的:
LINESTRING(hop1_long hop1_lat, hop2_long hop2_lat)
唯一的辦法我能確定使線段「彎曲」是插入中間點:
LINESTRING(hop1_long hop1_lat, long1 lat1, long2 lat2, ..., hop2_long hop2_lat)
這應該完全適合我們的應用程序,但我不知道如何產生的中介點!
我假設有一些衆所周知的方法/算法用於在2D平面中生成線段之外的「彎曲」線。有沒有人有任何想法,如何做到這一點,或書籍/文章/在線資源,可能會有所幫助?
UPDATE(2010-08-13):
貝塞爾曲線是門票,貫徹基本貝塞爾算法是在它讀了之後很容易。但是我必須編寫一些代碼來生成控制點。這是我提出的PHP代碼。這假設一個「Vector2d」類,x
和y
成員。
function get_control_points($to, $from, $mag_scale, $angle) { $dirX = $to->x - $from->x; $dirY = $to->y - $from->y; $mag = sqrt(($dirX * $dirX) + ($dirY * $dirY)); if (!$mag) { return array($to, $from); } $length = $mag * $mag_scale; $dirX = $dirX/$mag; $dirY = $dirY/$mag; $sin = sin($angle); $cos = cos($angle); $rotX = $cos * $dirX - $sin * $dirY; $rotY = $sin * $dirX + $cos * $dirY; $rotNegX = $cos * -$dirX - $sin * $dirY; $rotNegY = $sin * $dirX - $cos * $dirY; // Flip control points for "backwards" curves if ($dirX x; $y1 = -$rotNegY * $length + $from->y; $x2 = -$rotX * $length + $to->x; $y2 = -$rotY * $length + $to->y; } // Or generate "normal" control points else { $x1 = $rotX * $length + $from->x; $y1 = $rotY * $length + $from->y; $x2 = $rotNegX * $length + $to->x; $y2 = $rotNegY * $length + $to->y; } return array(new Vector2d($x2, $y2), new Vector2d($x1, $y1)); }
方便!如果我忘記了參數化方程式,我的幾何體確實很薄弱。對我來說,另一個問題是根據飛機上的起點/終點確定(cx,cy)。 – 2010-08-10 14:12:08