Cutting 2D shapes from 2D shapes and storing the remainder - php

I have a 10 by 10 sheet of paper. If I remove a 8 by 6, I want to be able to store the remainder as two shapes (that is 2 by 10 and 10 by 4) into a database. Now, if I need to use a 10 by 4, I should be able to cut it from the 10 by 4 but then this should also update the dimensions of the 2 by 10.
Yellow is the initially removed 86, blue and red is the 210, green and red is the 4*10
I tried storing them separately but I do not know when/how to ascertain when the dimension of the new required piece are now interfering with both the shapes

Related

Mysql return only items that have n number of property matches

I have a database of items and each item has various number of properties. Is it possible for MySql only to return items that have a certain number of matches (not properties) when a search is run?
Example: I am searching for any item with a wheel that is red and has a tire.
This would return all items with these three matches even if they have more properties and would automatically exclude anything that has less than 3 matches.
I have tried playing with the COUNT + GROUP BY + HAVING but I was unable to put together a meaningful working code. Before I spend more time on this I would like to know if it is possible at all.
TABLE DESIGN
ID ITEM PROPERTY
1 1 red
2 1 wheel
3 1 tire
4 2 red
5 2 wheel
6 2 tire
7 2 lamp
8 3 red
9 3 wheel
10 4 red
I would like it to return ITEM 1 and 2
You would do this with a group by and having. You really provide no information about your data structure, but the basic idea is:
select ip.item
from design ip
where ip.property in ('wheel', 'red', 'tire')
group by ip.item
having count(distinct ip.property) = 3;

MORRIS LINE GRAPH IN PHP LARAVEL

putting multiple lines in graph.
in my project- xaxis- SP values- S
yaxis -CMH values
Each record in tables
for each angle i have SP1 to SP10 and CMH1 to CMH10
For example:
angle 25 degree plot 10 point and form line- 10 point is(sp1,CMH1)(SP2,CMH2).... (SP10,CMH10)
26 degree again another 10 points as above line..
my dataset passing to line graph
"result":[
{"BLADE_ANGLE_ID":1,"SP1":10,"SP2":5,"SP3":6,"SP4":6,"SP5":2,"SP6":2,"SP7":1,"SP8":2,"SP9":3,"SP10":2,"CMH1":12,"CMH2":null,"CMH3":null,"CMH4":null,"CMH5":null,"CMH6":null,"CMH7":null,"CMH8":null,"CMH9":null,"CMH10":null,"CHECKED":1},
{"BLADE_ANGLE_ID":2,"SP1":6,"SP2":7,"SP3":7,"SP4":23,"SP5":32,"SP6":4,"SP7":7,"SP8":9,"SP9":55,"SP10":45,"CMH1":10,"CMH2":null,"CMH3":null,"CMH4":null,"CMH5":null,"CMH6":null,"CMH7":null,"CMH8":null,"CMH9":null,"CMH10":null,"CHECKED":1
}]
Here you can see 2 blade angles and here u have to draw 2 lines with each 10 points(sp,CMH) for 2 different angles

php percentage chance for event to occur

I know it is a noob question but i am quite stuck with it so i hope you can help me.
I have an array with integers. Depending on circumstances i can have an array with 1,2,3 or 1,1,1 or 1,2,2 and so on. The important thing is that difference between values in array may be no bigger than smallest number + 2 (i can have there 1, 2, 3 but no 1, 2, 4). Now i grab max and min of array and decrement min from max. Because always the difference between max and min is 0, 1 or 2 (array values are no bigger from eachother than two) i have free possible chances:
0: - all array values are equal
1: - all array values are from range <x, x + 1>
2: - all array values are from range <x-1, x+1>
Now if i want to randomly choose values from above arrays it's quite easy. But how can i do it with percentage chance of selecting number with bigger probability than the others?
What do i mean? Consider second example, and range of values in array x-1, x+1 - let it be Array(2, 3, 4). Now i would like to have 50% chance to select 4, 30% chance to select 3 and 20% to select 2. How can i connect value of integer in array with a chance of selecting it?
I hope you can understand what I mean and you can help me.
EDIT:
In other wordsif i have an array filled with values how to easily, having a range of values that is a part of all values in array select one value with more probability than the other?
I am not sure I totally understand the first part, but say you want to have a 50% chance of selecting 4, 30% chance of selecting 3 and 20% chance of selecting 2.
You just populate an integer array of length 10 with 5 4s, 3 3s and 2 2s:
int[] a=[4,4,4,4,4,3,3,3,2,2];
Now randomly choose an index between 0 and 9 with equal probability and return the number in the array at that index. This will return 4 with 50%, 3 with 30% and 2 with 20%.
$rand = rand(1, 100);
if ($rand > 50) {
//select first array
} else {
//select the second array and so on.
}
Will the above code help?

Generating 3 Random Numbers Within a Range and sum 3 numbers = this range [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to make 5 random numbers with sum of 100
i am new with php . Can i ask how to make 3 random number with range an sum of 3 numbers = max value of this range.
Example : i have range 0->900; 3 random number is 213 437 250
Pick two random numbers between 0 and 900 inclusive. Add 0 and 900 to the list. Sort them. Your numbers are the 3 differences between successive numbers.
For example, say you pick 503 and 117. Your sorted list is 0, 117, 503, 900. So your differences are:
117 - 0 = 117
503 - 117 = 386
900 - 503 = 397
So your three numbers are 117, 386, and 397.
Since you only need three numbers, you can simplify the process: Generate two random numbers between 0 and 900 (inclusive). Call the larger A and the smaller B. Your numbers are B, A - B and 900 - A.
See here.

Convert rating percent (50%) to the equivelant 5-star rating in PHP

I'm sure this is possible but my math isn't that fantastic.
I'm showing latest movies on my page and my application uses a 5-star rating system, however, the data I receive from a Web Service arrives as a percentage e.g. 50%.
Is there any way I can convert this percentage to a star rating equivalent, which in this case would be 50% = 2.5, allowing me to show 2.5 stars?
It seems fairly simple when I have 50% but if I get 94%, it confuses my poor little pea for a brain! Please help.
If you want to convert the 0..100 scale to a 0..5 scale, just divide by 20.
If you want it on a half-star boundary, then divide it by 10 instead and that's the number of half-stars you need.
Keep in mind I'm talking about integer division here, where the value is truncated (rounded down).
You may also want to consider rounding it more intelligently during the division, rather than truncating, so that something like 99% is 5 stars (not 4.5). This can be done by simply adding half the amount you're dividing by before the division, something like (in C):
int percent = 94;
int halfstars = (percent + 5) / 10;
This would give the following results for input values between 0 and 100 inclusive:
percent halfstars
------- ---------
0- 4 0
5- 14 1
15- 24 2
25- 34 3
35- 44 4
45- 54 5
55- 64 6
65- 74 7
75- 84 8
85- 94 9
95-100 10
The formula for finding the percentage of a number is fairly simple:
$percentInDecimalForm * $number
For example, a 94% rating would be:
.94 * 5 = 4.7
You just need to solve the following:
100% ---------- 5
94% ---------- x = (94 * 5) / 100 (=) x = 4.7
Now it's necessary to know the granularity of your star scale (how many times you can divide the star).
Since you mentioned 0.5 stars, I'm gonna assume your star granularity is 1 / 0.5 = 2, so just solve:
round(4.7 * 2) / 2 (=) 9 / 2 (=) 4.5

Categories