gltut / Documents / Positioning / GenInterpolateDirection.lua

Jason McKesson 18bc807 

require "SvgWriter"
require "vmath"
require "Viewport"
require "SubImage"
require "_utils"

local subImageSize = 300;

local subImages = SubImage.SubImage(1, 1, subImageSize, subImageSize, 50, 0);

local coordSize = 2;

local vp = Viewport.Viewport(subImages:SubSize(), {0, 0}, coordSize)
local trans2 = Viewport.Transform2D()

local scaleFactor = 0.25;

-- Styles
local styleLib = SvgWriter.StyleLibrary();
local pointSize = 9;

styleLib:AddStyle(nil, "circle", SvgWriter.Style{stroke="black", fill="none"});
styleLib:AddStyle(nil, "center", SvgWriter.Style{stroke="none", fill="black"});

styleLib:AddStyle(nil, "short_path",
	SvgWriter.Style{stroke="blue", stroke_width="8px", fill="none", stroke_opacity="0.3"});
styleLib:AddStyle(nil, "long_path",
	SvgWriter.Style{stroke="red", stroke_width="8px", fill="none", stroke_opacity="0.3"});
styleLib:AddStyle(nil, "vector",
	SvgWriter.Style{stroke="black", stroke_width="2px", fill="none", marker_end=SvgWriter.uriLocalElement("arrow")});
styleLib:AddStyle(nil, "arrowhead",
styleLib:AddStyle(nil, "label",

local centerPt = vmath.vec2(0, 0);
local radius = 0.8

local vectorAngles = {20, 140, 200}
local vectorEndpts = {}

for i, angle in ipairs(vectorAngles) do
	local radAngle = math.rad(angle);
	vectorEndpts[#vectorEndpts + 1] =
		vmath.vec2(math.cos(radAngle), math.sin(radAngle)) * radius;

local labelLocs = {};

for i, endPt in ipairs(vectorEndpts) do
	labelLocs[#labelLocs + 1] = (endPt + centerPt) / 2.0;

local labelData =
	{"q1", vmath.vec2(0, 25)},
	{"q2", vmath.vec2(17, -7)},
	{"-q1", vmath.vec2(0, 25)},

centerPt = vp:Transform(centerPt);
radius = vp:Length(radius);
vectorEndpts = vp:Transform(vectorEndpts);
labelLocs = vp:Transform(labelLocs);

local shortArc = SvgWriter.Path();
shortArc:M(vectorEndpts[2]):A({radius, radius}, 0, 0, 0, vectorEndpts[3])

local longArc = SvgWriter.Path();
longArc:M(vectorEndpts[2]):A({radius, radius}, 0, 0, 1, vectorEndpts[1])

local writer = SvgWriter.SvgWriter(ConstructSVGName(arg[0]), {(subImages:Size().x + 1) .."px", (subImages:Size().y + 1) .. "px"});
		writer:BeginGroup(nil, "g_point");
			writer:Circle(vmath.vec2(0, 0), pointRadius, {"vertex"});
		WriteStandardArrowhead(writer, "arrow", {"arrowhead"})
	writer:Circle(centerPt, radius, {"circle"});
	for i, endPt in ipairs(vectorEndpts) do
		writer:Line(centerPt, endPt, {"vector"});
	writer:Path(shortArc, {"short_path"});
	writer:Path(longArc, {"long_path"});

	writer:Circle(centerPt, 8, {"center"});
	for i, labelPos in ipairs(labelLocs) do
		writer:Text(labelData[i][1], labelPos + labelData[i][2], {"label"});

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.