VS:ThreePtCenter: Difference between revisions

From Vectorworks Developer
Jump to navigation Jump to search
m (1 revision)
 
(fix)
 
(5 intermediate revisions by the same user not shown)
Line 5: Line 5:
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<desc>
<desc>
Returns the center of a circle passing thru 3 given points.
Returns the center of a circle passing thru 3 given points.</desc>
</desc>


-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<def>
<def>
<funcDef lang="vs">
<funcDef lang="vs">
FUNCTION ThreePtCenter(pt1X, pt1Y, pt1Z :REAL; pt2X, pt2Y, pt2Z :REAL; pt3X, pt3Y, pt3Z :REAL) X, Y, Z :REAL;
FUNCTION ThreePtCenter(pt1:VECTOR; pt2:VECTOR; pt3:VECTOR) : VECTOR;
</funcDef>
</funcDef>
<funcDef lang="py">
<funcDef lang="py">
Line 23: Line 22:
<lineList ident=1>
<lineList ident=1>
<line>
<line>
pt1X, pt1Y, pt1Z
pt1
REAL
VECTOR


</line>
</line>
<line>
<line>
pt2X, pt2Y, pt2Z
pt2
REAL
VECTOR


</line>
</line>
<line>
<line>
pt3X, pt3Y, pt3Z
pt3
REAL
VECTOR


</line>
</line>
</lineList>
</lineList>
</params>
</params>
-----------------------------------------------------------------------------------------------------------
<return>
</return>


-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<remark>
<remark>
([[User:Orso.b.schmid|Orso]], 2011 Jan. 08) This call never sets the z-value of the returned center: the z is always zero.
([[User:CBM-c-|_c_]], 2022.01.18) In VS Python this routine returns a 3-dimensional tuple. Warning: Most Math - Vector routines require a 3-dimensional tuple, failing to init a third item in VW before 2023 (vs.Vec2Ang, for example, returns gibberish on 2-d tuples).
</remark>
</remark>


-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<sample>
<sample>
==== VectorScript ====
<code lang="pas">
<code lang="pas">
{ finds the tangent angle between two poly sides }
PROCEDURE Example;
PROCEDURE Example;
VAR
VAR
  pt1, pt2, pt3, center_pt :VECTOR;
    polyObj : HANDLE;
    p1, p2, p3, c, t : VECTOR;
    ang : REAL;
 
BEGIN
BEGIN
  GetPt(pt1.x, pt1.y);
polyObj := FSActLayer; { take care to have a polygon selected }
  GetPtL(pt1.x, pt1.y, pt2.x, pt2.y);
IF polyObj <> NIL THEN BEGIN { not checking here for obj type, but you should }
  MoveTo(pt1.x, pt1.y);
    GetPolyPt( polyObj, 1, p1.x, p1.y );
  LineTo(pt2.x, pt2.y);
    GetPolyPt( polyObj, 2, p2.x, p2.y );
  GetPtL(pt2.x, pt2.y, pt3.x, pt3.y);
    GetPolyPt( polyObj, 3, p3.x, p3.y );
  LineTo(pt3.x, pt3.y);
 
  center_pt := ThreePtCenter(pt1, pt2, pt3);
    c := ThreePtCenter( p1, p2, p3 );
  Locus(center_pt.x, center_pt.y);
    Locus( c.x, c.y );
 
    t := Perp( p2 - c );
    ang := Vec2Ang( t );
    AlrtDialog( Concat('Angle of tangent at pt2: ', Chr(13), Num2Str(3, ang)) );  
END;
END;
RUN(Example);</code>
Run(Example);
</code>
 
==== Python ====
<code lang="py">
# finds the tangent angle between two poly sides
polyObj = vs.FSActLayer() # take care to have a polygon selected
if polyObj != vs.Handle( 0 ): # not checking here for obj type, but you should
    p1 = vs.GetPolyPt( polyObj, 1 )
    p2 = vs.GetPolyPt( polyObj, 2 )
    p3 = vs.GetPolyPt( polyObj, 3 )


    c = vs.ThreePtCenter( p1, p2, p3 )
    vs.Locus( c )
    t = vs.Perp( p2[0] - c[0], p2[1] - c[1], 0 )
    ang = vs.Vec2Ang( t )
    vs.AlrtDialog( f'Angle of tangent at pt2:\r{ang:.3f}' ) # precision = 3, coercing float
</code>
</sample>
</sample>
-----------------------------------------------------------------------------------------------------------
<seeAlso></seeAlso>


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


This is drop-in function.
</version>
</version>
-----------------------------------------------------------------------------------------------------------
<seeAlso>
</seeAlso>


</vwDoc>
</vwDoc>

Latest revision as of 06:13, 27 January 2022

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

Description

Returns the center of a circle passing thru 3 given points.

FUNCTION ThreePtCenter(
pt1 :VECTOR;
pt2 :VECTOR;
pt3 :VECTOR) : VECTOR;
def vs.ThreePtCenter(pt1, pt2, pt3):
    return VECTOR

Parameters

pt1 VECTOR
pt2 VECTOR
pt3 VECTOR

Remarks

(_c_, 2022.01.18) In VS Python this routine returns a 3-dimensional tuple. Warning: Most Math - Vector routines require a 3-dimensional tuple, failing to init a third item in VW before 2023 (vs.Vec2Ang, for example, returns gibberish on 2-d tuples).

Example

VectorScript

{ finds the tangent angle between two poly sides }
PROCEDURE Example;
VAR
    polyObj : HANDLE;
    p1, p2, p3, c, t : VECTOR;
    ang : REAL;

BEGIN
polyObj := FSActLayer; { take care to have a polygon selected }
IF polyObj <> NIL THEN BEGIN { not checking here for obj type, but you should }
    GetPolyPt( polyObj, 1, p1.x, p1.y );
    GetPolyPt( polyObj, 2, p2.x, p2.y );
    GetPolyPt( polyObj, 3, p3.x, p3.y );

    c := ThreePtCenter( p1, p2, p3 );
    Locus( c.x, c.y );

    t := Perp( p2 - c );
    ang := Vec2Ang( t );
    AlrtDialog( Concat('Angle of tangent at pt2: ', Chr(13), Num2Str(3, ang)) ); 
END;
Run(Example);

Python

# finds the tangent angle between two poly sides
polyObj = vs.FSActLayer() # take care to have a polygon selected
if polyObj != vs.Handle( 0 ): # not checking here for obj type, but you should
    p1 = vs.GetPolyPt( polyObj, 1 ) 
    p2 = vs.GetPolyPt( polyObj, 2 )
    p3 = vs.GetPolyPt( polyObj, 3 ) 

    c = vs.ThreePtCenter( p1, p2, p3 )
    vs.Locus( c )

    t = vs.Perp( p2[0] - c[0], p2[1] - c[1], 0 ) 
    ang = vs.Vec2Ang( t )
    vs.AlrtDialog( f'Angle of tangent at pt2:\r{ang:.3f}' ) # precision = 3, coercing float

Version

Availability: from Vectorworks 2014