我目前正在开发一个使用SDK> = 16的Android应用程序,它应该能够使用WiFi无线电在局域网中发现不同的Android设备(后来也是iOS设备).
我的第一个猜测是使用在我的三星Galaxy S2上无效的多播:仅在从同一设备发送时才接收数据包.
我的第二个猜测是使用有限的IP地址范围主动扫描网络并等待适当的响应.不幸的是,这意味着网络使用DHCP来寻址IP地址.
上述解决方案似乎都不是完美的解决方案.
我目前解决的第一个猜测是:
public class MulticastReceiver extends AsyncTask<Activity, Integer, String> {
private static final String host = "224.1.1.1";
private static final int port = 5007;
private static final String TAG = "MulticastReceiver";
protected String doInBackground(Activity... activities) {
WifiManager wm = (WifiManager)activities[0].getSystemService(Context.WIFI_SERVICE);
WifiManager.MulticastLock multicastLock = wm.createMulticastLock("mydebuginfo");
multicastLock.acquire();
String message = "Nothing";
if (multicastLock.isHeld()) {
Log.i(TAG, "held multicast lock");
}
try {
InetAddress addr = InetAddress.getByName(host);
MulticastSocket socket = new MulticastSocket(port);
socket.setTimeToLive(4);
socket.setReuseAddress(true);
socket.joinGroup(addr);
byte[] buf = …Run Code Online (Sandbox Code Playgroud) 我希望能够使用numpys trapz函数计算跟随积分
numpy.trapz([-1, 1]) # returns 0
Run Code Online (Sandbox Code Playgroud)
但我不想允许负面区域.有没有一种有效的方法来做到这一点,还是我必须寻找最小点并手动转换数组?
是否numpy.trapz(numpy.abs([-1, 1]))有意义?
我正在努力解决一个简单的问题.我有一个numpy数组的形式:
[[[ 1152.07507324 430.84799194]
[ 4107.82910156 413.95199585]
[ 4127.64941406 2872.32006836]
[ 1191.71643066 2906.11206055]]]
Run Code Online (Sandbox Code Playgroud)
我想计算边界框,意思是,我想要最左边,最顶部,最右边和最底部的点.
这应该是一个正确的解决方案
[[[ 1152.07507324 413.95199585]
[ 4127.64941406 413.95199585]
[ 4127.64941406 2906.11206055]
[ 1152.07507324 2906.11206055]]]
Run Code Online (Sandbox Code Playgroud)
我开发了一个令人讨厌的功能,但是我对它非常不满意,因为它不是真正的pythonic/numpyic
def bounding_box(iterable):
minimum_x = min(iterable[0], key=lambda x:x[0])[0]
maximum_x = max(iterable[0], key=lambda x:x[0])[0]
minimum_y = min(iterable[0], key=lambda x:x[1])[1]
maximum_y = max(iterable[0], key=lambda x:x[1])[1]
return numpy.array([[(minimum_x, minimum_y), (maximum_x, minimum_y), (maximum_x, maximum_y), (minimum_x, maximum_y)]], dtype=numpy.float32)
Run Code Online (Sandbox Code Playgroud)
你有任何想法如何优化上面的功能,也许使用numpy内置?
我想围绕一个兴趣点旋转我的"相机".目前,相机仅围绕原点旋转.
许多教程建议使用以下方案:
translate(-P)
rotate
translate(P)
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不起作用.我的应用程序使用平移向量(QVector3D)以及四元数(QQuaternion)来保存相机的平移和旋转.
目前,它是这样做的,它始终围绕原点旋转:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(translation.x(),translation.y(), translation.z());
multMatrix(accumulatedQuaternionRotation);
Run Code Online (Sandbox Code Playgroud)
其中mulMatrix使用Quaternion构建一个传递给glMultMatrixf()的4x4矩阵;
使用这样的东西:
glTranslatef(-translation.x(),-translation.y(), -translation.z());
multMatrix(accumulatedQuaternionRotation);
glTranslatef(translation.x(),translation.y(), translation.z());
Run Code Online (Sandbox Code Playgroud)
导致非常奇怪的控制,我无法进一步描述.在我的应用程序中translation.z()表示:向前移动相机.更改x()和y()会发出类似操作的泛操作.
我怀疑我正在使用翻译向量错误,导致上述操作序列失败.
有什么我可以检查的吗?
编辑:这是四元数旋转的工作方式:
// calculate rotation axis
QVector3D rotationAxis = QVector3D(diff.y(), diff.x(), 0.0).normalized();
// update rotation see http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation
accumulatedQuaternionRotation = QQuaternion::fromAxisAndAngle(rotationAxis, diff.length()/4.0f) * accumulatedQuaternionRotation;
Run Code Online (Sandbox Code Playgroud)
diff只是两个鼠标移动事件点的差异.
我试图在C++中覆盖这样的基类
class A:
QWidget *getWidget();
class B: public A:
using A::getWidget;
QWidget *getWidget();
Run Code Online (Sandbox Code Playgroud)
当我尝试使用它时:
A *test = new B();
test->getWidget();
Run Code Online (Sandbox Code Playgroud)
这里,返回A类的小部件.有没有办法获得小部件B?因为我不想从检查我的类开始并向下转到B来获取正确的小部件,所以我希望能够使用它类似于上面的代码片段.有什么建议?
numpy ×2
python ×2
3d ×1
android ×1
arrays ×1
c++ ×1
discovery ×1
inheritance ×1
networking ×1
opengl ×1
polymorphism ×1
rotation ×1