Trigonometry math: help!

   2268   5   1
User Avatar
Member
1004 posts
Joined: April 2017
Offline
Hi!

I'm trying to find the length of the adjacent in a triangle but my math does not work. I have the hypotenuse and the angle (dot product) and I want to find the ajacent length.

I started by converting from dot product to radians with:

float radian = fit(DotProduct, 1, -1, 0, $PI);

And I thought I had to do:

float adjLength = hypotenuse*cos(radian)

But I don't get the right length. The result should be exactly 2 but the result of my math gets me 2.7589

- Olivier

Attachments:
trigono_find_adjacent.jpg (36.8 KB)

User Avatar
Member
2036 posts
Joined: Sept. 2015
Offline
Probably because your dot product wasn't calculated properly for your fit mapping.

So I'm not sure what your wanting to do, but in this hip the code calculates angle, then length.

Edit: Looked at this again. The dot product is the magnitude of the hypotenuse times the magnitude of the adjacent times the cosine of the angle you show. So in order to have gotten the dot product you show, you must have already knew what the length of the side you aim to know.
Edited by BabaJ - Oct. 25, 2018 09:21:51

Attachments:
Length via trigonometry_angles.hiplc (49.2 KB)

User Avatar
Member
1004 posts
Joined: April 2017
Offline
Forgot about this thread.

Thanks for troubleshooting!

To better explain, I have 2 points.
pt0 = 0, 0, 0
pt1 = -3, 0, 2

This is just a test so I can verify if my math holds up. In the real scenario, both points can be anywhere on the ground plane.

I found the distance between both(hypotenuse) and a normalized vector pointing from pt0 to pt1. I'm also using a vector pointing to to the right angle(for the test, I made it 0,0,-1 )to form an imaginary triangle.

//get point positions
vector bottomP = point(1, "P", 0);
vector topP = point(1, "P", 1);

//get point Ns
vector bottomN = normalize(point(1, "N", 0));
vector topN = point(1, "N", 1);


//trigonometry to find ajacent Soh Cah Toa:  using Cos = adj / hypo
//start by flattening on Y
vector bottomP2D = set(bottomP.x, 0, bottomP.z);
vector topP2D = set(topP.x, 0, topP.z);

float hypotenuse = distance(bottomP2D, topP2D);

float tempDot = dot(normalize(bottomN), normalize(topP2D-bottomP2D));
float radian = fit(tempDot, 1, -1, 0, $PI);

float adjLength = hypotenuse*cos(radian);
@adjLengthtest = adjLength;  //should give 2 but result is 2.7589

-Olivier
Edited by olivierth - Nov. 3, 2018 22:12:55

Attachments:
trigono_find_adjacent_02.JPG (211.3 KB)

User Avatar
Member
8525 posts
Joined: July 2007
Offline
dot product of 2 normalized vectors is not the angle as you assume
it is actually the cos of the angle

so all you need to do is
float adjLength = hypotenuse*tempDot;
Edited by tamte - Nov. 3, 2018 23:48:03
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
1004 posts
Joined: April 2017
Offline
Wow! I thought I had to use Soh-Cah-Toa. I have so much to learn!

Again, thanks a lot tamte! Cheers!

-Olivier
User Avatar
Member
5 posts
Joined: Aug. 2014
Offline
I am a beginner. Modeling a barn digital asset based on actual barn. For the roof, I know the measurement of hypotenuse and adjacent. I need to find the angle. I know the formula in words: cos(θ) = Adjacent / Hypotenuse, and then take -1 power... I think.

Is there a library where I can translate this formula into the command that Houdini will be able to execute?

Thanks much!

Alkesh.

PS: I figured out. just used "ACOS(A/H)", and that rotated the roof just at the correct angle. Thanks.
Edited by Alkesh Nanavaty - Jan. 12, 2021 12:20:06
  • Quick Links