Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

Sinus and Cosinus calculation in javacard?

JavaCard Applet Development Related Questions and Answers.
mhsnmaghsoodloo
Posts: 24
Joined: Thu Apr 07, 2016 12:14 pm
Points :457
Contact:

Sinus and Cosinus calculation in javacard?

Post by mhsnmaghsoodloo » Tue Sep 26, 2017 2:27 pm

Hello everyone,
I want to calculate sinus and cosinus in javacard. what is the best and fastest solution?
Thank a lot.

User avatar
mabel
Posts: 237
Joined: Mon May 18, 2015 3:09 am
Points :1705
Contact:

Re: Sinus and Cosinus calculation in javacard?

Post by mabel » Tue Sep 26, 2017 11:55 pm

Just try to use Look-up table method.

Define an array with size 360 bytes, direct look up the table to calculate sinus and cosinus.

mhsnmaghsoodloo
Posts: 24
Joined: Thu Apr 07, 2016 12:14 pm
Points :457
Contact:

Re: Sinus and Cosinus calculation in javacard?

Post by mhsnmaghsoodloo » Wed Sep 27, 2017 1:43 am

mabel wrote:Just try to use Look-up table method.

Define an array with size 360 bytes, direct look up the table to calculate sinus and cosinus.

Thank you very much mabel.

Tarantino
Posts: 101
Joined: Wed Aug 19, 2015 1:56 am
Points :478
Contact:

Re: Sinus and Cosinus calculation in javacard?

Post by Tarantino » Wed Sep 27, 2017 2:06 am

mabel wrote:Just try to use Look-up table method.

Define an array with size 360 bytes, direct look up the table to calculate sinus and cosinus.


It's indeed a good method. But there is still a problem. Look-up table method is available for integer angle. If you need to handle the angle with decimals, this method is not a good one.
The greatest glory in living lies not in never falling, but in rising every time we fall.--Nelson Mandela

scplatform
Posts: 39
Joined: Wed Aug 31, 2016 9:55 pm
Points :372
Contact:

Re: Sinus and Cosinus calculation in javacard?

Post by scplatform » Wed Sep 27, 2017 5:36 am

Maybe use a factor can solve your problem,e.g:sin1 => sin1*500, and you'll get the array like this:

Code: Select all

SIN[] =
{
    0, 8, 17, 26, 35, 44, 53, 62, 71, 80, 88, 97, 106, 115, 123, 132, 141, 149, 158,
    166, 175, 183, 191, 200, 208, 216, 224, 232, 240, 248, 255, 263, 271, 278, 286,
    293, 300, 308, 315, 322, 329, 335, 342, 349, 355, 362, 368, 374, 380, 386, 392,
    397, 403, 408, 414, 419, 424, 429, 434, 438, 443, 447, 452, 456, 460, 464, 467,
    471, 474, 477, 481, 484, 486, 489, 492, 494, 496, 498, 500, 502, 504, 505, 507,
    508, 509, 510, 510, 511, 511, 511, 512, 511, 511, 511, 510, 510, 509, 508, 507,
    505, 504, 502, 500, 498, 496, 494, 492, 489, 486, 484, 481, 477, 474, 471, 467,
    464, 460, 456, 452, 447, 443, 438, 434, 429, 424, 419, 414, 408, 403, 397, 392,
    386, 380, 374, 368, 362, 355, 349, 342, 335, 329, 322, 315, 308, 300, 293, 286,
    278, 271, 263, 255, 248, 240, 232, 224, 216, 208, 200, 191, 183, 175, 166, 158,
    149, 141, 132, 123, 115, 106, 97, 88, 80, 71, 62, 53, 44, 35, 26, 17, 8, 0, -8,
    -17, -26, -35, -44, -53, -62, -71, -80, -88, -97, -106, -115, -123, -132, -141,
    -149, -158, -166, -175, -183, -191, -200, -208, -216, -224, -232, -240, -248,
    -256, -263, -271, -278, -286, -293, -300, -308, -315, -322, -329, -335, -342,
    -349, -355, -362, -368, -374, -380, -386, -392, -397, -403, -408, -414, -419,
    -424, -429, -434, -438, -443, -447, -452, -456, -460, -464, -467, -471, -474,
    -477, -481, -484, -486, -489, -492, -494, -496, -498, -500, -502, -504, -505,
    -507, -508, -509, -510, -510, -511, -511, -511, -512, -511, -511, -511, -510,
    -510, -509, -508, -507, -505, -504, -502, -500, -498, -496, -494, -492, -489,
    -486, -484, -481, -477, -474, -471, -467, -464, -460, -456, -452, -447, -443,
    -438, -434, -429, -424, -419, -414, -408, -403, -397, -392, -386, -380, -374,
    -368, -362, -355, -349, -342, -335, -329, -322, -315, -308, -300, -293, -286,
    -278, -271, -263, -256, -248, -240, -232, -224, -216, -208, -200, -191, -183,
    -175, -166, -158, -149, -141, -132, -123, -115, -106, -97, -88, -80, -71, -62,
    -53, -44, -35, -26, -17, -8, 0
};

JCaberham
Posts: 26
Joined: Mon Nov 30, 2015 3:02 am
Points :208
Contact:

Re: Sinus and Cosinus calculation in javacard?

Post by JCaberham » Wed Sep 27, 2017 5:54 am

To handle the angle with decimals, try to use this formula
sin(a+b) =sina*cosb+cosa*sinb
cos(a+b) = cosa*cosb - sina*sinb


Take angle 45.5 as an example,

sin(45+0.5) = sina45*cos0.5 + cos45*sin0.5

But you may need to define 4 arrays sin[0~360], cos[0~360], sin[0.0~0.1],cos[0.0~0.1]

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 57 guests

JavaCard OS : Disclaimer