%%PageItemTitle%%

VectorDraw Web Library

JsPropertiesExtractor Send comments on this topic.
GetPlineSegmentIndexFromPoint Method
See Also  Example
vdWebLibrary Namespace > vdgeo Class : GetPlineSegmentIndexFromPoint Method
point
A passed point in world coordinates.
vertexes
An array of the vertexes of the polyline which we usually get from pline.VertexList.Items
isClosed
True if it is closed or False if it is open.If not passed it will be False
extrusionVector
An array of [X,Y,Z] which is a vector that is perpendicular to the plain of the polyline.Usually we get it from the polyline.If not passed it will get the [0,0,1] value.
Finds the closed segment of the polyline a passed point

Syntax

JScript 
public function GetPlineSegmentIndexFromPoint( 
   point : Object,
   vertexes : Object[],
   isClosed : boolean,
   extrusionVector : Object
) : int;

Parameters

point
A passed point in world coordinates.
vertexes
An array of the vertexes of the polyline which we usually get from pline.VertexList.Items
isClosed
True if it is closed or False if it is open.If not passed it will be False
extrusionVector
An array of [X,Y,Z] which is a vector that is perpendicular to the plain of the polyline.Usually we get it from the polyline.If not passed it will get the [0,0,1] value.

Example

Example where on mouse down event when we click somewhere close to a polyline we can find the segment with the start and the end point of the polyline which is more close to the point that we have clicked
C#Copy Code
function _vdmousedown(e) { 
 
  if (e.target.ActiveAction().IsStarted()) return; //no user waiting action is active 
  var entity = e.target.GetEntityFromPoint(e.xPix, e.yPix); //scan for an entity under the pick point 
  if (!entity || entity._t !== vdConst.vdPolyline_code) return; //check if entity exist and is a polyline type 
  var index = vdgeo.GetPlineSegmentIndexFromPoint([e.x, e.y, e.z], entity.VertexList.Items, entity.Flag == 1, entity.ExtrusionVector); //get the picked index near the pick point 
  if (index == -1) return;  
  //an index was found.Print the result 
  var sp, ep;  
  sp = entity.VertexList.Items[index];  
  if (index == entity.VertexList.Items.length - 1) ep = entity.VertexList.Items[0]; 
  else ep = entity.VertexList.Items[index + 1]; 
  alert("Segment" + index + "\nbetween first point X=" + sp[0].toFixed(3).toString() + "   Y=" + sp[1].toFixed(3).toString() + "   Z=" + sp[2].toFixed(3).toString() + "   Bulge=" + sp[3].toFixed(3).toString() 
  + "\nand second point X=" + ep[0].toFixed(3).toString() + "   Y=" + ep[1].toFixed(3).toString() + "   Z=" + ep[2].toFixed(3).toString() + "   Bulge=" + ep[3].toFixed(3).toString());  
 
             }

See Also