Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
714 B
2
Indexable
Never
/* kernel function to calculate coordinates according to given formula */
__global__ void calculateCoordinates(Coordinate *coordinates, Point *points, float t, int numPoints) {
	Point point;
	/* calculate index */
	int i = threadIdx.x + blockIdx.x * blockDim.x;

	/* calculate only for valid indices */
	if (i < numPoints) {
		point = points[i];
		coordinates[i].x = ((point.x2 - point.x1) / 2 ) * sin (t * M_PI / 2) + (point.x2 + point.x1) / 2;
		coordinates[i].y = point.a * coordinates[i].x + point.b;
		
		//printf("Point ID = %d, Point X1 = %f, Point X2 = %f, Point a = %f, Point b = %f, Coordinate: X = %f, Y = %f\n", point.id, point.x1, point.x2, point.a, point.b, coordinates[i].x, coordinates[i].y); 
	}
}