Php 高级MySQL区域成本
我对MySQL有点熟悉,但是想到实现这个功能,我的大脑会很受伤。我需要一个系统,你可以设置一个区域的“成本”,比如坐标X=20y=20width=20height=20,成本为每像素15,现在如果你在这个区域内放置另一个区域,比如X=25,Y=25,WIDTH=10,HEIGHT=10,成本为每像素5,之前的区域被分解成4个部分,中间部分被擦除,以利于这个区域Php 高级MySQL区域成本,php,mysql,Php,Mysql,我对MySQL有点熟悉,但是想到实现这个功能,我的大脑会很受伤。我需要一个系统,你可以设置一个区域的“成本”,比如坐标X=20y=20width=20height=20,成本为每像素15,现在如果你在这个区域内放置另一个区域,比如X=25,Y=25,WIDTH=10,HEIGHT=10,成本为每像素5,之前的区域被分解成4个部分,中间部分被擦除,以利于这个区域 我还希望能够计算特定像素之间区域的“成本”。希望我已经以你们大多数人都能理解的方式解释了这一点。我不知道从哪里开始。我会先存储所有具有优
我还希望能够计算特定像素之间区域的“成本”。希望我已经以你们大多数人都能理解的方式解释了这一点。我不知道从哪里开始。我会先存储所有具有优先级的区域,然后逐像素计算成本 因此,单个像素的成本为:
select c.*
from costs c
where PIXELX between c.x and c.x + c.deltax and PIXELY between c.y + c.deltay
order by priority desc
limit 1
要将其扩展到一个像素区域,可以将该区域扩展为一组像素。我建议使用numbers
表来帮助您:
select x.num as x, y.num as y
from numbers x cross join
numbers y
where x.num between PIXELX and PIXELX and DELTAX and
y.num between PIXELY and PIXELY and DELTAY
现在,结合这些想法,获得给定像素的所有可能成本:
select x.num as x, y.num as y, max(priority) as maxpriority
from numbers x cross join
numbers y join
costs c
on x.num between c.x and c.x + c.deltax and y.num between c.y + c.deltay
where x.value between PIXELX and PIXELX and DELTAX and
y.value between PIXELY and PIXELY and DELTAY
group by x.num, y.num
最后,加入给定优先级的成本:
select sum(c.cost)
from (select x.num as x, y.num as y, max(priority) as maxpriority
from numbers x cross join
numbers y join
costs c
on x.num between c.x and c.x + c.deltax and y.num between c.y + c.deltay
where x.value between PIXELX and PIXELX and DELTAX and
y.value between PIXELY and PIXELY and DELTAY
group by x.num, y.num
) xyp join
costs c
on xyp.x between c.x and c.x + c.deltax and xyp.y between c.y + c.deltay and
xyp.maxpriority = c.priority
我将通过优先存储所有区域,然后逐像素获取成本来实现这一点 因此,单个像素的成本为:
select c.*
from costs c
where PIXELX between c.x and c.x + c.deltax and PIXELY between c.y + c.deltay
order by priority desc
limit 1
要将其扩展到一个像素区域,可以将该区域扩展为一组像素。我建议使用numbers
表来帮助您:
select x.num as x, y.num as y
from numbers x cross join
numbers y
where x.num between PIXELX and PIXELX and DELTAX and
y.num between PIXELY and PIXELY and DELTAY
现在,结合这些想法,获得给定像素的所有可能成本:
select x.num as x, y.num as y, max(priority) as maxpriority
from numbers x cross join
numbers y join
costs c
on x.num between c.x and c.x + c.deltax and y.num between c.y + c.deltay
where x.value between PIXELX and PIXELX and DELTAX and
y.value between PIXELY and PIXELY and DELTAY
group by x.num, y.num
最后,加入给定优先级的成本:
select sum(c.cost)
from (select x.num as x, y.num as y, max(priority) as maxpriority
from numbers x cross join
numbers y join
costs c
on x.num between c.x and c.x + c.deltax and y.num between c.y + c.deltay
where x.value between PIXELX and PIXELX and DELTAX and
y.value between PIXELY and PIXELY and DELTAY
group by x.num, y.num
) xyp join
costs c
on xyp.x between c.x and c.x + c.deltax and xyp.y between c.y + c.deltay and
xyp.maxpriority = c.priority
一想到要实现这个功能,我的大脑就痛了
是的,我也是!六羟甲基三聚氰胺六甲醚。。。不过,这听起来确实很熟悉——因为以前在网上就已经做过了
也许你可以改为使用或改编一个预先制作的解决方案,比如谷歌的“像素广告脚本”
一想到要实现这个功能,我的大脑就痛了
是的,我也是!六羟甲基三聚氰胺六甲醚。。。不过,这听起来确实很熟悉——因为以前在网上就已经做过了
也许你可以改为使用或改编一个预先制作的解决方案,比如谷歌的“像素广告脚本”。为什么之前的区域被分成4个部分?与其说是编程问题,不如说是数学问题+1。我碰巧认为这是一个非常有趣的数据库问题。如果您要添加一个可能的数据库模式,这可能会向人们显示您所追求的目标。我已经尝试了解该模式很长一段时间了:(为什么前一个领域被分为4个部分?与其说是编程问题,不如说是数学问题+1…我碰巧认为这是一个非常有趣的数据库问题。+1给你一些视图。如果你想添加一个可能的数据库模式,这可能会向人们展示你的目标。我已经尝试弄清楚该模式有相当一段时间了:(这是真实的生活。那是两张分开的桌子,对吗?它们的结构看起来怎么样?有人吗?这看起来像是中国的。这是真实的生活。那是两张分开的桌子,对吗?有人吗?这看起来像中国的。这和我要找的完全不同。那和我要找的完全不同。