Drawing sine waves effeciently in android - java

I am making an app where I need to draw a sine wave between two given points. I have Google'd, and Google'd, and I haven't found anything that I have found suitable.
Is there an efficient way in android to use some pre defined points to draw a smooth wave like form?

You can use the android.graphics.Path class to construct a set of quadratic or cubic Bézier spline curves between your set of control points.

Related

3D Polynomial Interpolation

I am trying to create a 3D wireframe by interpolating known points on generated cross-sections. I need a smooth polynomial interpolating function for the collection of points with known XYZ coordinates that need to be interpolated. I will then need to evaluate this function to obtain the rest of the XYZ-coordinates in between. I have used cubic spline interpolation in the past for 2D applications but I haven't found anything useful for 3D applications.
I have looked into Tricubic interpolation but my points are not strictly increasing in the y and z coordinates and I don't have any known function that describes them. Finally I have looked into a reliable Catmull-Rom spline library.
Is there any interpolation method or library that can help me create smooth 3D curves given these x[], y[],z[] arrays. PS. My solution ideally needs to in java.

Linear Interpolation of Scattered 2D Data

So I have some irregularly spaced data that I want to interpolate onto a regular grid. (I want to do exactly this but in Java) Here's a picture:
Basically I have the x and y coordinates of each point and a z value associated with each point and I want to interpolate between them and fill in the center of my image.
What is the best way to do this using Java? Is there a built in 2D interpolation library I can use or should I try a "roll my own" approach?
This post and this one also seem to be trying to do about what I am but their answers don't quite apply.
Someone else with the same problem but no solution.
Note: I am using JavaFX-2 so if I could somehow use their Interpolator class that'd be great.
.
.
EDIT:
If anyone stumbles upon this and wants to know what I ended up using, it was a Delaunay Triangulation implementation from BGU:
Main Site
Code API
If linear interpolation is sufficient, I suggest you to use a 3d mesh with Gouraud Shading for drawing:
Convert the 2d point cloud to a mesh (you can google for existing algorithms)
Mapping the z value of each point to the vertex' color
Using Gouraud Shading to enable linear interpolation between the vertex colors
Creating a camera on top to the mesh and using a othonormal projection (to avoid perspective)
You say that you can use JavaFX. JavaFX supports 3d scenes and you can build your own meshes. But looking into the JavaDoc of TriangleMesh, I can't find any method to set the vertex color I found only a method to set the (x,y,z) and (u,v) (texture coordinates) coordinates.

How to draw absolutely custom shape in Java?

The most complex shape, supported by Java2D API is a Bezier segment. Suppose I want to draw rational segment (each control point has a weight and the entire rendering formula is slightly different).
How to accomplish that?
Is it possible to extend rendering engine to be able to draw more complex shapes?
UPDATE
Usual way to implement custom shape is implementing Shape interface. This interface has key methods to return PathIterator while PathIterator iterates over segment types. There are only 5 segment types. The most curved of them is SEG_CUBICTO which is standard Bezier curve with 4 control points (including 2 for beginning and end).
If I apply linear fractional transform to bezier curve, each control point get a weight, as an addition to it's coordinates, and Bezier curve turns to NURBS (not sure about that, have failed to learn exact terminology). Anyway, the formula for curve differs from Bezier.
You cannot really extend the rendering engine: you can create Graphics/Graphics2D subclasses, but you have no control over the instantiation, so you cannot force the drawing framework to pass your subclass to the painting methods.
What you can do is to create a RationalShape implementation of Shape that has methods that draw anything you like, and returns a PathIterator which approximates it using Bézier splines. As a user of graphical programs like Photoshop I found that every curve can be approximated very well with Bézier splines, I don't know how complicated the math behind this approximation would be.

How to detect a quadrilateral shape in an image in Java?

I want to detect a quadrilateral shape in an image in Java. I can use the HoughLinesP method in OpenCV (using javaCV for opencv java binding) to detect line segments. But I can't figure out how to detect a quadrilateral shape - is there another method for that or some way to use the hough lines? Also once the corners of the quadrilateral are detected, I want it to return a rectangle just like this class does - http://www.aforgenet.com/framework/docs/html/7039a71d-a87d-47ef-7907-ad873118e374.htm - is there an equivalent library in openCV?
How do your input images look like? If you detect lots of line segments with the Hough transformation, you could maybe try using RANSAC to generate a number of quadrilateral shape hypothesis, find a way to rate their fitness and return the best hypothesis.
One hypothesis could be generated like this:
choose four random line segments from the detected line segment set
find the four corners by looking for intersections of the lines the chosen line segments lie on
rate the fitness of the quadrilateral shape defined by these four points
The fitness could maybe be the area of the hypothetical quadrilateral (see the Bretschneider's formula for calculating the area of a convex quadrilateral), the distance of the quadrilateral edges from the other line segments in the detected set, or something that better fits your application.
This is just an idea, I haven't tried using this approach yet (but I'm planing on implementing something similar). Let me know if you think this could work, or why it won't! :)
Your algorithm could be something like this
Process the image to find edges (Canny filter)
Apply Hough Transformation to find lines
Detect pairs of lines that intersect with an angle of 90 deg (aprox)
If you use OpenCV library than you definitely should try FindChessboardCorners function. And also here's a good tutorial.

Drawing splines using openGL

I try to draw a spline using openGL and Java.
What I have now is just a set of points. What I want is a spline, which goes through each of these points.
Is there a special function in openGL for accomplish it?
Is there a special function in openGL for accomplish it?
No. And later versions of OpenGL (v3 and later) did focus on deprecating and removing anything specialized. You can write a combination of tesselation, geometry and vertex shaders that generate a tesselated bezier spline from a set of input points. But you'll have to write those shaders yourself.

Categories