github.com/archlabjp/eeslism-go@v0.0.0-20231109122333-4bb7bfcdf292/eeslism/INOROUT.go (about)

     1  //This file is part of EESLISM.
     2  //
     3  //Foobar is free software : you can redistribute itand /or modify
     4  //it under the terms of the GNU General Public License as published by
     5  //the Free Software Foundation, either version 3 of the License, or
     6  //(at your option) any later version.
     7  //
     8  //Foobar is distributed in the hope that it will be useful,
     9  //but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
    11  //GNU General Public License for more details.
    12  //
    13  //You should have received a copy of the GNU General Public License
    14  //along with Foobar.If not, see < https://www.gnu.org/licenses/>.
    15  
    16  /*
    17  
    18   点と面の交点が平面の内か外かを判別する
    19   FILE=INOROUT.c
    20   Create Date=1998.10.26
    21  
    22  */
    23  
    24  package eeslism
    25  
    26  import (
    27  	"fmt"
    28  	"math"
    29  	"os"
    30  )
    31  
    32  func INOROUT(Px, Py, Pz float64, P0, P1, P2 XYZ, S, T *float64) {
    33  	var Sx01, Sy01, Sz01, Tx03, Ty03, Tz03 float64
    34  	var AA1, BB1, CC1, aa1, bb1, cc1 float64
    35  
    36  	Sx01 = P1.X - P0.X
    37  	Sy01 = P1.Y - P0.Y
    38  	Sz01 = P1.Z - P0.Z
    39  	Tx03 = P2.X - P0.X
    40  	Ty03 = P2.Y - P0.Y
    41  	Tz03 = P2.Z - P0.Z
    42  
    43  	AA1 = Tx03*Sy01 - Ty03*Sx01
    44  	BB1 = Ty03*Sz01 - Tz03*Sy01
    45  	CC1 = Tx03*Sz01 - Tz03*Sx01
    46  
    47  	CAT(&AA1, &BB1, &CC1)
    48  
    49  	if math.Abs(AA1) > 0.0 {
    50  		*T = (Sy01*Px - Sx01*Py - P0.X*Sy01 + P0.Y*Sx01) / (Tx03*Sy01 - Ty03*Sx01)
    51  	} else if math.Abs(BB1) > 0.0 {
    52  		*T = (Sz01*Py - Sy01*Pz - P0.Y*Sz01 + P0.Z*Sy01) / (Ty03*Sz01 - Tz03*Sy01)
    53  	} else if math.Abs(CC1) > 0.0 {
    54  		*T = (Sz01*Px - Sx01*Pz - P0.X*Sz01 + P0.Z*Sx01) / (Tx03*Sz01 - Tz03*Sx01)
    55  	} else {
    56  		fmt.Printf("error inorout\n0X=%f 0Y=%f 0Z=%f\n1X=%f 1Y=%f 1Z=%f\n2X=%f 2Y=%f 2Z=%f\n",
    57  			P0.X, P0.Y, P0.Z, P1.X, P1.Y, P1.Z, P2.X, P2.Y, P2.Z)
    58  		// Exit the program with an error code
    59  	}
    60  
    61  	aa1 = Sx01
    62  	bb1 = Sy01
    63  	cc1 = Sz01
    64  
    65  	CAT(&aa1, &bb1, &cc1)
    66  
    67  	if math.Abs(aa1) > 0.0 {
    68  		*S = (Px - (*T)*Tx03 - P0.X) / Sx01
    69  	} else if math.Abs(bb1) > 0.0 {
    70  		*S = (Py - (*T)*Ty03 - P0.Y) / Sy01
    71  	} else if math.Abs(cc1) > 0.0 {
    72  		*S = (Pz - (*T)*Tz03 - P0.Z) / Sz01
    73  	} else {
    74  		fmt.Println("error inorout2")
    75  		os.Exit(1)
    76  	}
    77  }