cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Use World Cup data to build models, explore spatial relationships, and create informative visualizations in JMP. Register. July 17, 2 pm US Eastern Time.
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
TDK_Long
Level III

Calculate the angle between two planes

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 ) )
);
2 REPLIES 2
Craige_Hales
Super User

Re: Calculate the angle between two planes

No idea about the rest of the script, but line 33 isn't written in JSL. 

n1 = [a1, b1_, -1];
n2 = [a2, b2_, -1];

Probably should be more like

n1 = a1 ||  b1_ || -1;
 or perhaps
n2 = a2 |/ b2_ |/ -1;

the n1 example should make a row vector and the n2 make a col vector.

Craige
Craige_Hales
Super User

Re: Calculate the angle between two planes

And the dot product is probably wrong too, you should look it up and figure out if JMP's element-wise multiply is what you need; the * is a matrix multiply which might not be the operator you need.

Craige

Recommended Articles