Hi folks,
I have 30 discrete points in X, Y, Z defining plane 1, and 30 other points in X, Y, Z defining plane 2, I need to calculate the angle between plane 1 and plane 2. The ChatGPT provides the following JSL script, but it stuck at row #33. Could any of you help check the two attachments (*.jmp and *.jsl) to get this script going? Thanks a lot.
// Use current data table
dt = Current Data Table();
// Subset for Plane1 and Plane2
dt1 = dt << Subset( Where( :Plane == "Plane1" ), Output Table Name( "Plane1" ) );
dt2 = dt << Subset( Where( :Plane == "Plane2" ), Output Table Name( "Plane2" ) );
// Fit plane 1: z = a1*x + b1*y + c1
b1 = dt1 << Fit Model(
Y( :Z ),
Effects( :X, :Y ),
Personality( "Standard Least Squares" ),
Emphasis( "Effect Leverage" ),
Run( "Fit Model" )
);
coeff1 = b1 << Get Estimates;
a1 = coeff1["X"];
b1_ = coeff1["Y"];
// Fit plane 2: z = a2*x + b2*y + c2
b2 = dt2 << Fit Model(
Y( :Z ),
Effects( :X, :Y ),
Personality( "Standard Least Squares" ),
Emphasis( "Effect Leverage" ),
Run( "Fit Model" )
);
coeff2 = b2 << Get Estimates;
a2 = coeff2["X"];
b2_ = coeff2["Y"];
// Normal vectors: [a, b, -1]
n1 = [a1, b1_, -1];
n2 = [a2, b2_, -1];
// Compute dot product and magnitudes
dotProd = Sum( n1 * n2 );
mag1 = Sqrt( Sum( n1 ^ 2 ) );
mag2 = Sqrt( Sum( n2 ^ 2 ) );
// Compute angle in degrees
cosTheta = dotProd / (mag1 * mag2);
thetaRad = ACos( cosTheta );
thetaDeg = thetaRad * (180 / Pi());
// Display result
New Window( "Angle Between Planes",
Text Box( "Angle (degrees): " || Char( thetaDeg ) )
);