GDI+ acceleration - gdi+

This might be a dumb question but when I use GDI+ is it automatically GPU hardware accelerated?
E.g. is this the case for the following code?
g = pbCanvas.CreateGraphics();
PointF P1 = ...
PointF P2 = ...
g.DrawLine(pen1, P1, P2);
Thanx for the help!

Related

How to do a discrete Fourier transform (FFT) and to plot the amplitude in Octave

I want to ask if this code is correct.
[y, Fs] = audioread('07000202112135-01.wav');
y = y(:, 1);
t = [0: length(y)-1] ./Fs;
Y=fft(y);
Ymodul = abs(Y);
plot(Ymodul)
07000202112135-01.wav is audio file
I hope someone will edit the code for me, thanks

whats the formula to point along line known starting point, ending point and distance

i have a question to find the x,y,z of point on the line. i have start and end posint of line. how to calculate any point on the line(between start and end points) by distance? an example image are bellow. Thanks.
Create a normal and multiply it. I'm pretty sure there are better ways to do that though. =)
Vec3 BA = B - A;
BA.normalize(); // you have the direction
Vec3 Dist = BA.mult(distance);
Vec3 Result = A + Dist;

Need an algorithm for 3D vectors intersection

I have 2 vectors, each defined by 2 Point3D (origin and direction). I need to find out the point of their intersection.
A little bit of help is always welcome.
I will post my function, which gives me wrong output.
public static CurvIntersect3D Intersect2Linii3D (Vector3D dr1, Vector3D dr2) {
CurvIntersect3D result = new CurvIntersect3D(0, null);
double x = Math3D.VectorNorm3D(dr1.getDirectie());
double t = Math3D.VectorNorm3D(dr2.getDirectie());
double cosa = (dr1.getDirectie().getX()*dr2.getDirectie().getX() + dr1.getDirectie().getY()*dr2.getDirectie().getY() + dr1.getDirectie().getZ()*dr2.getDirectie().getZ()) / (t*x);
Punct3D p1 = dr1.getOrigine();
Punct3D p2 = new Punct3D(), p3 = new Punct3D();
for (int i=0; i<3; i++)
{
p2.set(i, dr1.getOrigine().get(i) + dr1.getDirectie().get(i));
p3.set(i, dr1.getOrigine().get(i) + dr2.getDirectie().get(i));
}
Matrici.Matrice3x3 rot = Math3D.GetMatriceRotatie(p1, p2, p3);
Punct3D orig = new Punct3D();
for (int i=0; i<3; i++)
orig.set(i, rot.getElement(i, 0) * (dr2.getOrigine().getX()-dr1.getOrigine().getX()) +
rot.getElement(i, 1) * (dr2.getOrigine().getY()-dr1.getOrigine().getY()) +
rot.getElement(i, 2) * (dr2.getOrigine().getZ()-dr1.getOrigine().getZ()));
x = orig.getY() - orig.getZ()* cosa / Math.sqrt(1 - cosa*cosa);
p1 = new Punct3D();
for (int i=0; i<3; i++)
p1.set(i, dr1.getOrigine().get(i) + x*dr1.getDirectie().get(i));
result.setCount(1);
result.add(p1);
return result;
}
CurvIntersec3D is a structure that stores the array of points and its length.
As mentioned before the two lines may not meet at a single point. The best you can do in general is find the point on line1 closest to line2 and vise versa. Connect those two points to create the common normal direction.
Given two lines passing through 3D points r1=[r1x,r1y,r1z] and r2=[r2x,r2y,r2z] and having unit directions e1=[e1x,e1y,e1z] and e2=[e2x,e2y,e2z] you can find the points on the line which are closest to the other line like this:
Find the direction projection u=Dot(e1,e2)=e1x*e2x+e1y*e2y+e1z*e2z
If u==1 then lines are parallel. No intersection exists.
Find the separation projections t1=Dot(r2-r1,e1) and t2=Dot(r2-r1,e2)
Find distance along line1 d1 = (t1-u*t2)/(1-u*u)
Find distance along line2 d2 = (t2-u*t1)/(u*u-1)
Find the point on line1 p1=Add(r1,Scale(d1,e1))
Find the point on line2 p2=Add(r2,Scale(d2,e2))
Note: You must have the directions as unit vectors, Dot(e1,e1)=1 and Dot(e2,e2)=1.
The function Dot() is the vector dot product. The function Add() adds the components of vectors, and the function Scale() multiplies the components of the vector with a number.
Good luck.
Are you sure that your lines have intersection?
If it is guaranteed, then the problem is rather simple: Get parametric equations of lines, solve a system of two linear equations like these:
A_X0+t*A_Dir_X = B_X0+u*B_DirX , where X0 is base point, and Dir is direction vector (take into account any pair of coordinates with non-zero cross product)
If not, then it is necessary to calculate a distance between two skew lines at first. If the distance is zero, then we could find intersection point.

