quad

HT for Web可视化QuadTree四叉树碰撞检测

我怕爱的太早我们不能终老 提交于 2020-11-21 04:10:10
QuadTree 四叉树顾名思义就是树状的数据结构,其每个节点有四个孩子节点,可将二维平面递归分割子区域。QuadTree常用于空间数据库索引,3D的椎体可见区域裁剪,甚至图片分析处理,我们今天介绍的是QuadTree最常被游戏领域使用到的碰撞检测。采用QuadTree算法将大大减少需要测试碰撞的次数,从而提高游戏刷新性能,本文例子基于 HT for Web 的图形引擎,通过 GraphView 和 Graph3dView 共享同一数据模型 DataModel ,同时呈现QuadTree算法下的2D和3D碰撞视图效果: http://v.youku.com/v_show/id_XODQyNTA1NjY0.html QuadTree的实现有很多成熟的版本,我选择的是 https://github.com/timohausmann/quadtree-js/ 四叉树的算法很简单,因此这个开源库也就两百来行代码。使用也非常简单,构建一个Quadtree对象,第一个参数传入rect信息制定游戏空间范围,在每次requestAnimationFrame刷新帧时,先通过quadtree.clear()清除老数据,通过quadtree.insert(rect)插入新的节点矩形区域,这样quadtree就初始化好了,剩下就是根据需要调用quadtree.retrieve(rect)获取指定矩形区域下

How to propagate error when using scipy quad on a spline of data with measurement error?

你说的曾经没有我的故事 提交于 2020-06-17 09:51:31
问题 I have a data set with N points which I fit a spline to and integrate using scipy.integrate.quad. I would like to use the N associated measurement errors to put an error estimate on the final integral value. I originally tried to use the uncertainties package but the x+/-stddev objects did not work with scipy. def integrand(w_point, x, y): #call spline function to get data arbitrary points f_i = spline_flux_full(x, y, w_point) #use spline for normalizing data at arbitrary points f_i_continuum

Problems integrating using quadpy

冷暖自知 提交于 2020-05-09 15:54:35
问题 I am trying to use quadpy as I want to do 2D numerical vector integration for 2D integrals. To see how fast quadpy works, I wanted to test it and compare it with scipy 1D vector integration. Thus I wrote a simple code: import numpy as np from scipy import integrate from scipy.special import erf from scipy.special import j0 import quadpy q = np.linspace(0.03, 1.0, 500) def f(t): return t * 0.5 * (erf((t - 40) / 3) - 1) * j0(q * t) y, _ = integrate.quad_vec(f, 0, 50) y1, _ = quadpy.quad(f, 0,

How do I use parameter epsabs in scipy.integrate.quad in Python?

青春壹個敷衍的年華 提交于 2020-01-15 09:46:47
问题 I am trying to make my integral more precise by specifying the parameter epsabs for scipy.integrate.quad , here say we will be integrating the function sin(x) / x^2 from 1e-16 to 1.0 from scipy.integrate import quad import numpy integrand = lambda x: numpy.sin(x) / x ** 2 integral = quad(integrand, 1e-16, 1.0) This gives you (36.760078801255595, 0.01091187908038005) However, if you specify the absolute error tolerance with epsabs with the following from scipy.integrate import quad import

scipy quad uses only 1 subdivision and gives wrong result

萝らか妹 提交于 2019-12-31 03:39:06
问题 I want to use quad to get the mean of a Gaussian distribution. My first try and 2nd try gets different result. And the 2nd try of quad uses only 1 subdivision. mu =1 sigma =2 import scipy as sp import scipy.integrate as si import scipy.stats as ss f = lambda x: x * ss.norm(loc=mu, scale=sigma).pdf(x) a = si.quad(f, -999., 1001., full_output=True) print a[0] #print sum(a[2]["rlist"][:a[2]["last"]]) print a[2]["last"] b = si.quad(f, -1001., 1001., full_output=True) print b[0] #print sum(b[2][

numerical integration python

爱⌒轻易说出口 提交于 2019-12-25 09:14:04
问题 I need to reduce the running time for quad() in python (I am integrating some thousands integrals). I found a similar question in here where they suggested to do several integrations and add the partial values. However that does not improve performance. Any thoughts? here is a simple example: import numpy as np from scipy.integrate import quad from scipy.stats import norm import time funcB = lambda x: norm.pdf(x,0,1) start = time.time() good_missclasified,_ = quad(funcB, 0,3.3333) stop = time

scipy integrate.quad return an incorrect value

那年仲夏 提交于 2019-12-25 00:25:18
问题 i use scipy integrate.quad to calc cdf of normal distribution: def nor(delta, mu, x): return 1 / (math.sqrt(2 * math.pi) * delta) * np.exp(-np.square(x - mu) / (2 * np.square(delta))) delta = 0.1 mu = 0 t = np.arange(4.0, 10.0, 1) nor_int = lambda t: integrate.quad(lambda x: nor(delta, mu, x), -np.inf, t) nor_int_vec = np.vectorize(nor_int) s = nor_int_vec(t) for i in zip(s[0],s[1]): print i while it print as follows: (1.0000000000000002, 1.2506543424265854e-08) (1.9563704110140217e-11, 3

Nonlinear magnetic model fit -with a definite integral- using scipy.integrate.quad and lmfit

妖精的绣舞 提交于 2019-12-12 04:18:07
问题 I would like to fit an hysteresis curve, with a superparamagnetic behavior, using a magnetic model which includes a Langevin function and a pair distribution function [1]. To fit with this equation I must solve a definite integral. I was trying to use scipy.integrate.quad for this purpose and the features of lmfit, but I do not get -at least- to simulate a reasonable curve (see the code below). Some real physical parameters that can be used to simulate this equation are: Dm = 3.2E-9 m, w = 0

How to use `scipy.integrate.quad` to compute integral of a function which depends on the integral of another function

我与影子孤独终老i 提交于 2019-12-11 16:09:42
问题 Any help to compute this integration, F function is defined using the f function which involves the first integration, finally, integrate F . from scipy.integrate import quad f = lambda x,a : a**2*x def F(s,a): return quad(f,0,s,args=(a,)) quad(F,0,5,args=(4,)) Got the error: 2 def F(s,a): 3 return quad(f,0,s,args=(a,)) ----> 4 quad(F,0,5,args=(4,)) 5 446 if points is None: 447 if infbounds == 0: --> 448 return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit) 449 else: 450

Conversion of symbolic expression to numeric one for use in quad - use lambdify?

拟墨画扇 提交于 2019-12-11 15:29:45
问题 I want to convert an expression containing symbolic variables to a numeric one so that the expression may be subsequently used in an integration method 'quad'. import numpy import math as m import scipy import sympy #define constants gammaee = 5.55e-6 MJpsi = 3.096916 alphaem = 1/137 lambdasq = 0.09 Ca = 3 qOsq = 2 def qbarsq(qsq): return (qsq+MJpsi**2)/4 def xx(qbarsq, w): return 4*qbarsq/(4*qbarsq-MJpsi**2+w**2) from sympy import * x,NN,a,b,ktsq,qbarsq,w = symbols('x NN a b ktsq qbarsq w')