Using curves or lines, we can easily spot roots from n-degree polynomials in 2D: wherever they cross the real line, we know there is a root. However, as we are well aware, roots can also be complex numbers. In this case, plotting curves no longer seem adequate since they won't be found at the real line. That's when coloring comes into place; by painting the 2D plane, we can visualize where complex or real roots are and get a sense of what's happening in a function.
In this problem, we will color the complex plane using the color space HSV. Imagine that there is a vector spawning from the origin to each point in the complex plane; horizontal axis imaginary and vertical axis real. Each vector has an angle α (from the real-line) and a norm β that defines a hue (H), and a brightness (V), respectively; for saturation (S), we assume a fixed value of 1,
. H and V must range from 0 to 1, and to fit them into it, we will have to divide the angle by
,
, and apply the cube root to the Min-max normalization of the distance,
(the cube root allows a faster transition between low and high brightness).
Once we have the HSV value for a point at the complex plane, we can use the function hsv2rgb to find the RGB corresponding value implement it if it becomes unavailable in the future (read about it here). All RGB values must be rounded to 4 decimal places to obtain the following result:
All you have to do in this problem is to reproduce the above result for any matrix size, m x n x 3, given m and n as input. Moreover, the complex plane origin is always in the middle of the image
. Notice that since the plane origin has the vector null, it will generate a black dot that brightens while going to the figure's edge.
Note-1: This problem is inspired by a 3Blue1Brown's video: https://www.youtube.com/watch?v=b7FxPsqfkOY, and I recommend that you watch his video if you haven't already. However, it is not required that you do to solve this problem.
This problem has two parts, since it may not be easy to do everything at once. And you are encouraged to use the code for this 1st part of the problem into the next: Problem 46963.
Note-2: This problem was last updated 21/08/2020; thanks to Alex's and Svyatoslav's feedback. All solutions were rescored. Please, let me know if anyone run into issues.
Solution Stats
Problem Comments
9 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers5
Suggested Problems
-
We love vectorized solutions. Problem 1 : remove the row average.
884 Solvers
-
549 Solvers
-
438 Solvers
-
Matlab Basics - Absolute Value
670 Solvers
-
457 Solvers
More from this Author5
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Hi, I have tried a first solution. Since I see only the hash value of the correct solution and not the solution itself, I am not sure how to finalize my code.. So, some questions:
(1) where exactly is the zero angle? The text says on the real line (which should be to the right?) the picture suggests to the bottom (isn't red equal to zero angle in HSV?)
(2) what exactly is beta? The text says "norm" --> I assumed Euclidean norm. is this correct?
(3) does the test suite account for numerical noises due to different implementations, or is it just a hash of the reference solution?
Thanks. :-)
Thanks for the feedback, Alex.
(1) The zero angle in the HSV space is given by the color red. So it is positioned on the vertical axis at the figure's center, and the angle increases counter-clockwise.
(2) You are right to assume that beta is the euclidean norm, I've checked your solutions for V, and they are correct (as well as S, of course). The problem seems to be with your angle (H). I am not sure you can determine the right angle by using just asin. I believe you need to use atan, or both asin and acos to find the right angle quadrant.
(3) You are right. I've forgotten to take into account the noise, sorry about that. When I was designing this problem, I was thinking about using uint8 to remove noise, but in the end, I didn't. So I will fix the test suite to consider only 4 decimal places or use uint8 and update the problem description when I'm finished.
Hi, I have been trying the solution for a while. Will the solution be incorrect if I used 'hsv2rgb' function of matlab?
Hi, Ratul, yes, you can use hsv2rgb function, but there seems to be a problem with the test suite. Please, wait a while, I will fix everything and update the problem description today.
All problems are fixed now, sorry Ratul and Alex for any issues that you had. RGB values should be rounded to 4-decimal places. And remove NaNs from your results if present. Let me know if you still experience issues, or if you want a tip (I've fixed some of your codes, and they passed the test suite).
Example image is not correct, since hue equal 0 corresponds to primary red color. Please correct.
(https://en.wikipedia.org/wiki/Complex_plane states that real axis is pointing to the left, not to the bottom)
Also it would be great if you add additional checks in test cases, from which we can understand how our solution differs from yours.
For example: check correct value for some points of resulting image (like corners or real/imaginari axis points).
Svyatoslav Golousov, the real axis pointing left is only a convention. However, I will change the problem description later to explain it as I did on the next one. And I will think of a way to measure the similarity between images. I agree it's essential to provide better feedback; thanks for the suggestion.
Hi, Rafael.
I tried your problem and my solution only passed test suite #3.
I used complex number to represent the coordinates. From that, I computed abs() and angle().
I assumed that row m is corresponding to positive y-axis, and column n is positive x-axis.
For m or n is odd, the center is exactly the midpoint of the array 1:m or 1:n,
but for m or n is even, I put two elements for each for the origin.
Therefore, we have 2x2 array for the origin when m and n is even
or 2x1 if m is even and n is odd, or 1x2 m is odd or n is even.
Before that I also tried with simple origin by taking the floor(([m, n]+1)/2).
Unfortunately, those two approaches didn't give the same results as yours.
I plot the `cp` array (m x n x 3) using `image` and the plot is same as your
image.
I also flip the each HSV array, because Matlab use the convention for angle
start from -pi to pi (in this problem it points to negative y axis).
Thank you.