Convert Degrees to Pitch: software converts in one direction; I need the other dir.

jayh99

New member
Joined
Oct 2, 2018
Messages
4
Bare with me here, I'm a software developer, I use math in my software, but never tried to calculate something this.

I have this formula which works fine:
function CalculateDegrees(pitch){
var result = 0;
var v2 = 12;
var hyp1 = Math.sqrt(Math.pow(pitch, 2) + Math.pow(v2, 2));
var ang1 = pitch / hyp1;
var ang2 = Math.acos(ang1);
result = ang2 * (180 / Math.PI);
result = Math.round(result * 100) / 100;
return result;
}

If you pass in a pitch of 12, the result is 45 degrees.

I'm wanting to create the exact opposite of this formula where Degrees would be passed in and Pitch is calculated and returned. I apologize if Pitch isn't the correct terminology for it, like I said, this definitely isn't my strong suit. I just need layman's terms as to how I would go about calculating that value.
 
Bare with me here, I'm a software developer, I use math in my software, but never tried to calculate something this.

I have this formula which works fine:
function CalculateDegrees(pitch){
var result = 0;
var v2 = 12;
var hyp1 = Math.sqrt(Math.pow(pitch, 2) + Math.pow(v2, 2));
var ang1 = pitch / hyp1;
var ang2 = Math.acos(ang1);
result = ang2 * (180 / Math.PI);
result = Math.round(result * 100) / 100;
return result;
}

If you pass in a pitch of 12, the result is 45 degrees.

I'm wanting to create the exact opposite of this formula where Degrees would be passed in and Pitch is calculated and returned. I apologize if Pitch isn't the correct terminology for it, like I said, this definitely isn't my strong suit. I just need layman's terms as to how I would go about calculating that value.
Can't do that - need to keep my shirt on! Forum Rule!!

Can you please define "pitch" and "Degrees" in this context?

I am assuming degrees is referring to an angle - but angle of what?

Similarly "pitch" has different in different context - what is your context?

Can you translate your program into simple english statements?
 
Bare with me here, I'm a software developer, I use math in my software, but never tried to calculate something this.

I have this formula which works fine:
function CalculateDegrees(pitch){
var result = 0;
var v2 = 12;
var hyp1 = Math.sqrt(Math.pow(pitch, 2) + Math.pow(v2, 2));
var ang1 = pitch / hyp1;
var ang2 = Math.acos(ang1);
result = ang2 * (180 / Math.PI);
result = Math.round(result * 100) / 100;
return result;
}

If you pass in a pitch of 12, the result is 45 degrees.

I'm wanting to create the exact opposite of this formula where Degrees would be passed in and Pitch is calculated and returned. I apologize if Pitch isn't the correct terminology for it, like I said, this definitely isn't my strong suit. I just need layman's terms as to how I would go about calculating that value.

I believe you mean pitch as in carpenters terms; i.e. a 12/12 pitch is 450.
here 12/12 is the tangent of the angle.
so tan(degrees)=pitch.
 
var v2 = 12

var hyp1 = Math.sqrt(Math.pow(pitch, 2) + Math.pow(v2, 2));

var ang1 = pitch / hyp1;
I read that code as:

\(\displaystyle \text{hyp1} = \sqrt{\text{pitch}^2 + 12^2}\)

It seems like you have a right triangle. The height is 12 units, and you've named it 'v2'.

You've named the base length 'pitch' and the hypotenuse length 'hyp1'.

You've named the angle opposite the height as 'ang1'. In other words, ang1 is the angle formed by the base and hypotenuse.

If this is all correct, then you can simplify code by using the tangent function (i.e., hypotenuse not needed).

tan(ang1) = v2/pitch

pitch = v2 / tan(ang1)

ang1 = arctan(v2/pitch)
 
Here's a diagram

Yes, a carpenter's pitch is what I'm talking about. It is always a right angle and is always based upon a 12" run. So if I'm given one angle, I know the other 2 based on 90 and 180-90-angle. How do I calculate the pitch/rise/? on the triangle below? I think you are all on the right track and I really appreciate the help so far.

I just wanted to add this diagram to be 100% certain of what I'm looking for.


diagram.jpg
 
Thank you all for your input on this. I was able to come up with this formula based on your responses:

12 * tan(angle * pi/180)

-->12 is my constant for the base

So far I believe that everything works as it should.
 
Top