Math-Offset Vertex

From Vectorlab
Jump to: navigation, search


Given chord and radius of an arc, returns the sagitta. You need to load the routine M_CheckAng360, M_OffsetPt and M_GetSlopebefore this. By Orso B. Schmid


{ Orso ***************************** }
{ translate a vertex p by a distance }
{ it is like having two polygons, where one is offsetting the first at a distance }
{ if poly 1 has a vertex, the routine outputs the vertex of poly 2   }
FUNCTION M_OffsetVtx(vtxMinus1, vtx, vtxPlus1 : VECTOR; dist: REAL): VECTOR;
	VAR
		chord1, chord2, cen : VECTOR;
		angLeft, angRight : REAL;
		
	BEGIN
		angLeft := M_CheckAng360(M_GetSlope(vtx, vtxPlus1) - 90);
		angRight := M_CheckAng360(M_GetSlope(vtxMinus1, vtx) - 90);
		
		{ find the translation of the vtx at distance h }
		chord1 := M_OffsetPt(vtx, dist, angLeft); { left side of vertex }
		chord2 := M_OffsetPt(vtx, dist, angRight); { right side of vertex }
		
		{ center of the circle passing through the vertex and the chord }
		cen := ThreePtCenter(chord1, chord2, vtx);
		
		M_OffsetVtx := M_OffsetPt(cen, Norm(vtx.x -cen), M_GetSlope(vtx, cen));  
		{ projection of vertex at distance h }
	END;