作为学校项目的一部分,我需要从表单中替换一个字符串:
5 * x^3 - 6 * x^1 + 1
Run Code Online (Sandbox Code Playgroud)
类似于:
5x<sup>3</sup> - 6x<sup>1</sup> + 1
Run Code Online (Sandbox Code Playgroud)
我相信这可以用正则表达式来完成,但我还不知道该怎么做.
你能借给我一个手吗?
PS实际的分配是实现一个多项式处理Java应用程序,我用它来将多项式.toString()从模型传递给视图,我希望以一种漂亮的方式使用html标签显示它.
我一直在我的Android代码中使用FloatBuffers一段时间(从一些opengles教程复制它),但我无法准确理解这个构造是什么以及为什么需要它.
例如,我在许多人的代码和android教程中看到的这段代码(或类似代码):
float[] vertices = ...some array...
ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length * 4);
vbb.order(ByteOrder.nativeOrder()); // use the device hardware's native byte order
FloatBuffer fb = vbb.asFloatBuffer(); // create a floating point buffer from the ByteBuffer
fb.put(vertices); // add the coordinates to the FloatBuffer
fb.position(0); // set the buffer to read the first coordinate
Run Code Online (Sandbox Code Playgroud)
这看起来非常冗长和混乱,据我所知,这只是一个漂浮的数组的花哨包装.
问题:
这种类(ByteBuffer,FloatBuffer)的理由是什么,而不是任何其他类型的集合或简单的浮点数组?
在将ByteBuffer转换为FloatBuffer之前创建ByteBuffer背后的想法是什么?
在帮助其他用户提出有关响应触摸事件 Android教程的问题之后,我下载了源代码,并且对我所看到的内容感到非常困惑.该教程似乎无法决定是否要使用行向量或列向量,它看起来都混淆了我.
在Android Matrix页面上,他们声称他们的约定是列向量/列主要,这是OpenGL的典型.
我是对的,还是我缺少的东西?以下是它的相关部分:
首先通过乘以mProjMatrix*mVMatrix创建MVPMatrix.到现在为止还挺好.
// Set the camera position (View matrix)
Matrix.setLookAtM(mVMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
// Calculate the projection and view transformation
Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0)
Run Code Online (Sandbox Code Playgroud)
接下来他们在MVPMatrix的左侧附加一个旋转?这看起来有点奇怪.
// Create a rotation for the triangle
Matrix.setRotateM(mRotationMatrix, 0, mAngle, 0, 0, -1.0f);
// Combine the rotation matrix with the projection and camera view
Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0)
Run Code Online (Sandbox Code Playgroud)
以非转置顺序上传.
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
Run Code Online (Sandbox Code Playgroud)
最后在他们的着色器中,向量*矩阵乘法?
// the matrix must …
Run Code Online (Sandbox Code Playgroud) 我想在屏幕中间显示三个按钮,并且三个按钮的宽度都相同,但它们将具有不同长度的文本标签.
只需添加三个不同长度的文本标签按钮,即可生成不同宽度的按钮.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center">
<Button
android:id="@+id/button_1"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:text="ABCDEF" />
<Button
android:id="@+id/button_2"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:text="GHI" />
<Button
android:id="@+id/button_3"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:text="JKLM" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
默认按钮宽度包装内容:
-
在所有按钮上将layout_weight设置为1并将layout_width设置为0dip会使它们均匀拉伸以填充整个屏幕宽度.对于我想要的东西,这样的按钮太大了,特别是在大屏幕上.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center">
<Button
android:id="@+id/button_1"
android:layout_height="fill_parent"
android:layout_width="0dip"
android:layout_weight="1"
android:text="ABCDEF" />
<Button
android:id="@+id/button_2"
android:layout_height="fill_parent"
android:layout_width="0dip"
android:layout_weight="1"
android:text="GHI" />
<Button
android:id="@+id/button_3"
android:layout_height="fill_parent"
android:layout_width="0dip"
android:layout_weight="1"
android:text="JKLM" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
布局重量1按钮填充屏幕宽度:
-
在父LinearLayout中为weightSum设置不同的值可以用来阻止按钮填满整个屏幕,但我不认为这是我想要的路径,因为我不希望按钮占据很大一部分在大屏幕设备上的屏幕.为了澄清,使用weightSum,我可以,例如,我可以设置三个按钮共同占据屏幕宽度的一半,这在小屏幕上看起来可以正常,但在大屏幕上,按钮仍然占据屏幕宽度的一半,并且按钮会比我想要的要大得多.也许最终的解决方案是为不同的屏幕设置不同的布局文件,但我宁愿不走这条路.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:weightSum="5"> …
Run Code Online (Sandbox Code Playgroud) 我无法理解这个移位运算符(c#reference):
class MainClass1
{
static void Main()
{
int i = 1;
long lg = 1;
Console.WriteLine("0x{0:x}", i << 1);
Console.WriteLine("0x{0:x}", i << 33);
Console.WriteLine("0x{0:x}", lg << 33);
}
}
/*
Output:
0x2
0x2
0x200000000
*/
class MainClass2
{
static void Main()
{
int a = 1000;
a <<= 4;
Console.WriteLine(a);
}
}
/*
Output:
16000
*/
Run Code Online (Sandbox Code Playgroud) 在OpenGL中,我可以通过正常绘制对象来绘制对象,然后使用模板缓冲区再次将其绘制为线框,这样就不会绘制原始对象.但是,这会产生一种纯色的轮廓.
在此图像中,生物轮廓的像素似乎比它们勾勒出的生物更加透明.如何使用OpenGL实现类似的效果?
我正在开发一款安卓游戏,我开始注意到在开发过程中有点迟钝,所以我想尝试利用多线程来获得乐趣和学习.
我的应用程序有3个主题:
我尽可能地最小化了线程2和3之间的关键部分,并且认为游戏逻辑可以独立于渲染线程进行更新,然后在两个线程的末尾我可以有一个尽可能短的窗口,我推动所有图形从逻辑线程更新到游戏循环.这应该允许两个线程在大多数情况下独立工作.理论上听起来像是表演胜利.
然而,一旦我开始实施,我的表现就大了不少.它比以前更糟糕,一个更新和渲染循环花了50毫秒(20fps),所以它看起来像垃圾.这只是渲染大约20个三角形和20个纹理四边形,这是一个非常简单的工作量(我不敢想到当我实现适当的图形时会是什么).
无论如何,我在android中使用DDMS跟踪来描述出现问题或者可以改进的地方.
http://i.stack.imgur.com/DDUYE.png
这是我游戏大约3帧的视图.到目前为止,它似乎大致按照我的预期行事.以蓝色突出显示的部分是锁定部分,它看起来是正确的(保持glThread在锁定时大多等待).然而,一旦我解锁它,我应该看到两个线程同时工作,看起来它们是,但如果我仔细观察:
http://i.stack.imgur.com/vukXQ.png
我正在双核手机上进行开发,但如果我理解了它的正确性,它看起来并不像是并行执行任何操作,而且更糟糕的是它似乎每毫秒切换活动线程数百次!(除非我不正确地解释这个).所有这些上下文切换似乎对性能都很糟糕,所以我不确定为什么它会如此快速地来回切换.
因此,在我冗长的解释之后,我想知道一些事情:
我正在尝试获取我的小部件的所有ACTIVE实例的列表.在我的AppWidgetProvider的OnUpdate方法中,我正在执行以下操作:
// Get all ids
ComponentName thisWidget = new ComponentName(context, this.getClass());
int[] lastWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
Run Code Online (Sandbox Code Playgroud)
问题是,如果您将小部件添加到主屏幕然后将其删除,getAppWidgetIds仍会返回一个列表,其中包含您刚刚删除的小部件的ID.
有没有办法只检索主屏幕上活动的小部件的ID?
如何在Java中逐行读取输入?我搜索过,到目前为止我有这个:
import java.util.Scanner;
public class MatrixReader {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while (input.hasNext()) {
System.out.print(input.nextLine());
}
}
Run Code Online (Sandbox Code Playgroud)
这个问题是它没有读取最后一行.所以,如果我输入
10 5 4 20
11 6 55 3
9 33 27 16
Run Code Online (Sandbox Code Playgroud)
它的输出只会是
10 5 4 20 11 6 55 3
Run Code Online (Sandbox Code Playgroud) 我们在课堂上学习B树,并被要求在代码中实现它们.老师已经选择了编程语言给我们,我想尝试用C#做.我的问题是以下结构在C#中是非法的,
unsafe struct BtreeNode
{
int key_num; // The number of keys in a node
int[] key; // Array of keys
bool leaf; // Is it a leaf node or not?
BtreeNode*[] c; // Pointers to next nodes
}
Run Code Online (Sandbox Code Playgroud)
具体来说,不允许创建指向结构本身的指针.我可以使用一些解决方法或替代方法吗?我很确定在托管代码中必须有一种方法可以做到这一点,但我无法弄明白.
编辑:埃里克的回答指出了我正确的方向.这是我最终使用的,
class BtreeNode
{
public List<BtreeNode> children; // The child nodes
public static int MinDeg; // The Minimum Degree of the tree
public bool IsLeaf { get; set; } // Is the current node a leaf or not?
public List<int> …
Run Code Online (Sandbox Code Playgroud)