How to find a list of colors that have the largest number of nested shapes? Using aggregate library tools.
I will be grateful for your help!
figure(square1, red).
figure(circle, red).
figure(triangle, blue).
figure(rectangle, green).
figure(diamond, purple).
figure(square2, green).
figure(trapezium1, black).
figure(hexagon, grow).
figure(trapezium2, yellow).
contains(square1, rectangle).
contains(circle, diamond).
contains(square1, hexagon).
contains(trapezium2, square2).
contains(trapezium1, triangle).
contains(triangle, square2).
extract (X, L) :- retract(figure(X-L)), !.
extract (_, []).
colorList(_) :- figure(X, Y), extract(X, L),
assertz(name(X-[Y|L])), fail.
colorList(List) :-extractFigures(List).
Related
I would like to calculate the distance between two points of the object by clicks.
I use IFCviewerAPI.
This solution is for Three.js in general, so it'll work in any Three.js app, including web-ifc-three and web-ifc-viewer (like in your case).
first of all, you shall find the position of both points in the 3D space (x, y, z),
let's assume there's two pointA and pointB each has (x, y, z) values
Math.pow(Math.pow( (pointB.x - pointA.x), 2) + Math.pow( (pointB.y - pointA.y),2) + Math.pow( (pointB.z - pointA.z),2), 0.5)
While this solution is super basic, you need to know that you might find issues in performance while scaling this code to multiple points.
I'm new to writing Prolog and would like to know how to state the following properties in a way that's useful for later reasoning.
There are N objects.
Every object has a color.
There are three possible colors: red, green, blue
Let's assume there are two objects: object 1 is red, object 2 has a different, unspecified color. How can I ask Prolog for possible colors of object 2? I'd expect green and blue.
My code so far:
object(obj_1).
object(obj_2).
color_value(red).
color_value(green).
color_value(blue).
color(Obj, Val) :- object(Obj), color_value(Val).
color(obj_1, red).
different_color(O1, O2) :- color(O1, X), color(O2, Y), X \= Y.
different_color(obj_1, obj_2).
When I query for possible colors of obj_2, Prolog includes red. So I'm doing it wrong somehow.
color(obj_2, A).
A = red ;
A = green ;
A = blue.
I suspect there's something wrong with how I use color and different_color.
Your definition of color/1 offers redundant solutions for color(_, red) or color(obj_1, _). Your clause for color(Obj, Val) needs to exclude the case where Obj is obj_1 or Val is red.
A simplistic approach could be:
color(Obj, Val) :-
dif(Obj, obj_1),
dif(Val, red),
object(Obj),
color_value(Val).
color(obj_1, red).
Also, consider #DavidTonhofer's comment about style. :)
I realise I've written this like a homework question, but that's because it's the simplest way for me to understand and try to relay the problem. It's something I want to solve for a personal project.
I have cards laid out in a grid, I am starting with a simple case of a 2x2 grid but want to be able to extrapolate to larger n×n grids eventually.
The cards are all face down, and printed on the faces of the cards are either a:
positive non-zero integer, representing the card's 'score'
or the black spot.
I am given the information of the sum of the scores of each row, the number of black spots in each row, and the sum of the scores of each column, and the number of black spots in each column.
So the top row must have a sum score of 1, and exactly one of the cards is a black spot.
The rightmost column must have a sum score of 2, and exactly one of the cards is a black spot.
Etc.
Of course we can see the above grid will "solve" to
Now I want to make a function that inputs the given information and produces the grid of cards that satisfies those constraints.
I am thinking I can use tuple-like arguments to the function.
And then every "cell" or card in the grid is itself a tuple, the first element of the tuple will be the score of the card there (or 0 if it is a black spot) and the second element will be a 1 if the card is a black spot or a 0 otherwise.
So the grid will have to resemble that ^^
I can find out what all the a, b, variables are by solving this system of equations:
(Knowing also that all of these numbers are integers which are ≥0).
I wanted to use this problem as a learning exercise in prolog, I think it seems like a problem Prolog will solve elegantly.
Have I made a good decision or is Prolog not a good choice?
I wonder how I can implement this in Prolog.
Prolog is very good for this kind of problems. Have a look clp(fd), that is Constraint Logic Programming in Finite Domains.
This snippet shows a primitive way how to solve your initial 2x2 example in SWI Prolog:
:- use_module(library(clpfd)).
test(Vars) :-
Vars = [TopLeft, TopRight, BottomLeft, BottomRight],
global_cardinality([TopLeft, TopRight], [0-1,1-_,2-_]), TopLeft + TopRight #= 1,
global_cardinality([TopLeft, BottomLeft], [0-1,1-_,2-_]), TopLeft + BottomLeft #= 1,
global_cardinality([BottomLeft, BottomRight], [0-1,1-_,2-_]), BottomLeft + BottomRight #= 2,
global_cardinality([TopRight, BottomRight], [0-1,1-_,2-_]), TopRight + BottomRight #= 2,
label(Vars).
Query:
?- test(Vars).
Vars = [1, 0, 0, 2].
You can take this as a starting point and generalize. Note that the black dot is represented as 0, because clp(fd) deals only with integers.
Here is the documentation: http://www.swi-prolog.org/man/clpfd.html
I've recently been looking into color spaces and color models. I've become interested in the relationships and conversions between different spaces, and I came across CIEXYZ and CIELUV.
In the conversion algorithm, the CIELUV article mentions the variables u', v', u'ₙ, v'ₙ, and Yₙ. I understand that these are related to the white point (of which a table of common values can be found here,) but I'm not exactly sure what the relationship is.
In the article, it says:
For example, for the 2° observer and standard illuminant C, u'ₙ = 0.2009, v'ₙ = 0.4610
(The values for the 2° observer and standard illuminant C can be found in the table mentioned above, and are given as x₂ = 0.31006 and y₂ = 0.31616.)
Below this, the equations for computing u' and v' are given:
u' = (4x)/(-2x + 12y + 3)
v' = (9y)/(-2x + 12y + 3)
If we plug in the x₂ and y₂ we've been given, we get the expected result of u' = 0.2009 and v' = 0.4610. However, earlier in the article, it said that u'ₙ and v'ₙ should be those respected values. Not u' and v'.
Also, the article makes no mention of Yₙ other than stating that it's the luminance of the (u', v') chromaticity coordinates, information on which I can't find.
So, my question is, what the heck are u', v', u'ₙ, v'ₙ, and Yₙ? Assuming that u' and v' are the target chromaticity and u'ₙ and v'ₙ are the source chromaticity (or vice-versa,) then the main conversion algorithm would make no sense if the target and source are the same, as the resulting u* and v* would equal 0. If someone could shed a little light on this for me, it'd be greatly appreciated. Thanks.
You calculated the u', v' of white point, which are per definition u'ₙ, v'ₙ. These are constant. Computer screen (sRGB), HDTV (Rec.709), movie theater, etc. have own specific white point. You should decide it, and keep constant for the transformation.
Yₙ is the luminance of the white point. This depend on the setting of the television. More power, more luminous will be the white point. Probably you should set it as 1.0 (or 100, or the maximum digital value). You see that L*, u*, and v* are inversely proportional to Yₙ. This is just used to norm L to 100 (in the case of Wikipedia transformation). So you should just it as the maximum Y, or the luminance Y of white (if you have superwhite, like in HDTV).
CIEXYZ (you initial space, and most common "common" space to be used between transformation) have just defines X, Y, Z (or x, y, z or also more frequently x, y, Y). These values represent eye sensitivity (really a linear transformation, just to have positive values, they discovered exact coordinates later (LMS colour space), so that are independent to white space (so you have no parameter for white), but this means also that well defined chromacity (x, y) can be seen as different colour, according the actual colour adaptation.
I short (inverse order from Wikipedia).
you have x, y, Y of a point, according CIEXYZ (linear space). x, and y are the chromacities. Y is the luminance.
you transform to u', v' (for now just chromacities, also just in function to x, y).
and last step is the gamma correction, so you transform from linear space into a perceived function, so you get L*, u*, v*.
Wikipedia is mixing colour model (e.g. RGB, and the generic transformation to/from RGB) with colour space (sRGB [the normal "web colour" space], which is a RGB model with well defined chromacities for Red, Green, Blue and White, and a well defined gamma function). You should treat variables with N subscript as pre-defined constant, for your specific Luv colour space.
I have a scatter plot on the left-hand side below, where there are lots of data points, and the figure on the right are corresponding density plot using seaborn.kdeplot(). But unfortunately since the variance of the density is so large that kdeplot fails to capture many details in other low-density area (e.g. there is basically no information about the density distribution on the top right).
Does anyone have any ways to fix this issue?
Thanks!
You can use the n_levels parameter, i.e.
f, axes = plt.subplots(1, 3, figsize=(15, 5), sharex=True, sharey=True)
x, y = np.random.normal(0, 1, (2, 1000))
axes[0].scatter(x, y, s=5, c=".1")
sns.kdeplot(x, y, n_levels=10, ax=axes[1])
sns.kdeplot(x, y, n_levels=30, ax=axes[2])
f.tight_layout()