trigonometry
holy
Posts: 9
i need some help about trig.
in mathematic term, 20 cos 30 = 17.32
however in bs2, i couldn't get the same result...
i have read about the brad, but i could not understand the explanation..
could som1 help me explain how to get the same result as my example?
in mathematic term, 20 cos 30 = 17.32
however in bs2, i couldn't get the same result...
i have read about the brad, but i could not understand the explanation..
could som1 help me explain how to get the same result as my example?
Comments
The sample from the help file shows this:
Main:
FOR degr = 0 TO 359 STEP 45 ' Use degrees
cosine = COS (degr * 128 / 180) ' Convert to brads, do COS
DEBUG "Angle: ", DEC degr, TAB ' Display results
DEBUG "Cosine: ", SDEC cosine, CR
NEXT
END
Considering what you want as an answer,you should be able to change the third line in the sample to: cosine = 20* (COS (degr*128/180))
More info provided usually means a better chance of getting an accurate answer.
Cheers
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
'{$STAMP BS2}
'{$PBASIC 2.5}
x VAR word
x=20 * COS (30*128/180)
DEBUG DEC3 ? x,
x=220
when i use
'{$STAMP BS2}
'{$PBASIC 2.5}
x VAR word
x=20 * COS 30
DEBUG DEC3 ? x
x=880.
the problem is i need the answer to be 20 cos 30 = 17.32. how to get this answer?? does basic stamp support floating number??
sine VAR word
degr VAR word
x VAR word
start:
DEBUG "Enter degree", cr
DEBUGIN DEC degr
·sine = SIN (degr */$00B6)' 128 / 180)-Convert to brads
· DEBUG SDEC ? sine, cr
· x = sine *79
· DEBUG· ".",DEC ? x, cr
· x = (x/10) * 20
· DEBUG DEC x/1000, ".", DEC3 x, cr, cr
· GOTO start
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
The only way is work with whole numbers (so your answer is 1732) and then get it to be displayed digit by digit, inserting the "." as a character.
Also, the result of COS(30*128/180) is about 110, as per the Help file explanantion of COS. In terms of the traditional COS, that should be 110/127=0.8661 and multiplied by 20 gives 17.32.
In our earlier example, therefore we'd want x = 20 * (cos(30*128/180))/127 that would give the 17; then, use the // operator to get the remainder in the calculation: y=20*(cos(30*128/180))//127
Cheers
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
That uses the */ operator twice, once to convert degrees to brads (that is the same as Sid used, 182=$B6), then again as a fractional multiplier, with the extra factor of 100 thrown in to get the extra digits to the right of the decimal point. The correct answer would be 17.32, but 17.34 is pretty close and about the best that the Stamp COS operator can do.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
sine VAR Word
degr CON 70 'cos20=sin70
sine2 VAR Word
cmdist CON 150
cm VAR Word
IF (cmdist>70) THEN
sine = SIN (degr */$00B6)' 128 / 180)-Convert to brads
sine = sine *79
sine = ((sine/10) * 70) /1000
cm=cmdist-70
sine2 = SIN (degr */$00B6)' 128 / 180)-Convert to brads
sine2 = sine2 *79
sine2 = ((sine2/10) * cm)/1000
sine=sine+sine2
ELSEIF (cmdist<=70) THEN
sine = SIN (degr */$00B6)' 128 / 180)-Convert to brads
sine = sine *79
sine = (sine/10) * cmdist
ENDIF
DEBUG DEC sine, ".", DEC3 sine, CR, CR
however tracy allen's calculation give a better solution compared to newzed [noparse]:)[/noparse]. it is more accurate and i dont have to make modification to it.
thanks to those who has lend me a hand in solving this problem. you guys are helpful [noparse]:)[/noparse]
k let me start, im using a ping sensor which has an inclination of 34degree, k i need to detect an object in front of me, this part has already been solved, i could calculate the distance accurately.
However the difficult part start from here on... the ping sensor needs to determine the height of the object in front of me. The ping sensor is mounted 95cm above ground, and inclined downward 34degree. so in order to get the height of the object in front of me, i need to determine the height by subtracting the 95cm with the cos34 multiplied by distance detected from ping sensor to the object. such as 95 - (cmdist * cos 34). this will give the height of the object in theory.
however. this does not happen when i am implementing the ping sensor into action. for example, the distance from the ping to object or should we call hypotenus is 200, thereforeby implementing theorem pythagoras, sqrt(200^2-95^2)=180cm. this is correct from math and also with the ping. now to determine the height of the object, 95-(200cos34)=-71cm. This is very confusing. and i have experimented with many angle. the answer is the same for the distance. is it caused by the reflection of the ping sensor with the floor?
can anyone suggest to me how to determine height of the object from this setup?? [noparse]:([/noparse]
Post Edited (holy) : 3/17/2007 6:24:53 AM GMT
·
·
COS(34) = 0.829
·
·
1) Determine the hypotenuse of your offset height... (using your example 95cm)
·
95cm / 0.829 = 114.596cm
·
2) Read current Ping value in cm and subtract #1 above to determine hypotenuse relative to the objects height (using your example of 200cm)
·
200cm - 114.595cm = 85.404cm
·
3) Convert hypotenuse in #2 to object height
·
85.404cm * 0.829 = 70.8cm
·
·
·
What is the SIZE of the object you are trying to determine the height on?· Could you mount the PING sensor directly overhead and then use simple subtraction?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 3/17/2007 7:51:34 AM GMT
the problem is that it can detect the distance accurately but not the height.
i am stuck to this problem. taking the cos of this problem, 200cos34=165cm which
is higher than the elevation of the ping which is 95cm. how can this be??
i am only thinking that the refelcted wave caused this problem.. is it right??
is there any solution to my problem??
the object's height to be determined is 20cm. and the ping cannot be positioned as you have stated because the
object will not be detected if the object is getting nearer the ping.
Post Edited (holy) : 3/17/2007 8:21:37 AM GMT
Or so I think.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Shawn Lowe
My last words shall be - "NOT YET!!!"
I imagine that if the measurement is longer than you believe it should be it doesn’t mean the calculation is incorrect, but rather that the signal is traveling farther than you expect.
Perhaps it would be helpful to collect raw time data from your device, and then calculate the height using a calculator. Once the math is verified, duplicating it on the Stamp will indicate a calculation error versus a measurement error more surely. Perhaps, too, monitor the measurements ‘real time’ and perhaps see when (if) the calculation is correct.
Never mind. I'm thinking PIR not PING! Whats a few letters...
and basis of operation...
Beau's math is right. The line in his drawing represents where on the object the ping is sending its signal. Your height would be the shortest distance the sensor says it sees.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Shawn Lowe
My last words shall be - "NOT YET!!!"
Am I missing something about the 200 cm reading?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Here is a diagram with those sides on the left, and the one with 34 degrees at the top on the right. They are very different triangles!!!
Which is it, I wonder?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
the first diagram of tracy is the right one and bare in mind that the object is moving closer to the ping.
just curious.... if i add an ir, and it is within the region of the ping, will it effect the measurement of
the ping and ir? will using ir solve my problem??? or it is just making things worst?
Post Edited (holy) : 3/18/2007 3:25:59 AM GMT
IR and ultrasound measurements shouldn't interfere with one another. However, the IR range finder also works best when it has a flat surface in front of it to look at, and the quality of the surface is even more picky than with ultrasound. (Thinking of the Sharp GP2D12) But that is not to say it can't be done, by scanning the environment with the narrow beam. Here is a nice tutorial that shows some nice results on object avoidence and comparison of ultrasound and IR:
www.societyofrobots.com/sensors_sharpirrange.shtml
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com