Skip to content

Latest commit

 

History

History
106 lines (86 loc) · 2.57 KB

File metadata and controls

106 lines (86 loc) · 2.57 KB

RelativeCoords

Description

Translates a point into a coordinate system defined by 2 other points.

FUNCTION RelativeCoords(
				pt    : VECTOR;
				begPt : VECTOR;
				endPt : VECTOR): VECTOR;
def vs.RelativeCoords(pt, begPt, endPt):
    return VECTOR

Parameters

Name Type Description
pt VECTOR
begPt VECTOR
endPt VECTOR

Remarks

(_c_, 2022.01.19) In Python the tuple returned is always bidimensional in the form (0.0, 0.0). Remember to add a third item (0.0, 0.0, 0.0) for usage in the vector Routines such as VS:Vec2Ang or they will return gibberish.

See graphical representation below (click on the image to enlarge it):

C_MathRelativeCoords.png

[MaKro 11/2021] Did not dig deeper, but looks like beg and end can be interpreted as: vs.RelativeCoords(p, p_origin, x_axis)

Examples

VectorScript

PROCEDURE Example;
VAR
    pt, beg_pt, end_pt, v :VECTOR;

BEGIN
    Message('Set begin point');
    CallTool(-221); { creates a locus }
    GetLocPt(FSActLayer, beg_pt.x, beg_pt.y);

    Message('Set end point');
    CallTool(-221); { creates a locus }
    GetLocPt(FSActLayer, end_pt.x, end_pt.y);

    Message('Set point');
    CallTool(-221); { creates a locus }
    GetLocPt(FSActLayer, pt.x, pt.y);

    v := RelativeCoords(pt, beg_pt, end_pt);
    Message('result vector=', v);
    Locus(v.x, v.y);
END;
RUN(Example);
lowestX  := kMinReal;
highestX := kMaxReal;
for cnt2 := 1 to sectCnt DO BEGIN
	IF g.WinderLAngle < 0
		THEN tmpPt := RelativeCoords(sects[cnt2], nutherPt, onPoly)
		ELSE tmpPt := RelativeCoords(sects[cnt2], onPoly, nutherPt);
	if (tmpPt.x > lowestX) & (tmpPt.x < 0) then BEGIN
		lesserPt := sects[cnt2];
		lowestX := tmpPt.x;
	END;

lowestX  := kMinReal;
highestX := kMaxReal;
for cnt2 := 1 to sectCnt DO BEGIN
	IF g.WinderUAngle1 < 0
		THEN tmpPt := RelativeCoords(sects[cnt2], nutherPt, onPoly)
		ELSE tmpPt := RelativeCoords(sects[cnt2], onPoly, nutherPt);
	if (tmpPt.x > lowestX) & (tmpPt.x < 0) then BEGIN
		lesserPt := sects[cnt2];
		lowestX := tmpPt.x;
	END;

BEGIN
	temp_pt := RelativeCoords(pt, beg_pt, END_pt);
	PtPerpLine := beg_pt + (UnitVec(END_pt - beg_pt) * temp_pt.x);
END;
import vs

# Translates a point into a coordinate system defined by 2 other points.
pt = (0, 0)
begPt = (1, 1)
endPt = (2, 2)

vec = vs.RelativeCoords(pt, begPt, endPt)
vs.Message('RelativeCoords returned: ' + str(vec))

Version

Availability: from Vectorworks 2014

Category