|
Post by thejoecole on May 2, 2018 20:53:32 GMT
I'm working on a small app for work to determine what depression angle I need to set a camera for oblique aerial photography.
I'm not strong in math, but my wife is and she showed me a formula using Tangent. I looked in the JB Help and saw an example to use Tangent:
TAN( n )
This function returns the tangent of the angle n. The angle n should be expressed in radians
Usage:
for t = 1 to 45
print "The tangent of "; t; " is "; tan(t)
next t I understand this OK enough, but the formula I have requires the use of an inverse Tangent. Not sure how to do this with code. Also, my desired output will be in degrees and as I understand the example above, the output is in radians and I'll have to convert to degrees.
Does anyone have experience with this?
Thanks, Joe
|
|
|
Post by B+ on May 2, 2018 20:56:46 GMT
pi = acs(-1) 'quick way for pi radianAngle * 180/pi = degreeAngle It is handy to make some coversion numbers GLOBAL: global PI, DEG, RAD PI = acs(-1) DEG = 180 / PI RAD = PI / 180
Put the GLOBAL definitions at the top of your program, then you can use these anywhere in a program. To convert a radian angle to a degree angle multiply by DEG. To convert a degree angle to radian angle multiply by RAD. Now another name for Inverse Tangent is Arc Tangent. It is the angle in radians whose Tangent is some ratio usually a y difference in height divded by an x difference in horizontal measure, usually and atan2( y difference, x difference) will usually get you that. The tangent is the side opposite the angle in question (of a right triangle = one angle is 90 degrees) divided by the side adjacent to the angle (connects to the angle.) Tangent is ratio of the two side lengths = y/x, arc tangent is the angle that produces that ratio.
|
|
|
Post by thejoecole on May 3, 2018 1:05:20 GMT
Thanks B+
I'll give this a whirl and see if I can put together something useful.
|
|
|
Post by bluatigro on May 3, 2018 7:25:47 GMT
maybe you can use this :
function v3d.dot( x1 , y1 , z1 , x2 , y2 , z2 ) v3d.dot = x1 * x2 + y1 * y2 + z1 * z2 end function
function v3d.angle( x1 , y1 , z1 , x2 , y2 , z2 ) dot = v3d.dot( x1 , y1 , z1 , z2 , y2 , x2 ) l1 = v3d.lenght( x1 , y1 , z1 ) l2 = v3d.lenght( x2 , y2 , z2 ) v3d.angle = acs( dot / ( l1 * l2 ) ) end function
function v3d.lenght( x , y , z ) v3d.lenght = sqr( x * x + y * y + z * z ) end function
|
|
|
Post by tsh73 on May 3, 2018 11:13:50 GMT
Have a look at this. It uses built-in ATN. (it will fail if dy = 0 , by using atan2 you avoid that) nomainwin open "click somewhere" for graphics_nsb_nf as #gr #gr "trapclose [quit]" #gr "down"
#gr "home; posxy cx cy" #gr "circle 10" #gr "when mouseMove [move]" #gr "when leftButtonUp [mUp]"
lastX=cx+1:lastY=0 pi=acs(-1) 'notice pi wait
[move] #gr "color white" #gr "home; goto ";lastX;" ";lastY lastX=MouseX lastY=MouseY #gr "color black" #gr "home; goto ";lastX;" ";lastY wait
[mUp]
lastX=MouseX lastY=MouseY dy=lastY-cy dx=lastX-cx #gr "color red" #gr "home" #gr "\dy=";dy;" " #gr "\dx=";dx;" " '#gr "\ATN(dy/dx)=";using("####.##", atn(dy/dx));" " 'rad #gr "\ATN(dy/dx)=";using("####.##", atn(dy/dx)*180/pi);" " 'degrees #gr "home; goto ";lastX;" ";lastY
wait [quit] close #gr end
|
|
|
Post by B+ on May 4, 2018 14:23:15 GMT
Hi Joe, How are you coming along? bluatigro has given code for 3D calculations but you need a system origin for those x, y, z. Ha! well I guess you need that for 2D too. tsh73 has a calculator but instead of key presses you can draw the angle in question with mouse click. OK I just looked up a diagram of what you are trying and tangent of angle in question is x/y ratio as I have labeled diagram: So atan2(x, y) should give you the angle in radians A * 180 / pi is angle in degrees. x and y are positive number lengths. x is the side opposite angle in question, y is side adjacent to angle in question tan = opposite/adjacent. It looks as if for "oblique aerial photographs", we are talking about the angle at the other end of a right triangle for the camera. We had been giving you angles from the ground to the camera. A picture is worth a 1000 replies!
|
|
|
Post by B+ on May 4, 2018 15:15:03 GMT
I have modified tsh73 code for Joe's angle question.
See if this looks right now?
nomainwin open "click below circle 4 angle" for graphics_nsb_nf as #gr #gr "trapclose [quit]" #gr "down"
#gr "home; posxy cx cy" #gr "circle 10" #gr "when mouseMove [move]" #gr "when leftButtonUp [mUp]"
lastX=cx+1:lastY=0 pi=acs(-1) 'notice pi wait
[move] #gr "color white" #gr "home; goto ";lastX;" ";lastY lastX=MouseX lastY=MouseY #gr "color black" #gr "home; goto ";lastX;" ";lastY wait
[mUp]
lastX=MouseX lastY=MouseY dy=lastY-cy dx=abs(lastX-cx) #gr "place 0 50" #gr "color red" '#gr "home" #gr "\height = ";dy;" " #gr "\ground to plumb = ";dx;" " '#gr "\ATN(dy/dx)=";using("####.##", atn(dy/dx));" " 'rad #gr "\ATN(ground to plumb / height) = ";using("####.##", atn(dx/dy)*180/pi);" " 'degrees #gr "home; goto ";lastX;" ";lastY
wait [quit] close #gr end
You should now get the camera angle to target shot on ground.
Camera angle in degrees = atan2( distance target to plumb on ground, height of camera ) * 180 / pi
|
|
|
Post by thejoecole on May 4, 2018 19:15:19 GMT
Thanks for all the help. I will definitely share the final product.
|
|