VS:Vec2Ang: Difference between revisions

From Vectorworks Developer
Jump to navigation Jump to search
m (1 revision)
(add examples for pascal and python)
Line 33: Line 33:
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<return>
<return>
Returns the angle of the specified vector in degrees.</return>
Returns the angle of the specified vector in degrees.
</return>
 
-----------------------------------------------------------------------------------------------------------
<sample>
 
==== VectorScript ====
 
<code lang="pas">
{ ... }
p : VECTOR;
vtx1 : INTEGER;
{ ... }
 
{ fetches coordinates of vertex 1 in a polygon, remember to use GetPolylineVertex if it's a polyline!  }
vtx1 := 1;
GetPolyPt( polyHandle, vtx1, p.x, p.y );
 
ang := Vec2Ang( p );
</code>
 
==== Python ====
<code lang="py">
# fetches coordinates of vertex 1 in a poly, returns a tuple with 2 items in the form ( 0, 0 )
 
p = vs.GetPolyPt( polyHandle, vtx1 )
ang = vs.Vec2Ang( (p[0], p[1], 0 ) # adds z coordinate or vs.Vec2Ang will fail (VS Python only, Pascal OK )
 
# or
 
p += (0,) # add a 3rd item to the tuple
ang = vs.Vec2Ang( p ) # returns angle
 
# FAILURE EXAMPLES:
# ang = vs.Vec2Ang( p ) # always returns 90
# ang = vs.Vec2Ang( (p[0], p[1]) ) # always returns 90
</code>
</sample>
 
-----------------------------------------------------------------------------------------------------------
<remark>
([[User:CBM-c-| _c_]], 2022.01.18) or Vectorscript Python you need to add a third item in the tuple or vs.Vec2Ang returns always 90/-90. This is the opposite in VS Pascal.
</remark>


-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------

Revision as of 04:21, 18 January 2022

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

Description

Returns the angle, in degrees, of the specified vector. If Vect is a 3D vector, Vec2Ang will return the 3D angle between Vect and the X axis. If Vect is {0,0,0}, Vec2Ang returns -90.

FUNCTION Vec2Ang(
Vect :VECTOR) : REAL;
def vs.Vec2Ang(Vect):
    return REAL

Parameters

Vect VECTOR Source vector.

Return Value

Returns the angle of the specified vector in degrees.

Remarks

( _c_, 2022.01.18) or Vectorscript Python you need to add a third item in the tuple or vs.Vec2Ang returns always 90/-90. This is the opposite in VS Pascal.

Example

VectorScript

{ ... }
p : VECTOR;
vtx1 : INTEGER;
{ ... }

{ fetches coordinates of vertex 1 in a polygon, remember to use GetPolylineVertex if it's a polyline!  }
vtx1 := 1;
GetPolyPt( polyHandle, vtx1, p.x, p.y ); 

ang := Vec2Ang( p );

Python

# fetches coordinates of vertex 1 in a poly, returns a tuple with 2 items in the form ( 0, 0 )

p = vs.GetPolyPt( polyHandle, vtx1 ) 
ang = vs.Vec2Ang( (p[0], p[1], 0 ) # adds z coordinate or vs.Vec2Ang will fail (VS Python only, Pascal OK )

# or 

p += (0,) # add a 3rd item to the tuple
ang = vs.Vec2Ang( p ) # returns angle

# FAILURE EXAMPLES:
# ang = vs.Vec2Ang( p ) # always returns 90
# ang = vs.Vec2Ang( (p[0], p[1]) ) # always returns 90

Version

Availability: from All Versions