How can I estimate the clarity of a color? [closed] - algorithm

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 days ago.
Improve this question
This question might sound a little bit broad, but how can I estimate the clarity of a rgb color?
I'm trying to create a function f(rgb) that returns 0 if the rgb is black (0,0,0), 1 if it is white (1,1,1) and something in between for other rgb colors.
What I'm trying is this:
f(rgb) = min(rgb) + c1r + c2g + c3b
First I take the minimum value of the rgb channels, then I add it with the products between each channel and a predefined constant.
Example: rgb = (0.4, 0.8, 0.5)
f(rgb) = min(0.4, 0.8, 0.5) + 0.4 c1 + 0.8 c2 + 0.5 c3
f(rgb) = 0.4 + 0.4 c1 + 0.8 c2 + 0.5 c3
But obviously I don't know the values of the constants, I would have to test them manually.
This is why I'm asking if there is a way already.

Got an idea: convert the color to grayscale.
Here I could find an algorithm that does that:
f(rgb) = 0.299r + 0.587g + 0.114b

Related

How D3.JS positions the <g>? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I am really new to D3 and i m trying to understand how the the <g> are positioned in the svg.
Take the following example:
https://stackblitz.com/edit/angular-packed-bubble-chart?file=src%2Fapp%2Fd3-packed-bubble-chart.service.ts
How would be possible to approach the 2 clusters?
The g elements are positioned in lines 73-75 by setting the g elements' transform attribute to "translate(" + d.x + "," + d.y + ")" via the the accessor function.
Essentially, applying a translate(x,y) value to a transform attribute on an element, means shifting the element x pixels horizontally and y pixels vertically.
Check out the documentation for the transform attribute and what it does with a translate value.
The values of d.x and d.y are computed using D3's pack and hierarchy functions.
Hope this helps!

When velocity becomes 0 and how to recalculate acceleration for final position can be whole number by rounding off? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
Position P is start with 7.56m and velocity V is 6(m/s). Acceleration A is -2 (m/s): How to get P when V becomes 0 and how to recalculate acceleration A for final P can be whole number by rounding off?
use equations of motion.
v2 = u2 + 2as
here,
v=0, u=6m/s and a=-2m/s2
So,
s = 9m
So, final position will be 7.56 + 9 = 16.56m
and since acceleration does not change, final acceleration = initial acceleration = -2m/s2
EDIT:
In that case, again use the same equation. Changed values will be:
v=0, u=6, s=9.44
So,
a = -1.907m/s2

how to calculate shortest distance between two moving objects [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
the question is simple one object is moving from east-west with a velocity of v1 and another from south-north with velocity v2.
I just need the algorithm(formula) to calculate the shortest distance between them so I can write a program for it.
I do have distance between them and the meting point of their paths they are d1 and d2.
Assuming you are asking for 2-d space, at t=0, let the starting points be (d1,0) and (0,d2) on the coordinate axes. We can assume this because one object is always moving horizontally (E-W direction, along X-axis) and other vertically (S-N direction, along Y-axis). Now, after some time t, their positions will be,(d1-t*v1) and (0,d2-t*v2). (Speed-Distance-Time relation).
Now, distance between them at this time t will be,
D = d^2 = (d1-t*v1)^2 + (d2-t*v2)^2
So, differentiating both sides wrt t,
dD/dt = 2(-v1)(d1-t*v1) + 2(-v2)(d2-t*v2) ....(1)
For D to be minimum, dD/dt = 0 and second differential must be positive. Now, second differential :
d2D/dt2 = 2*v1^2 + 2*v2^2 which is positive for all real v1/v2. So, if `dD/dt = 0`, distance will be minimum.
So, equating (1) = 0, we get
t = (d1v1 + d2v2)/(v1^2 + v2^2)
So, get sqrt(D) at t = --above value-- and that shall be your answer.
PS: ask these type of questions on mathematics stackexchange.

Cocos2d Sprite Movement Speed [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a class which creates a sprite at a random point on the screen, this sprite then moves to the center of the screen.
How can I make it so that it always travels at the same speed?
obviously
CCMoveTo* move = [CCMoveTo actionWithDuration:5 position: ccp(screenWidth/2, screenHeight/2)];
Will always mean the duration is 5 seconds regardless of the distance. But I want the speed to be constant if its travelling 50 pixels or 500 pixels.
Any Help much appreciated
Calculate the duration from the distance to the center.
duration = distance / rate;
Say that moving 50 pixels in 5 seconds is okay. Then your rate is 10 pixels/second.
rate = 10;
If your sprite is at (x,y) then distance is by the pythagorean theorem
dx = x - screenWidth / 2;
dy = y - screenHeight / 2;
distance = sqrt(dx * dx + dy * dy);

Algorithmical issue with point inside circle [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I have a question [ silly - I admit ] about finding wherether the point is in the circle or not, I have a coordinates of the center of circle, and I know the equation, but I'm having the problem with radius, let say it is 2 km, so I have x:46.123654 y: 15.789456 and r=2 or 200 or 2000? What should be the value of R?
For clarity, the units of r should almost certainly be the same as the units of x and y. If, for instance x = 46.123654 means 46.123654 meters, and the radius of your circle is two kilometers, then the value of r should be 2000.0, meaning two thousand meters. You should also be explicit in some comment about what the units are, i.e. x = 46.123654 //meters. If the units are the same, you can apply formulas without confusing conversions, for instance:
//determines whether a point (x, y) is in the circle of radius r centered at (0, 0)
bool isInCircle(double x, double y, double r)
{
return x * x + y * y <= r * r; //pythagorian theorem!
}
This isn't really programming, just middle-school math and common sense.

Resources