surface
A Material Design CSS only framework
I have a 3D closed mesh car object having a surface made up
triangles. I want to calculate its volume, center of volume and inertia tensor.
Could you help me
Regards.
George
Source: (StackOverflow)
Basically, on surfaces that are going to exist right until the program terminates, do I need to run SDL_FreeSurface()
for each of them, or would SDL_Quit()
take care of all this for me?
I ask mainly because the pointers to a number of my surfaces are class members, and therefore I would need to keep track of each class instance (in a global array or something) if I wanted to run SDL_FreeSurface()
on each of their respective surfaces. If SDL_Quit() will do it all in one fell swoop for me, I'd much rather go with that :D
Source: (StackOverflow)
I'm plotting multiple surfaces on the same figure using matplotlib, and I'd like to see only the topmost surface, as matlab shows.
Matlab 3D view:
Matlab top view:
Matplotlib 3D view:
Matplotlib top view:
How can I get Matplotlib to show a result similar to Matlab, in which whatever topmost class is shown at the top, as opposed to one single class taking precedence over the other?
Source: (StackOverflow)
I have a cloud of points scattered in a 2D Euclidean space. I would like to calculate the area inside the polygon linking the most extreme (=peripheral) points of the cloud. In other words, I would like to estimate the area covered by the cloud in this space.
Is there a formula in R?
Thanks a lot for any response
Julien
Source: (StackOverflow)
I am learning pygame
and want a graphic for a button with the three states: normal, hover, and pressed. I have an image like this one ...
... and I want to get a new Surface
using a portion of it.
I'm loading the image with this code:
buttonStates = pygame.image.load(os.path.join('image','button.png'))
How can I make a new surface using just a portion of that graphic?
Source: (StackOverflow)
I have a set of 3d points that approximate a surface. Each point, however, are subject to some error. Furthermore, the set of points contain a lot more points than is actually needed to represent the underlying surface.
What I am looking for is an algorithm to create a new (much smaller) set of points representing a simplified, smoother version of the surface (pardon for not having a better definition than "simplified, smoother"). The underlying surface is not a mathematical one so I'm not hoping to fit the data set to some mathematical function.
Source: (StackOverflow)
I have an example 5x5 matrix with the following values:
dat <- matrix(seq(1,13,0.5), nrow=5, byrow=TRUE)
dat[seq(2,25,2)] <- NA
1 | NA | 2 | NA | 3
NA | 4 | NA | 5 | NA
6 | NA | 7 | NA | 8
NA | 9 | NA | 10 | NA
11 | NA | 12 | NA | 13
I cannot for the life of me get a 3D surface plot using for example persp3d() because of the missing values. Isn't there a way that R can just interpolate the values and still plot them?
Source: (StackOverflow)
I want to make a prediction for a child's height, based on the fathers+mothers height and the gender and visualize this.
Without the gender variable I can still visualize this in a 3D graph.
But when I add the gender I'd like to have 2 surface plots, one for gender==male and one for gender==female. Is there an elegant way to fix this gender variable in the fit2
model, so that I can plot both?
library(fields)
library(scatterplot3d)
library(ggplot2)
library(UsingR)
data(GaltonFamilies)
attach(GaltonFamilies)
fit <- lm(childHeight ~ mother + father)
fit2 <- lm(childHeight ~ mother + father + gender)
colorSet <- tim.colors(2)
s3d <- scatterplot3d(father,mother,childHeight,color=colorSet[gender])
detach(GaltonFamilies)
s3d$plane3d(fit)
The fit including gender looks like:
> fit2
Call:
lm(formula = childHeight ~ mother + father + gender)
Coefficients:
(Intercept) mother father gendermale
16.5212 0.3176 0.3928 5.2150
But when I tryto plot two surface planes for both genders I get an error:
s3d$plane3d(fit2)
Error in segments(x, z1, x + y.max * yx.f, z2 + yz.f * y.max, lty = ltya, :
cannot mix zero-length and non-zero-length coordinates
I'd like to have something like this, does anybody know how this is possible?
s3d$plane3d(fit2(gendermale=1))
s3d$plane3d(fit2(gendermale=0))
Source: (StackOverflow)
Hi
This is my first question in this forum, so please bear with me and I hope I'm not violating any rules. I am looking at different ways to model scattered 3d data as a gridded function (over xy support, z=z(x,y)).
Answering another question, coryan was so nice as to mention the method using heat equation to interpolate (approximate) a terrain surface which I've heard about and been eager to learn, or even find a parallel implementation? Could please coryan or anybody else point me to such an implementation, if it's in public domain, or at least to explain a bit further how it is done.
Source: (StackOverflow)
I have a problem of getting principal curvatures from a given mesh (of a shape).
I am trying to use 'patchcurvature' method from Matlab file exchange. However, the method always given the positive curvatures. I think it might be that the method considered the mesh as separate patches, and calculate the principal curvatures for each patch.
[~,~,Dir1,Dir2,PrincipalCurvature1,PrincipalCurvature1]=patchcurvature(meshFaceVertices);
I also tried to use another method from Matlab file exchange called 'surfature'; however, it calculates the principal curvatures of a 'surface' defined by three 2D arrays of points on the surface. I am not sure how to create a 'surface' with 2D point arrays from a existing mesh defined by vertices and faces. There are some methods convert surface to mesh but not the other way around...
Any ideas would be appreciated. Thanks so much and Happy New Year!!!
Best,
A.
Source: (StackOverflow)
If I declare a SDL_Surface pointer in a class, can i share it with another class to draw on it in somehow?
class foo{
private:
SDL_Surface* mainScreen;
public:
foo() {
mainScreen = SDL_SetVideoMode(400,300,32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_OPENGL);
}
~foo() {
SDL_FreeSurface(mainScreen);
}
SDL_Surface* getSurf() {
return mainScreen;
}
};
class fee{
private:
SDL_Surface* screen_passed;
public:
void draw(SDL_Surface* screen) {
screen_passed = screen;
SDL_Surface* img;
SDL_Surface* app;
app = IMG_Load("image.png");
img = SDL_DisplayFormatAlpha(app);
SDL_FreeSurface(app);
SDL_Rect destR;
destR.x=0;
destR.y=0;
SDL_BlitSurface(img, NULL, screen, &destR);
}
};
int main(int argc, char* argv[]) {
SDL_Init(SDL_INIT_VIDEO);
foo a;
fee b;
b.draw(a.getSurf());
SDL_Flip(a.getSurf());
sleep(5);
return 0;
}
compiles and run, but the screen is black, can anyone help?
Source: (StackOverflow)
Say I have the following array/matrix in python (any language will do, to be honest).
A =
[0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 0 0 0 0
0 1 1 1 1 1 0 0 0 0
0 1 1 1 1 1 1 0 0 0
0 0 1 1 1 1 1 1 0 0
0 0 1 1 1 1 1 0 0 0
0 0 1 1 1 1 1 0 0 0
0 0 0 1 1 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0]
Is there any easy way to manipulate entries in this array as if they are pixels. Example, would there be any way to create an interior and a surface of arbitrary length, to get, for example:
[0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 0 0 0 0
0 1 1 0 0 1 0 0 0 0
0 1 1 0 0 0 1 0 0 0
0 0 1 0 0 0 1 1 0 0
0 0 1 0 0 0 1 0 0 0
0 0 1 1 0 1 1 0 0 0
0 0 0 1 1 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0]
Perhaps there is some way to recursively solve this, or maybe in a different way, which would rely on the entries around each element. Any thoughts?
Source: (StackOverflow)
I want to change the color of a surface depending on another value (an ID) that takes discrete values (so I need a discrete colorbar).
In the simplified example below I have drawn a sphere with 3 different IDs:
0/red on the left
2/blue on the middle
1/Green on the left
But with the code below, I obtain some strange behaviours (green points) at the limit between red and blue.
It is probably because of an interpolation!
The Code:
from mayavi import mlab
import numpy as np
# my dataset -simplified-
x,y,z = np.mgrid[-3:3:100j, -3:3:100j, -3:3:100j]
values = np.sqrt(x**2 + y**2 + z **2)
# my color values : the volume is divided in 3 sub-volumes along x taking
colorvalues=np.empty(values.shape)
colorvalues[0:33,:,:]=0.
colorvalues[33:66,:,:]=2.
colorvalues[66:,:,:] =1.
src = mlab.pipeline.scalar_field(values)
src.image_data.point_data.add_array(colorvalues.T.ravel())
src.image_data.point_data.get_array(1).name = 'myID'
src.image_data.point_data.update()
# the surface i am interested on
contour = mlab.pipeline.contour(src)
contour.filter.contours= [2.8,]
# to map the ID
contour2 = mlab.pipeline.set_active_attribute(contour, point_scalars='myID')
# And we display the surface The colormap is the current attribute: the ID.
mySurf=mlab.pipeline.surface(contour2)
# I change my colormap to a discrete one : R-G-B
mySurf.module_manager.scalar_lut_manager.lut.table = np.array([[255,0,0,255],[0,255,0,255],[0,0,255,255]])
mlab.colorbar(title='ID', orientation='vertical', nb_labels=3)
mlab.show()
I have also tried with this line before mlab.show():
mySurf.actor.mapper.interpolate_scalars_before_mapping = True
The rendering is better but green points become a green strip.
Source: (StackOverflow)
I have the following code to display a 3D surface using ax.plot_surface
:
fig = plt.figure()
ax = fig.gca(projection='3d')
X,Y = np.meshgrid(range(k_mean.shape[0]), range(k_mean.shape[1]))
Z = k_mean
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, linewidth=0., alpha=0.8, cmap=cm.nipy_spectral, antialiased=False, shade=False)
cset = ax.contour(X, Y, Z, zdir='z', offset=0, cmap=cm.nipy_spectral)
cset = ax.contour(X, Y, Z, zdir='x', offset=0, cmap=cm.nipy_spectral)
cset = ax.contour(X, Y, Z, zdir='y', offset=120, cmap=cm.nipy_spectral)
ax.set_xlim(0, 120)
ax.set_ylim(0, 120)
ax.set_zlim(0, 1)
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()
plt.savefig('3d.pdf', dpi=500)
The display of the plot in Spyder is "correct", but the PDF seems to ignore the linewidth=0.
. How can I fix that?
Spyder output:
PDF output:
Source: (StackOverflow)
I am working on a control algorithm to be run on an embedded system. My programming language is C and the system will be pretty tightly constrained in terms of memory and processing power.
I have a few (in the order of about 10) reference points in three dimensional space. These are normally static, but will change once in a while. I would like to fit a spline surface so that it passes though all of these points, and then have a function which for a given input vector (x, z) returns distance y from the plane y = 0.
I think this is a problem that needs to be solved in two parts: 1) some new coefficients will be calculated whenever a reference point changes and 2) the coefficients are plugged into a function which returns y for a given (x, z). (Only 2 needs to happen 'real time'.)
I have researched on the net this a bit but am having a hard time with the math, and a lot of the material is specific to computer graphics. I am not even sure what type of spline I need; NURBS and Catmull-Rom both seem to be relevant. Lastly, regarding the shape of the edges of my spline: As my input vectors are from well bounded sensor readings, I don't really care what the spline does outside of that boundary.
I would be very grateful for some help or pointers to relevant material, and any snippets of pseudo code would be much appreciated.
Source: (StackOverflow)