7 kyu
Cartesian coordinates from degree angle
143 of 1,661user4190256
Loading description...
Algorithms
Mathematics
Geometry
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
python new test framework is required. updated in this fork
Approved
Added an NASM translation: https://www.codewars.com/kumite/6298e0105f99e3001a4bcfde?sel=6298e0105f99e3001a4bcfde
sin(90) = 0.893996663601 ?? How is this possible? C language. Math included. Any one can help me?? Thanks.
Those 90 are radians, not degrees.
Write a simple function that takes polar coordinates (an angle in degrees and a radius) and returns the equivalent cartesian coordinates (rounded to 10 places). It says angles in degrees?
Please read the docs: https://www.programiz.com/c-programming/library-function/math.h/sin,
sin
uses radians, not degrees. What your function has to do, doesn't matter. Do the conversion before using it, otherwise, you won't get the result you expect.Thank u :)
When I use the inverse sine and inverse cosine I passed a 100/100 random insertion and 2/3 fixed ones. Also when I use the conversion to radians then the sine fucntion still same thing. This fixed case when the input is 0 (degrres) and 1 (radius) gives me an error, missmatched results.
C lang:
Submitted: {9848.07753012, 1736.48177667} Expected: {9848.07753012, 1736.48177667}
Submitted: {781.444791958, 180.410745584} Expected: {781.444791958, 180.410745584}
Still no random tests in JS and ruby
A minor typo in the description:
... (rou[N]ded to 10 places).
C Translation available
More a math than a programming exercise.
All languages except python are lacking random tests
Haskell fixed.
I've added them in ruby, JS, Java. Please check them and resolve this issue.
lacking C so, no.
edit: mmh, C is recent. rowcased added them?
C has random tests, I've sent screenshot on gitter.
(the C translation had random tests prior to approval)
.
(oops)
Never 6 kyu. Downranked to 7kyu (to be nice. Could even be 8...)
I got this error on the last test. Everything else is ok... Expected: '[0, 1]', instead got: '[-0, 1]'
I'm using javascript and on the last test case, my x coordinate is resulting in -0, whereas all the other test cases the x coordinate is either 0, or the correct number.
The only case that fails is the last because its -0 and not 0.
I understand that in the last test case, using my method, the cos is approaching 0 from the negative side.
Maybe you could show the radius and degrees in the test cases. So we could check your answers with a calculator.
Hi I have passed test for 10 rounding decimal places but can't pass below example, Not sure what is the problem with my rounding. I am using JavaScript btw Test Passed: Value == [0.7071067812,0.7071067812]
✘ Expected: [9848.0775301221,1736.4817766693], instead got: [9848.07753,1736.481777]
That looks like rounding to 10 significant figures more than 10 decimal places.
Maybe you're calling the wrong method or rounding at the wrong spot :)
(Java)All the tests pass except this:
test_5(CoordinatesTest)
Incorrect coordinates expected: but was:
What does that mean, I am so confused
Sad story: In haskell
just set Math.round(cos(pi/2), 10); so it will round your result for 10 places.
Tests in Java are broken. No solutions pass.
seems resolved, now.
It seems there's bug in Javascript submit test #5: (9848.0775301221, 1736.4817766693) should equal (9848.07753,1736.481777)
10 decmial places, not significant figures.
When submitting my result for this I get:
90 1 90==-0.4480736161291701 Test Passed: Value == [0,1] 90 2 90==-0.8961472322583403 Expected: [0,2], instead got: [-1,2]
as you can see for 90,2 where 2 is the radius my math totals -0.89 and that rounded is -1 but the test fixture expects 0, why is that?
Rotating a vector 90 degrees counter-clockwise from x axis should give a vector pointing at the +y direction, so a [-1,2] would be absurd. You should recheck your math.
Also, the tests require rounding to 10 decimal places, not the nearest integer.
Expected: [0,2], instead got: [0,1],
what kind of tests are you using? How can you expect 2 when expecting cartesian coordiantes that can only go from -1 --> 1?
If the radius of a circle is > 1, coordinates on the circle can be greater than 1 or less than -1.
This comment has been hidden.
This comment has been hidden.
On the Java version, when I run the tests, I see the text result without any actual number values. Something like this, "Expected: Received: " No test values are displayed, either. Is this likely due to something I'm doing wrong, or a problem with the test cases? Interestingly enough, my code does pass the initial tests, but on the subsequent batch, there are some failures. None of them, though, display any actual values on the results. Any ideas?
Yes, the tests are aren't printing the tested values and expected results. The most likely problem is rounding. I'll try and get the tests fixed so they print out what they are expecting. I'll see if I can add some random tests as well. Thanks.
Issue in Python, 4th test I get this output: (1.0, 1.0) should equal (0.7071067812, 0.7071067812)
Shouldnt (45.0, 1.0) equal (0.7071067812, 0.7071067812) ? Might have misunderstood the exercise though.
I can't find the bug you are talking about in the python version...(45.0, 1.0) does equal (0.7071067812, 0.7071067812)
(1.0, 1.0) should equal (0.7071067812, 0.7071067812) Is what the unit test tells me
This is not a kata issue, this is your solution issue.
You are asked to calculate (x, y) for the end of a vector that starts at (0, 0), heads in the direction of 45 degrees and has a radius of 1. This means that distance between (0, 0) and (x, y) must be exactly 1.
Your solution returns (1.0, 1.0) - but this is wrong! A vector (0, 0) -> (1, 1) has length of squareroot(2), i.e. approximately 1.4142.
I'm guessing their rounding is wrong.
In Ruby, the template is missing the radius parameter.
fixed
This comment has been hidden.
Added a small number of integer and float random tests. Please try it out and let me know if they work for you. Thanks.
Nice!
I suggest adding an example in description that shows how 10 decimal places actually look like (e. g. for a 45 degrees angle). Like that:
Thanks, I've added your example.
It seems there's bug in Python submit test #5:
(9848.0775301221, 1736.4817766693) should equal (9848.07753, 1736.481777)
The kata description states the values should be rounded to 10 places, while this test clearly expects rounding to 6 places instead.
Thanks, fixed it in the ruby example as well.
Thanks! Green light! :)
In traditional cartesian coodrdinates it would be (0.0, 1.0), x = cos(a), y = sin(a)
Oops! You are 100% correct. Thanks for picking me up on that! Fixed it.