18910140161

HTML-PHP文件不显示任何输出堆栈溢出

顺晟科技

2022-10-19 13:59:56

245

我使用HTML和PH PHP来计算正常单位

<html>
<head>
<title> Comprehensive FORM CGI program </title>
</head>
<body bgcolor=#DDDDDD>
<p>
<!-- The lines above are the standard html header -->

<?php

  // First get the input variables and their values

$A = $_POST['f_A'];

$B = $_POST['f_B'];


$Acomponent = explode(",", $A);
$Bcomponent = explode(",", $B);

$AX = (int)$Acomponent[0];
$AY = (int)$Acomponent[1];
$AZ = (int)$Acomponent[2];
$BX = (int)$Bcomponent[0];
$BY = (int)$Bcomponent[1];
$BZ = (int)$Bcomponent[2];


function dot_product($AX, $AY, $AZ, $BX, $BY, $BZ){
$dotproduct = ($AX*$BX+$AY*$BY+$AZ*$BZ);
return($dotproduct);

}

function cross_product($AX, $AY, $AZ, $BX, $BY, $BZ){
        
        $i = ($AY*$BZ-$AZ*$BY);
        $j = (-1)*($AX*$BZ-$AZ*$BX);
        $k = ($AX*$BY-$AY*$BX);
        return($i);
        return($j);
        return($k);

}


function norm($AX, $AY, $AZ, $BX, $BY, $BZ) {
     
        
        
        $Anorm=sqrt(pow($AX,2)+pow($AY,2)+ pow($AZ,2));
        $Bnorm=sqrt(pow($BX,2)+pow($BY,2)+ pow($BZ,2));
        
        return($Anorm);
        return($Bnorm);

}

function anglebetween($dotproduct,$Anorm, $Bnorm) {
        $angle = acos($dotproduct/($Anorm*$Bnorm));
        return($angle);
}

function normalunitvector($i,$j,$k) {
   
        $crossnorm=sqrt(pow($i,2)+pow($j,2)+ pow($k,2));
        $normaluniti = $i/$crossnorm;
        $normalunitj = $j/$crossnorm;
        $normalunitk = $k/$crossnorm;
        $normalunit = [];
        $normalunit[0] = $normaluniti;
        $normalunit[1] = $normalunitj;
        $normalunit[2] = $normalunitk;
        return($normalunit);
}


dot_product($AX, $AY, $AZ, $BX, $BY, $BZ);
cross_product($AX, $AY, $AZ, $BX, $BY, $BZ);
norm($AX, $AY, $AZ, $BX, $BY, $BZ);
anglebetween($dotproduct,$Anorm, $Bnorm);
normalunitvector($i,$j,$k);

echo($angle);
echo($normaluniti);
echo($normalunitj);
echo($normalunitk);
?>
<p>
<hr>
<p>
</body>
</html>

AX、AY、AZ、BX、BY、BZ值打印良好,而angle、normaluniti、normalunij、normalunitk值打印不良

我不知道为什么,但我猜我的函数中有一个错误?

<html>
<head>
<title> Comprehensive FORM CGI program </title>
</head>
<body bgcolor=#DDDDDD>
<p>
<!-- The lines above are the standard html header -->

<?php

  // First get the input variables and their values

$A = $_POST['f_A'];

$B = $_POST['f_B'];


$Acomponent = explode(",", $A);
$Bcomponent = explode(",", $B);

$AX = (int)$Acomponent[0];
$AY = (int)$Acomponent[1];
$AZ = (int)$Acomponent[2];
$BX = (int)$Bcomponent[0];
$BY = (int)$Bcomponent[1];
$BZ = (int)$Bcomponent[2];


function dot_product($AX, $AY, $AZ, $BX, $BY, $BZ){
$dotproduct = ($AX*$BX+$AY*$BY+$AZ*$BZ);
return($dotproduct);

}

function cross_product($AX, $AY, $AZ, $BX, $BY, $BZ){
        
        $i = ($AY*$BZ-$AZ*$BY);
        $j = (-1)*($AX*$BZ-$AZ*$BX);
        $k = ($AX*$BY-$AY*$BX);
        return($i);
        return($j);
        return($k);

}


function norm($AX, $AY, $AZ, $BX, $BY, $BZ) {
     
        
        
        $Anorm=sqrt(pow($AX,2)+pow($AY,2)+ pow($AZ,2));
        $Bnorm=sqrt(pow($BX,2)+pow($BY,2)+ pow($BZ,2));
        
        return($Anorm);
        return($Bnorm);

}

