Matplotlib Tangent Plane of surface is very distorted - matplotlib

I've been trying to plot a tangent plane to a quadratic surface for a really long time yesterday with a couple of nice helpers.
It works well if below the surface to some degree as above, but as soon as it's further and steeper away it looks extremely distorted.
Even when we made it much smaller, it just looks super weird.
Is there something we forgot to consider?
Thank you!
I tried sympy and plotly too, it's the same, from below it looks quite nice, as soon as it goes to the sides it's starts to look weird.
Should I use a different coordinate system (meshgrid) to make it more aligned?

Related

Continuous modification of a set of points - find all nearest neighbors

I have a 3D set of points. These points will undergo a series of tiny perturbations (all points will be perturbed at once). Example: if I have 100 points in a box, each point may be moved up to, but no more than 0.2% of the box width in each iteration of my program.
After each perturbation operation, I want to know the new distance to each point's nearest neighbor.
This needs to use a very fast data structure; I'm optimizing this for speed. It's a somewhat tricky problem because I'm modifying all points at once. Approximate NN algorithms are not suitable for this problem.
I feel like the answer is somewhere between kd-trees and Voronoi tessellations, but I am not an expert on data structures, so I am baffled about what to do. I sure this is a very hard problem that would require a lot of research to reach a truly optimal solution, but even something fairly optimal will work for me.
Thanks
You can try a quadkey or monster curve. It reduce the dimension and fills the plane. Microsoft bing maps quadkey is a good start to learn.

transform a path along an arc

Im trying to transform a path along an arc.
My project is running on osX 10.8.2 and the painting is done via CoreAnimation in CALayers.
There is a waveform in my project which will be painted by a path. There are about 200 sample points which are mirrored to the bottom side. These are painted 60 times per second and updated to a song postion.
Please ignore the white line, it is just a rotation indicator.
What i am trying to achieve is drawing a waveform along an arc. "Up" should point to the middle. It does not need to go all the way around. The waveform should be painted along the green circle. Please take a look at the sketch provided below.
Im not sure how to achieve this in a performant manner. There are many points per second that need coordinate correction.
I tried coming up with some ideas of my own:
1) There is the possibility to add linear transformations to paths, which, i think, will not help me here. The only thing i can think of is adding a point, rotating the path with a transformation, adding another point, rotating and so on. But this would be very slow i think
2) Drawing the path into an image and bending it would surely lead to image-artifacts.
3) Maybe the best idea would be to precompute sample points on an arc, then save save a vector to the center. Taking the y-coordinates of the waveform, placing them on the sample points and moving them along the vector to the center.
But maybe i am just not seeing some kind of easy solution to this problem. Help is really appreciated and fresh ideas very welcome. Thank you in advance!
IMHO, the most efficient way to go (in terms of CPU usage) would be to use some form of pre-computed approach that would take into account the resolution of the display.
Cleverly precomputed values
I would go for the mathematical transformation (from linear to polar) and combine two facts:
There is no need to perform expansive mathematical computation
There is no need to render two points that are too close from each other
I have no ready-made algorithm for you, but you could use a pre-computed sin or cos table, and match the data range to the display size in order to work with integers.
For instance imagine we have some data ranging from 0 to 1E6 and we need to display the sin value of each point in a 100 pix height rectangle. We can use a pre-computed sin table and work with integers. This way displaying the sin value of a point would be much quicker. This concept can be refined to get a nicer result.
Also, there are some ways to retain only significant points of a curve so that the displayed curve actually looks like the original (see the Ramer–Douglas–Peucker algorithm on wikipedia). But I found it to be inefficient for quickly displaying ever-changing data.
Using multicore rendering
You could compute different areas of the curve using multiple cores (can be tricky)
Or you could use pre-computing using several cores, and one core to do finish the job.

Bones in 3DS max or blender

