Given two or more points (plus any other variables), can someone give me the Python code/just the formula for calculating the curve between them? Just a general bezier curve, it doesn’t have to be super complicated.
I don’t know a lot about curves, but I am defiantly willing to learn.
If you need a starting point:
# a list of points
points = [(0,0),(1,1),(2,0)]
# the rest is up to you
This would be used in some sort of “click to add points to this graph” kind of interface.
Another interesting thing would be a formula to get any point on that curve.
-Sunjay03
All I need, is the algorithm for a curve, which should tell me where the new points of the curve are between the first two points of my list of points.
So something like this:
# a list of points
points = [(0,1),(1,1),(0,2)]
# the first point
current_point = points[0]
# all the new points that will be generated soon. in a list
newpoints = []
for point in points[1:]:
newpoints.append(current_point)
# The curve algorithm adds lots of points to new points
# based on current_point and point
current_point = point
This is for Blender 2.49 and therefore, Python 2.6
-Sunjay03
find the algo and write it in python
should be very easy to do
in the other script it was for a sinus i think so the equation is very simple in this case
Y = A sin(angle ) and tnis give you the 2 points
you could also scale it or rotate afterward or add some equations to do that!
dpends on the equation i cannot guess what you need as algo here
you have to find it and then do it in python !
the script shown in example use TK
i mean i never used this before so cannot help you with this one
but if you find the doc let us know
in any case it would be better to go with 2,5 i guess
I think, what you need is an implementation of certain interpolation method in Python. I have translated some interpolation algorithms to Turbo Pascal (Delphi) some 2-3 years ago but they were regarding 2D curves, i.e. interpolating the point data to obtaining a curve that best matches the points. For doing that one should have the equation of the function of the required curve in advance in parametric form, then using certain algorithm (for example, the less sum of squares method) - to arrive at the best set of parameters for THAT equation given a precision threshold which should be also previously known. A good reading to start with the matter is given here. To me, the solution would look like using the general 3D cubic or 3D hermite interpolation for best results in Blender as the points may be really 3D :spin: Also, reflecting the realities in Blender, one should know at what precision to generate a point to represent the solution curve visually. And finally, I think the more are the points, the more precise interpolation you can get but after a longer calculation time! One can rely on such interpolation INSIDE the point cloud, while OUTSIDE it - the curve just goes endlessly as per the last interpolation restrictions, sooo one should be careful with that!
verts is a list of coordinates like [(1,4,3), (4,2,6),…]
nth is the number of the derivative one wants.
If you put 0 in there you get the bezier curve defined by the verts.
t is the location on the curve (between 0 and1) you want to get
then you get a return value where you are on the curve (a new vert)
I see. I am more in the drawing stage of the curves right now, and from what I understand, your function gives me the point on the graph closest to the verts?
Could you maybe edit my blend and re-upload it? You seem to know a lot more about what you are talking about than I do.
Well, I am not an expert in BGE and I dont know why but for some reason I have problems with Rasterizer module (I refer to posting #6 above:
Compiled with Python version 2.6.2.
Checking for installed Python... got it!
Traceback (most recent call last):
File "Text", line 37, in <module>
ImportError: No module named Rasterizer
Fortunately, I was able to get a copy of your calculated data, then I put them into EXCEL and I think the graph shows that they are correctly calculated:
Therefore, you’d need to check the drawing function performance… I think
My ONE-and-ONLY idea at the moment is that you check (somehow) if in the game only the 3 initial points are shown, so that they are prime lines rather than cosine curves…