VS:Vec2Ang: Difference between revisions

From Vectorworks Developer
Jump to navigation Jump to search
(add examples for pascal and python)
No edit summary
Line 63: Line 63:
# or  
# or  


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


Line 74: Line 75:
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<remark>
<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.
([[User:CBM-c-| _c_]], 2022.01.18) For Vectorscript Python you might need to add a third item in the tuple for the vector, or vs.Vec2Ang will return 90/-90. This is the opposite in VS Pascal.
</remark>
</remark>



Revision as of 05:45, 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) For Vectorscript Python you might need to add a third item in the tuple for the vector, or vs.Vec2Ang will return 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 

if Len(p) == 2:
    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