如果我理解正确,您想找到八角形中八个点中每个点的转换坐标——对吗?如果是这样,Raphael 没有为您提供开箱即用的解决方案,但您应该能够使用 Raphael 的一些核心实用功能相对轻松地获得所需的信息。
我的建议是这样的:
var pathdetail = "your path definition here. Your path uses only absolute coordinates... right?";
var pathdetail = Raphael.transformPath( pathdetail, "your transform string" );
// pathdetail will now still be a string full of path notation, but its coordinates will be transformed appropriately
var pathparts = Raphael.parsePathString( pathdetail );
var cornerList = [];
// pathparts will not be an array of path elements, each of which will be parsed into a subarray whose elements consist of a command and 0 or more parameters.
// The following logic assumes that your path string uses ONLY ABSOLUTE COORDINATES and does
// not take relative coordinates (or H/V directives) into account. You should be able to
// code around this with only a little additional logic =)
for ( var i = 0; i < pathparts.length; i++ )
{
switch( pathparts[i][0] )
{
case "M" :
case "L" :
// Capture the point
cornerList.push( { x: pathparts[i][1], y: pathparts[i][2] } );
break;
default :
console.log("Skipping irrelevant path directive '" + pathparts[i][0] + "'" );
break;
}
}
// At this point, the array cornerList should be populated with every discrete point in your path.
这显然是不希望使用内联的代码块,并且只会处理野外路径的子集(尽管它可以扩展为适合通用用途)。但是,对于路径字符串使用绝对坐标的八边形情况,这个——或类似的东西——应该能准确地给你你需要的东西。