function anglebetween($dotproduct,$Anorm, $Bnorm) {
        $angle = acos($dotproduct/($Anorm*$Bnorm));
        return($angle);
}

function normalunitvector($i,$j,$k) {
   
        $crossnorm=sqrt(pow($i,2)+pow($j,2)+ pow($k,2));
        $normaluniti = $i/$crossnorm;
        $normalunitj = $j/$crossnorm;
        $normalunitk = $k/$crossnorm;
        $normalunit = [];
        $normalunit[0] = $normaluniti;
        $normalunit[1] = $normalunitj;
        $normalunit[2] = $normalunitk;
        return($normalunit);
}


dot_product($AX, $AY, $AZ, $BX, $BY, $BZ);
cross_product($AX, $AY, $AZ, $BX, $BY, $BZ);
norm($AX, $AY, $AZ, $BX, $BY, $BZ);
anglebetween($dotproduct,$Anorm, $Bnorm);
normalunitvector($i,$j,$k);

echo($angle);
echo($normaluniti);
echo($normalunitj);
echo($normalunitk);
?>
<p>
<hr>
<p>
</body>
</html>

没有显示任何东西。如何解决此问题?


顺晟科技:

  1. 执行函数后,请将返回的值赋给局部变量
  2. 对于从单个函数返回多个值,请使用数组

因此,请在下面找到一个工作示例:

(为了测试,我添加了两行代码来赋值$A和$B,如果要应用$_POST的值,请删除它们)

<html>
<head>
<title> Comprehensive FORM CGI program </title>
</head>
<body bgcolor=#DDDDDD>
<p>
<!-- The lines above are the standard html header -->

<?php

  // First get the input variables and their values

$A = $_POST['f_A'];

$B = $_POST['f_B'];


$Acomponent = explode(",", $A);
$Bcomponent = explode(",", $B);

$AX = (int)$Acomponent[0];
$AY = (int)$Acomponent[1];
$AZ = (int)$Acomponent[2];
$BX = (int)$Bcomponent[0];
$BY = (int)$Bcomponent[1];
$BZ = (int)$Bcomponent[2];


function dot_product($AX, $AY, $AZ, $BX, $BY, $BZ){
$dotproduct = ($AX*$BX+$AY*$BY+$AZ*$BZ);
return($dotproduct);

}

function cross_product($AX, $AY, $AZ, $BX, $BY, $BZ){
        
        $i = ($AY*$BZ-$AZ*$BY);
        $j = (-1)*($AX*$BZ-$AZ*$BX);
        $k = ($AX*$BY-$AY*$BX);
        return($i);
        return($j);
        return($k);

}


function norm($AX, $AY, $AZ, $BX, $BY, $BZ) {
     
        
        
        $Anorm=sqrt(pow($AX,2)+pow($AY,2)+ pow($AZ,2));
        $Bnorm=sqrt(pow($BX,2)+pow($BY,2)+ pow($BZ,2));
        
        return($Anorm);
        return($Bnorm);

}

function anglebetween($dotproduct,$Anorm, $Bnorm) {
        $angle = acos($dotproduct/($Anorm*$Bnorm));
        return($angle);
}

function normalunitvector($i,$j,$k) {
   
        $crossnorm=sqrt(pow($i,2)+pow($j,2)+ pow($k,2));
        $normaluniti = $i/$crossnorm;
        $normalunitj = $j/$crossnorm;
        $normalunitk = $k/$crossnorm;
        $normalunit = [];
        $normalunit[0] = $normaluniti;
        $normalunit[1] = $normalunitj;
        $normalunit[2] = $normalunitk;
        return($normalunit);
}


dot_product($AX, $AY, $AZ, $BX, $BY, $BZ);
cross_product($AX, $AY, $AZ, $BX, $BY, $BZ);
norm($AX, $AY, $AZ, $BX, $BY, $BZ);
anglebetween($dotproduct,$Anorm, $Bnorm);
normalunitvector($i,$j,$k);

echo($angle);
echo($normaluniti);
echo($normalunitj);
echo($normalunitk);
?>
<p>
<hr>
<p>
</body>
</html>

您将它们用作函数内部的局部变量。它们的生命周期在函数的括号之间开始和结束。

试着告诉我这是否有效。

如果是这样,则可以存储AngleBetween($dotproduct,$anorm,$bnorm);在变量中或仅调用函数

  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航