3D Arrays in OpenCL

I am new to OpenCL programming and my input is a 3D array. I am calculating the index as:
int gidX = get_global_id(0)?1:get_global_id(0);
int gidY = get_global_id(1)?1:get_global_id(1);
int gidZ = get_global_id(2)?1:get_global_id(2);
int index = gidX + (gidY*SizeX) + (gidZ*SizeY*SizeZ);
Is this the right way to do it? How do I use the local thread ids with 3d arrays? I had used it with 2d arrays as:
int tid = get_local_id(0);
int gid = get_global_id(0);
int index = tid + gid*width;
And, is there a way I could use image3d_t type for my 3D volume?
Thanks,
Sayan
What you seem to need is some basic information about the functionality and working principles of OpenCL. Please have a look to the following links:
http://developer.download.nvidia.com/compute/cuda/3_2_prod/toolkit/docs/OpenCL_Programming_Guide.pdf
http://www.nvidia.com/object/cuda_opencl_new.html
http://developer.download.nvidia.com/compute/cuda/3_0/sdk/website/OpenCL/website/samples.html
You code samples for getting gidX, gidY and gidZ do not make much sense and the calculation of the index is wrong, too. The calculation depends on the ordering of your 3D matrix. It should look something like:
int index = x + y * sizeX + z * sizeX * sizeY;
But you should check the documentation first. Especially the working principle of the local ids are not explained quickly.
It depends how you have your 3D array linearized to memory.. but Rick's answer coded as an inline function would work fine. The other optimization you may want are prefetching to local memory when possible.
/* Visualize as a cube. You are looking at the front in x,y coordinates. Z is depth. You have stored it by starting at (x=0, y=0) and taking the depth z lists of elements one by one and placing them in a contiguous array.*/
//Inline this
int matrix3D_lookup(int x, int y, int z, int sizeZ, int sizeX){
return z+ sizeZ*x +(sizeZ*sizeX*y);
}

Calculate a bezier spline to get from point to point

I have 2 points in X,Y + Rotation and I need to calculate a bezier spline (a collection of quadratic beziers) that connects these 2 points smoothly. (see pic) The point represents a unit in a game which can only rotate slowly. So to get from point A to B, it has to take a long path. The attached picture shows quite an exaggeratedly curvy path, but you get the idea.
What formulas can I use to calculate such a bezier spline?
Just saw that I misunderstood your question. Couldn't you use a single cubic hermite splines instead since you have a start and end point and two directions (tangents)? Are there any additional constraints?
To calculate the start and end tangents just use the start and end direction and scale them with the distance between the start and end points (and additionally some other constant factor like 0.5 depending on how curvy you want the path to be).:
p0 = startpoint;
p1 = endpoint;
float scale = distance(p0, p1);
m0 = Vec2(cos(startangle), sin(startangle)) * scale;
m1 = Vec2(cos(endangle), sin(endangle)) * scale;
I use this system to interpolate camera paths in a game I'm working on and it works great.
As you probably know, there are infinite solutions, even if we assume 2 control points.
I found Smoothing Algorithm Using Bézier Curves, which answers your question (see equations of Bx(t) and By(t) in the beginning):
Bx(t) = (1-t)3 P1x + 3 (1-t)2 t P2x + 3 (1-t) t2 P3x + t3 P4x
By(t) = (1-t)3 P1y + 3 (1-t)2 t P2y + 3 (1-t) t2 P3y + t3 P4y
P1 and P4 are your endpoints, and P2 and P3 are the control points, which you're free to choose along the desired angles. If your control point is at a distance r along an angle θ from point (x, y), the coordinates of the point are:
x' = x - r sin(θ)
y' = y - r cos(θ)
(according to the co-ordinate system you've used—I think I got the signs right). The only free parameter is r, which you can choose as you want. You probably want to use
r = α dist(P1, P4)
with α < 1.
I don't remember where I got it, but I have been using this:
Vector2 CalculateBezierPoint(float t, Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3)
{
float u = 1 - t;
float tt = t*t;
float uu = u*u;
float uuu = uu * u;
float ttt = tt * t;
Vector2 p = uuu * p0; //first term
p += 3 * uu * t * p1; //second term
p += 3 * u * tt * p2; //third term
p += ttt * p3; //fourth term
return p;
}
where t is ratio along path between start and end points.

Resources