|
-
Mar 8th, 2010, 03:02 AM
#1
Thread Starter
Lively Member
[RESOLVED] VB6 facing problems with Sine and Cosine
I was translating some codes from C++ to vb6 and I notice the results output when using sine or cosine is different for instance, sin(0.224654) will yield a result of 0.222769 when it should be 0.0039209. Any idea why?
Thanks.
-
Mar 8th, 2010, 03:07 AM
#2
Re: VB6 facing problems with Sine and Cosine
But Sine of 0.224654 is 0.222769070022729
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Mar 8th, 2010, 03:20 AM
#3
Re: VB6 facing problems with Sine and Cosine
Code:
?sin(.224654 *3.14159265/180)
3.92094192660541E-03
?cdec(sin(.224654 *3.14159265/180))
0.00392094192660541
it does not quite match the value using excel worksheet functions
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 8th, 2010, 03:31 AM
#4
Thread Starter
Lively Member
Re: VB6 facing problems with Sine and Cosine
 Originally Posted by westconn1
Code:
?sin(.224654 *3.14159265/180)
3.92094192660541E-03
?cdec(sin(.224654 *3.14159265/180))
0.00392094192660541
it does not quite match the value using excel worksheet functions
Sorry I am a little confused here, so which is which?
-
Mar 8th, 2010, 03:42 AM
#5
Re: VB6 facing problems with Sine and Cosine
Sin(0.224654) in vb6 and sin(0.224654) in Excel both give me 0.222769070022729
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Mar 8th, 2010, 03:52 AM
#6
Thread Starter
Lively Member
Re: VB6 facing problems with Sine and Cosine
 Originally Posted by koolsid
Sin(0.224654) in vb6 and sin(0.224654) in Excel both give me 0.222769070022729
Hmm..when I work in C++ it gives me 0.0039209419... same when I use my window xp calculator.
-
Mar 8th, 2010, 04:05 AM
#7
Re: VB6 facing problems with Sine and Cosine
Yes that's because what you pass to sin is very imp.
Sin returns the sine of the given angle(Radians). if 0.224654 is an angle(Radians) then 0.222769070022729 is correct but if 0.224654 is degrees then you need to change it to angle(Radians) and then 0.0039209 is correct...
1 radian = 57.2957795 degrees
So
Code:
Format(Sin(0.224654 / 57.2957795), "0.0000000") will give you 0.0039209
Last edited by Siddharth Rout; Mar 8th, 2010 at 04:13 AM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Mar 8th, 2010, 04:25 AM
#8
Thread Starter
Lively Member
Re: VB6 facing problems with Sine and Cosine
 Originally Posted by koolsid
Yes that's because what you pass to sin is very imp.
Sin returns the sine of the given angle(Radians). if 0.224654 is an angle(Radians) then 0.222769070022729 is correct but if 0.224654 is degrees then you need to change it to angle(Radians) and then 0.0039209 is correct...
1 radian = 57.2957795 degrees
So
Code:
Format(Sin(0.224654 / 57.2957795), "0.0000000") will give you 0.0039209
Thanks a lot for the explanation!
-
Mar 8th, 2010, 04:31 AM
#9
-
Mar 8th, 2010, 04:38 AM
#10
Re: VB6 facing problems with Sine and Cosine
Sorry I am a little confused here, so which is which?
the return from sin is a double
first example
by type casting to decimal you get the returned value as a decimal value
both are equal
sid converted the return to a formatted string, but i prefered to keep as a value
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|