I'm pretty much grabbing at straws here cause I have no idea what I'm asking, but here is the question.
I've been looking at 3D modeling out of pure interest and came across the concept of bones.
Now, I am not too sure what bones are even after looking it up on wiki, but they seem like an abstraction of real-life skeletons and whatnot, so in a model of say a human I just think of them as the skeleton.
To my understanding, a bone is defined by a translation, rotation, and a scale on the x, y and z axis'. (Isn't that just a single point?)
I am interested in taking a model in blender or max and export the information (whatever they may be) that is used to define these bones. I can definitely see the bones in these programs, but I want to get that out into a text file Is there a way to export this?
I think you need to seperate these ideas:
Bones - which as you correcly say have a position and rotation. They are the objects that you can control and will effect the skin of the model. They are usually in a hierarchy so that if you move one bone then it will affect all of the bones connected to it, like a human skeleton.
Skin - this is the polygonal mesh that you can usually see. It is given a base position by you in the editor and the skeleton operates on the skin to move it around.
Animation - This is data to pass to the bones. Usually a rotation, for example to make an arm bend.
http://gpwiki.org/index.php/OpenGL:Tutorials:Basic_Bones_System gives a good explanation.
Hope that helps :3

Detect Collision point between a mesh and a sphere?

I am writing a physics simulation using Ogre and MOC.
I have a sphere that I shoot from the camera's position and it travels in the direction the camera is facing by using the camera's forward vector.
I would like to know how I can detect the point of collision between my sphere and another mesh.
How would I be able to check for a collision point between the two meshes using MOC or OGRE?
Update: Should have mentioned this earlier. I am unable to use a 3rd party physics library as we I need to develop this myself (uni project).
The accepted solution here flat out doesn't work. It will only even sort of work if the mesh density is generally high enough that no two points on the mesh are farther apart than the diameter of your collision sphere. Imagine a tiny sphere launched at short range on a random vector at a huuuge cube mesh. The cube mesh only has 8 verts. What are the odds that the cube is actually going to hit one of those 8 verts?
This really needs to be done with per-polygon collision. You need to be able to check intersection of polygon and a sphere (and additionally a cylinder if you want to avoid tunneling like reinier mentioned). There are quite a few resources for this online and in book form, but http://www.realtimerendering.com/intersections.html might be a useful starting point.
The comments about optimization are good. Early out opportunities (perhaps a quick check against a bounding sphere or an axis aligned bounding volume for the mesh) are essential. Even once you've determined that you're inside a bounding volume, it would probably be a good idea to be able to weed out unlikely polygons (too far away, facing the wrong direction, etc.) from the list of potential candidates.
I think the best would be to use a specialized physics library.
That said. If I think about this problem, I would suspect that it's not that hard:
The sphere has a midpoint and a radius. For every point in the mesh do the following:
check if the point lies inside the sphere.
if it does check if it is closer to the center than the previously found point(if any)
if it does... store this point as the collision point
Of course, this routine will be fairly slow.
A few things to speed it up:
for a first trivial reject, first see if the bounding sphere of the mesh collides
don't calc the squareroots when checking distances... use the squared lengths instead.(much faster)
Instead of comparing every point of the mesh, use a dimensional space division algorithm (quadtree / BSP)for the mesh to quickly rule out groups of points
Ah... and this routine only works if the sphere doesn't travel too fast (relative to the mesh). If it would travel very fast, and you sample it X times per second, chances are the sphere would have flown right through the mesh without every colliding. To overcome this, you must use 'swept volumes' which basically makes your sphere into a tube. Making the math exponentially complicated.

Smoothing Zedgraph linegraphs without 'bumps'

When you use Zedgraph for linegraphs and set IsSmooth to true, the lines are nicely curved instead of having hard corners/angles.
While this looks much better for most graphs -in my humble opinion- there is a small catch. The smoothing algorithm makes the line take a little 'dive' or 'bump' before going upwards or downwards.
In most cases, if the datapoint are themselves smooth, this isn't a problem, but if your datapoints go from say 0 to 15, the 'dive' makes the line go under the x-axis, which makes it seems as though there are some datapoints below zero (which is not the case).
How can I fix this (prefably easily ;)
No simple answer for this. Keeping the tension near zero will be your simplest solution.
ZedGraph uses GDI's DrawCurve tension parameter to apply smoothness, which is probably Hermite Interpolation. You can try to implement your own Cosine Interpolation, which will keep local extremes because of its nature. You can look at the this link to see why:
http://local.wasp.uwa.edu.au/~pbourke/miscellaneous/interpolation/
EDIT: Website is down. Here is a cached version of the page:
http://web.archive.org/web/20090920093601/http://local.wasp.uwa.edu.au/~pbourke/miscellaneous/interpolation/
You could try to alter the myCurve.Line.SmoothTension property up or down and see if that helps.