VS:PointAlongPoly: Difference between revisions

From Vectorworks Developer
Jump to navigation Jump to search
No edit summary
 
m (add see also)
 
(4 intermediate revisions by the same user not shown)
Line 5: Line 5:
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<desc>
<desc>
Returns a point at the specified distance along the poly, and a vector tangent to the poly at that point. Returns FALSE if it fails for any reason.
Returns a point at the specified distance along the poly, and a vector tangent to the poly at that point.</desc>
</desc>


-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<def>
<def>
<funcDef lang="vs">
<funcDef lang="vs">
FUNCTION PointAlongPoly(h :HANDLE; dist :REAL; VAR ptX, ptY, ptZ :REAL; VAR tangentX, tangentY, tangentZ :REAL) :BOOLEAN;
FUNCTION PointAlongPoly(h:HANDLE; dist:REAL; VAR pt:VECTOR; VAR tangent:VECTOR) : BOOLEAN;
</funcDef>
</funcDef>
<funcDef lang="py">
<funcDef lang="py">
Line 33: Line 32:
</line>
</line>
<line>
<line>
ptX, ptY, ptZ
pt
REAL
VECTOR
Output parameter.
 
</line>
</line>
<line>
<line>
tangentX, tangentY, tangentZ
tangent
REAL
VECTOR
Output parameter.
 
</line>
</line>
</lineList>
</lineList>
</params>
</params>
-----------------------------------------------------------------------------------------------------------
<return>
</return>


-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<remark>
<remark>
This appears to be annotated wrong? Shouldn't pt and tangent be POINT or VECTOR variables?
([[User:CBM-c-| _c_]], 2022.01.18) In Vectorscript Python this returns a tuple with 3 items ( 0, 0, 0 ). This is relevant for usage in routines such as [[VS:Vec2Ang | Vec2Ang]], returning wrong values if the tuple is only bidimensional.
</remark>
</remark>


-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<sample>
<sample>
==== Pascal ====
<code lang="pas">
<code lang="pas">
PROCEDURE Example;
PROCEDURE Test;
VAR
VAR
  h    :HANDLE;
    polyObj : HANDLE;
  p, t :VECTOR;
    dist : REAL;
  dist :REAL;
    p, tangentVec : VECTOR;
BEGIN
BEGIN
  h := FSActLayer;
    polyObj := FSActLayer;
  IF h = NIL THEN
 
      AlrtDialog('Select a poly before running this script.')
    IF polyObj = NIL THEN
  ELSE BEGIN
        AlrtDialog( 'Select a polygon' )
      dist := RealDialog('Enter distance:', '1');
      DSelectAll;
    ELSE BEGIN
      IF PointAlongPoly(h, dist, p, t) THEN BEGIN
        dist := 1m;
        Locus(p.x, p.y);
        IF PointAlongPoly( polyObj, dist, p, tangentVec ) THEN
        MoveTo(p.x, p.y);
            Locus( p.x, p.y );
        LineTo(p.x + (t.x * 10), p.y + (t.y * 10));
    END;
      END ELSE AlrtDialog('Error!');
  END;
END;
END;
RUN(Example);</code>
Run(Test);
</code>
 
==== Python ====
<code lang="py">
def Str2Num( inStr ):
    ok, num = vs.ValidNumStr( inStr )
    if ok:
        return num
    else:
        return 0
 
polyObj = vs.FSActLayer()
 
if polyObj == vs.Handle():
    vs.AlrtDialog( 'Select a polygon' )
else:
    dist = Str2Num( '1m' ) # convert string to dim
    ok, p, tangentVec = vs.PointAlongPoly( polyObj, dist )
    if ok:
        vs.Locus( p )
        vs.AlrtDialog( str( len(p)) ) # return a tuple with 3 items
</code>


</sample>
</sample>
-----------------------------------------------------------------------------------------------------------
<seeAlso>
VS Functions:
* [[VS:PointAlongPolyN]]
</seeAlso>


-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<version>
<version>
Availability: from All Versions
Availability: from Vectorworks 2014


This is drop-in function.
</version>
</version>
-----------------------------------------------------------------------------------------------------------
<seeAlso>
[[VS:PointAlongPolyN]]
</seeAlso>


</vwDoc>
</vwDoc>

Latest revision as of 06:23, 25 January 2022

.VectorScript|VectorScript ..VS:Function Reference|Function Reference ..VS:Function_Reference_Appendix|Appendix

Description

Returns a point at the specified distance along the poly, and a vector tangent to the poly at that point.

FUNCTION PointAlongPoly(
h :HANDLE;
dist :REAL;
VAR pt :VECTOR;
VAR tangent :VECTOR) : BOOLEAN;
def vs.PointAlongPoly(h, dist):
    return (BOOLEAN, pt, tangent)

Parameters

h HANDLE
dist REAL
pt VECTOR
tangent VECTOR

Remarks

( _c_, 2022.01.18) In Vectorscript Python this returns a tuple with 3 items ( 0, 0, 0 ). This is relevant for usage in routines such as Vec2Ang, returning wrong values if the tuple is only bidimensional.

Example

Pascal

PROCEDURE Test;
VAR
    polyObj : HANDLE;
    dist : REAL;
    p, tangentVec : VECTOR;
	
BEGIN
    polyObj := FSActLayer;

    IF polyObj = NIL THEN
        AlrtDialog( 'Select a polygon' )
		
    ELSE BEGIN
        dist := 1m;
        IF PointAlongPoly( polyObj, dist, p, tangentVec ) THEN
            Locus( p.x, p.y );
    END;
END;
Run(Test);

Python

def Str2Num( inStr ):
    ok, num = vs.ValidNumStr( inStr )
    if ok:
        return num
    else:
        return 0

polyObj = vs.FSActLayer()

if polyObj == vs.Handle():
    vs.AlrtDialog( 'Select a polygon' )
else:
    dist = Str2Num( '1m' ) # convert string to dim
    ok, p, tangentVec = vs.PointAlongPoly( polyObj, dist )
    if ok:
        vs.Locus( p )
        vs.AlrtDialog( str( len(p)) ) # return a tuple with 3 items

Version

Availability: from Vectorworks 2014

See Also

VS Functions:

VS Functions:
  • [[VS:PointAlongPolyN]]