VS:DotProduct: Difference between revisions

From Vectorworks Developer
Jump to navigation Jump to search
m (1 revision)
(add examples, comment about need of 3-dimensional parameters)
 
Line 43: Line 43:
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<remark>
<remark>
This should be used in place of the bullet/yen operator for better cross-platform operability. - PCP</remark>
([[User:CBM-c-|_c_]], 2022.01.20) In Python the two vectors used as parameters MUST be 3-dimensional, or it will return gibberish. This doesn't matter in Pascal.
 
<code lang="py">
# EXAMPLE OF FAULTY USAGE
v1 = (12, 1) # bidimensional
v2 = (3, 15)
vs.Message( str(vs.DotProduct(v1, v2)) ) # returns gibberish
</code>
 
''' other comments whose author/date is lost:'''
 
(PCP ): This should be used in place of the bullet/yen operator for better cross-platform operability. -</remark>


-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
Line 51: Line 62:
PROCEDURE Example;
PROCEDURE Example;
VAR
VAR
pt1, pt2, pt3, pt4 :VECTOR;
    pt1, pt2, pt3, pt4 :VECTOR;
ang :REAL;
    ang :REAL;
BEGIN
BEGIN
GetPt(pt1.x, pt1.y);
    GetPt(pt1.x, pt1.y);
GetPtL(pt1.x, pt1.y, pt2.x, pt2.y);
    GetPtL(pt1.x, pt1.y, pt2.x, pt2.y);
GetPtL(pt2.x, pt2.y, pt3.x, pt3.y);
    GetPtL(pt2.x, pt2.y, pt3.x, pt3.y);
MoveTo(pt1.x, pt1.y);
 
LineTo(pt2.x, pt2.y);
    MoveTo(pt1.x, pt1.y);
LineTo(pt3.x, pt3.y);
    LineTo(pt2.x, pt2.y);
pt4 := (pt1 + pt3) / 2;
    LineTo(pt3.x, pt3.y);
{Find the angle between the vectors.}
    pt4 := (pt1 + pt3) / 2;
ang := Rad2Deg(ArcCos(DotProduct(UnitVec(pt1-pt2), UnitVec(pt3-pt2))));
 
TextOrigin(pt4.x, pt4.y);
    { Find the angle between the vectors.}
CreateText(Concat(ang));
    ang := Rad2Deg(ArcCos(DotProduct(UnitVec(pt1-pt2), UnitVec(pt3-pt2))));
    TextOrigin(pt4.x, pt4.y);
    CreateText(Concat(ang));
END;
END;
RUN(Example);</code>
RUN(Example);</code>
==== Python ====
==== Python ====
<code lang="py">
<code lang="py">
 
v1 = (12, 1, 0) # 3-dimensional tuple
v2 = (3, 15, 0)
vs.Message( str(vs.DotProduct(v1, v2)) )
</code>
</code>
</sample>
</sample>
Line 81: Line 97:
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<version>
<version>
Availability: from VectorWorks8.0
Availability: from VectorWorks 8.0


</version>
</version>

Latest revision as of 05:57, 20 January 2022

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

Description

Returns the dot product of the two specified vectors.

The dot product is also known as the scalar product of the two vectors, and is equivalent to the product of the magnitudes of the two vectors multiplied by the cosine of the angle between the two vectors.

FUNCTION DotProduct(
v1 :VECTOR;
v2 :VECTOR) : REAL;
def vs.DotProduct(v1, v2):
    return REAL

Parameters

v1 VECTOR Source vector 1.
v2 VECTOR Source vector 2.

Return Value

Returns the scalar, or dot, product of the vectors v1 and v2.

Remarks

(_c_, 2022.01.20) In Python the two vectors used as parameters MUST be 3-dimensional, or it will return gibberish. This doesn't matter in Pascal.

# EXAMPLE OF FAULTY USAGE
v1 = (12, 1) # bidimensional
v2 = (3, 15) 
vs.Message( str(vs.DotProduct(v1, v2)) ) # returns gibberish

other comments whose author/date is lost:

(PCP ): This should be used in place of the bullet/yen operator for better cross-platform operability. -

Example

VectorScript

PROCEDURE Example;
VAR
    pt1, pt2, pt3, pt4 :VECTOR;
    ang :REAL;
BEGIN
    GetPt(pt1.x, pt1.y);
    GetPtL(pt1.x, pt1.y, pt2.x, pt2.y);
    GetPtL(pt2.x, pt2.y, pt3.x, pt3.y);

    MoveTo(pt1.x, pt1.y);
    LineTo(pt2.x, pt2.y);
    LineTo(pt3.x, pt3.y);
    pt4 := (pt1 + pt3) / 2;

    { Find the angle between the vectors.}
    ang := Rad2Deg(ArcCos(DotProduct(UnitVec(pt1-pt2), UnitVec(pt3-pt2))));
    TextOrigin(pt4.x, pt4.y);
    CreateText(Concat(ang));
END;
RUN(Example);

Python

v1 = (12, 1, 0) # 3-dimensional tuple
v2 = (3, 15, 0) 
vs.Message( str(vs.DotProduct(v1, v2)) )

Version

Availability: from VectorWorks 8.0

See Also

VS Functions:

VS:AngBVec

VS Functions: [[VS:AngBVec]]