使用 Line() 函数 TCPDF 计算线的起点和终点以创建五边形
Calculate start and end of a line to create a pentagon using Line() function TCPDF
我知道 TCPDF 具有创建不同形状的内置功能。我有一个案例,我必须创建一条线并将点作为点 (8,2) 放置在它上面,将 0 视为线的中心。使用 tcpdf line()
function. I created a line and placed dots on it see the screenshot below.
在此屏幕截图中,点 (8,2)
位于一条线上,其中 8 是距线中心的左侧点,2 是距线中心的右侧点。现在我必须将线旋转到 72 degrees
并将下一行与(左,右)点放在一起。对具有动态(左、右)点的总共 5 行重复相同的过程。
这是我目前使用的:
$counter = 1;
foreach($graph_points as $points){
// center of the line
$xc = 100;
$yc = 150;
if($counter > 1){
$pdf->Rotate(-72, $xc, $yc);
}
$left = round($points->left);
$left_perc = (($left*10)/100) * 50;
$right = round($points->right);
$right_perc = (($right*10)/100) * 50;
$pdf->SetDrawColor(200, 200, 200);
$pdf->Line($xc - 50 , $yc, $xc + 50 , $yc,array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
$pdf->Line($xc, $yc - 2, $xc, $yc + 2,array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
$pdf->Circle($xc - 50 + (50 - $left_perc), $yc, 1, 0, 360, 'DF', array('width' => 0.25, 'dash' => 0, 'color' => array(255,0,0)), array(210, 0, 0));
$pdf->Text($xc - 53 + (50 - $left_perc), $yc - 7, $left, false, false, true, 0, 0, '', 0, '', 0, false, 'T', 'T');
$pdf->Circle($xc + 50 - (50 - $right_perc), $yc, 1, 0, 360, 'DF', array('width' => 0.25, 'dash' => 0, 'color' => array(255,0,0)), array(210, 0, 0));
$pdf->Text($xc + 47 - (50 - $right_perc), $yc - 7, $right, false, false, true, 0, 0, '', 0, '', 0, false, 'T', 'T');
$counter++;
}
下面的截图是这段代码的输出,我想要一个有 5 条线及其点的五角形。
我已经尝试了 2 天,但没有找到任何可行的解决方案。请建议我以使用线创建五边形的方式进行计算。
谢谢
更新
我设法创建了形状,但边彼此连接不均匀,这也影响了数字的文本位置。
代码如下:
$counter = 1;
$xc = 100;
$yc = 150;
foreach($graph_points as $points){
// center of the line
if($counter > 1){
$xc = $xc - 65;
$yc = $yc - 45;
$pdf->Rotate(-72, $xc, $yc);
}
$left = round($points->left);
$left_perc = (($left*10)/100) * 50;
$right = round($points->right);
$right_perc = (($right*10)/100) * 50;
$pdf->SetDrawColor(200, 200, 200);
$pdf->Line($xc - 50 , $yc, $xc + 50 , $yc,array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
$pdf->Line($xc, $yc - 2, $xc, $yc + 2,array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
$pdf->Circle($xc - 50 + (50 - $left_perc), $yc, 1, 0, 360, 'DF', array('width' => 0.25, 'dash' => 0, 'color' => array(255,0,0)), array(210, 0, 0));
$pdf->Text($xc - 53 + (50 - $left_perc), $yc, $left, false, false, true, 0, 0, '', 0, '', 0, false, 'T', 'T');
$pdf->Circle($xc + 50 - (50 - $right_perc), $yc, 1, 0, 360, 'DF', array('width' => 0.25, 'dash' => 0, 'color' => array(255,0,0)), array(210, 0, 0));
$pdf->Text($xc + 47 - (50 - $right_perc), $yc, $right, false, false, true, 0, 0, '', 0, '', 0, false, 'T', 'T');
$counter++;
}
这是现在的截图。
经过3天的努力,我终于找到了一个可行的解决方案。在这里发布我的解决方案以防有人有相同的要求。
$xc = 100;
$yc = 200;
$counter = 1;
foreach($graph_points as $points){
if($counter > 1){
$xc = $xc - 39;
$yc = $yc - 28;
$pdf->Rotate(-72, $xc, $yc);
}
$left = round($points->left);
$left_perc = (($left*10)/100) * 30;
$right = round($points->right);
$right_perc = (($right*10)/100) * 30;
$pdf->SetDrawColor(200, 200, 200);
$pdf->Line($xc - 30 , $yc, $xc + 30 , $yc,array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
$pdf->Line($xc, $yc - 2, $xc, $yc + 2,array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
$pdf->Circle($xc - 30 + (30 - $left_perc), $yc, 1, 0, 360, 'DF', array('width' => 0.25, 'dash' => 0, 'color' => array(255,0,0)), array(210, 0, 0));
$pdf->Circle($xc + 30 - (30 - $right_perc), $yc, 1, 0, 360, 'DF', array('width' => 0.25, 'dash' => 0, 'color' => array(255,0,0)), array(210, 0, 0));
$counter++;
}
我知道 TCPDF 具有创建不同形状的内置功能。我有一个案例,我必须创建一条线并将点作为点 (8,2) 放置在它上面,将 0 视为线的中心。使用 tcpdf line()
function. I created a line and placed dots on it see the screenshot below.
在此屏幕截图中,点 (8,2)
位于一条线上,其中 8 是距线中心的左侧点,2 是距线中心的右侧点。现在我必须将线旋转到 72 degrees
并将下一行与(左,右)点放在一起。对具有动态(左、右)点的总共 5 行重复相同的过程。
这是我目前使用的:
$counter = 1;
foreach($graph_points as $points){
// center of the line
$xc = 100;
$yc = 150;
if($counter > 1){
$pdf->Rotate(-72, $xc, $yc);
}
$left = round($points->left);
$left_perc = (($left*10)/100) * 50;
$right = round($points->right);
$right_perc = (($right*10)/100) * 50;
$pdf->SetDrawColor(200, 200, 200);
$pdf->Line($xc - 50 , $yc, $xc + 50 , $yc,array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
$pdf->Line($xc, $yc - 2, $xc, $yc + 2,array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
$pdf->Circle($xc - 50 + (50 - $left_perc), $yc, 1, 0, 360, 'DF', array('width' => 0.25, 'dash' => 0, 'color' => array(255,0,0)), array(210, 0, 0));
$pdf->Text($xc - 53 + (50 - $left_perc), $yc - 7, $left, false, false, true, 0, 0, '', 0, '', 0, false, 'T', 'T');
$pdf->Circle($xc + 50 - (50 - $right_perc), $yc, 1, 0, 360, 'DF', array('width' => 0.25, 'dash' => 0, 'color' => array(255,0,0)), array(210, 0, 0));
$pdf->Text($xc + 47 - (50 - $right_perc), $yc - 7, $right, false, false, true, 0, 0, '', 0, '', 0, false, 'T', 'T');
$counter++;
}
下面的截图是这段代码的输出,我想要一个有 5 条线及其点的五角形。
我已经尝试了 2 天,但没有找到任何可行的解决方案。请建议我以使用线创建五边形的方式进行计算。
谢谢
更新
我设法创建了形状,但边彼此连接不均匀,这也影响了数字的文本位置。
代码如下:
$counter = 1;
$xc = 100;
$yc = 150;
foreach($graph_points as $points){
// center of the line
if($counter > 1){
$xc = $xc - 65;
$yc = $yc - 45;
$pdf->Rotate(-72, $xc, $yc);
}
$left = round($points->left);
$left_perc = (($left*10)/100) * 50;
$right = round($points->right);
$right_perc = (($right*10)/100) * 50;
$pdf->SetDrawColor(200, 200, 200);
$pdf->Line($xc - 50 , $yc, $xc + 50 , $yc,array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
$pdf->Line($xc, $yc - 2, $xc, $yc + 2,array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
$pdf->Circle($xc - 50 + (50 - $left_perc), $yc, 1, 0, 360, 'DF', array('width' => 0.25, 'dash' => 0, 'color' => array(255,0,0)), array(210, 0, 0));
$pdf->Text($xc - 53 + (50 - $left_perc), $yc, $left, false, false, true, 0, 0, '', 0, '', 0, false, 'T', 'T');
$pdf->Circle($xc + 50 - (50 - $right_perc), $yc, 1, 0, 360, 'DF', array('width' => 0.25, 'dash' => 0, 'color' => array(255,0,0)), array(210, 0, 0));
$pdf->Text($xc + 47 - (50 - $right_perc), $yc, $right, false, false, true, 0, 0, '', 0, '', 0, false, 'T', 'T');
$counter++;
}
这是现在的截图。
经过3天的努力,我终于找到了一个可行的解决方案。在这里发布我的解决方案以防有人有相同的要求。
$xc = 100;
$yc = 200;
$counter = 1;
foreach($graph_points as $points){
if($counter > 1){
$xc = $xc - 39;
$yc = $yc - 28;
$pdf->Rotate(-72, $xc, $yc);
}
$left = round($points->left);
$left_perc = (($left*10)/100) * 30;
$right = round($points->right);
$right_perc = (($right*10)/100) * 30;
$pdf->SetDrawColor(200, 200, 200);
$pdf->Line($xc - 30 , $yc, $xc + 30 , $yc,array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
$pdf->Line($xc, $yc - 2, $xc, $yc + 2,array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
$pdf->Circle($xc - 30 + (30 - $left_perc), $yc, 1, 0, 360, 'DF', array('width' => 0.25, 'dash' => 0, 'color' => array(255,0,0)), array(210, 0, 0));
$pdf->Circle($xc + 30 - (30 - $right_perc), $yc, 1, 0, 360, 'DF', array('width' => 0.25, 'dash' => 0, 'color' => array(255,0,0)), array(210, 0, 0));
$counter++;
}