hi, I need to bounce objects against a border that is not running parallel to x or y, but in a gradient angle. actually I need to bounce the objects within a pentagon. iSeg2D allows object to cross the border when they bounce, there is no x/y-max for gradients. I am also looking into frank's pyode script. Is there something in it, that can do that? marius.
On Sat, 13 Oct 2007, marius schebella wrote:
I need to bounce objects against a border that is not running parallel to x or y, but in a gradient angle.
What's a "gradient angle"? never heard that one.
_ _ __ ___ _____ ________ _____________ _____________________ ... | Mathieu Bouchard - tél:+1.514.383.3801, Montréal QC Canada
I haven't heard it before, but tried to translate it from german (steigungswinkel) any line that is defined by f(x)=ax+b and where a!=0
btw. I made a stupid mistake in my patch, because I attached the outlets for force to position, which gave me a weird movement... marius.
Mathieu Bouchard wrote:
On Sat, 13 Oct 2007, marius schebella wrote:
I need to bounce objects against a border that is not running parallel to x or y, but in a gradient angle.
What's a "gradient angle"? never heard that one.
_ _ __ ___ _____ ________ _____________ _____________________ ... | Mathieu Bouchard - tél:+1.514.383.3801, Montréal QC Canada
On Sat, 13 Oct 2007, marius schebella wrote:
I haven't heard it before, but tried to translate it from german (steigungswinkel) any line that is defined by f(x)=ax+b and where a!=0
That's called "linear" or "affine" equation.
In one terminology, "linear" is the general case, and "linear homogeneous" when b=0.
In another terminology, "affine" is the general case, and "linear" is when b=0.
But that's probably not all that you want to support: you want also to support f(x)=b and the non-function case of a vertical line. The thing is, functions of 1 variable to 1 variable are all that they teach people in high-school, but if you want to compute things in which y and x are considered of equal importance and not hierarchised, you have to stop considering one as the function of the other. You could, for example, use plain equations (not functions) for things that don't move, and consider y,x to be functions of t for things that move.
However, I don't remember anything about MSD, so I can't help you with that.
_ _ __ ___ _____ ________ _____________ _____________________ ... | Mathieu Bouchard - tél:+1.514.383.3801, Montréal QC Canada
how would you call the angle/gradient that the equation has. for example: f(x)=kx+b... if k=1, the line has a "gradient angle" of 45 degrees if k=2 the angle is ~63. angle=arctan(k). marius.
Mathieu Bouchard wrote:
On Sat, 13 Oct 2007, marius schebella wrote:
I haven't heard it before, but tried to translate it from german (steigungswinkel) any line that is defined by f(x)=ax+b and where a!=0
That's called "linear" or "affine" equation.
In one terminology, "linear" is the general case, and "linear homogeneous" when b=0.
In another terminology, "affine" is the general case, and "linear" is when b=0.
But that's probably not all that you want to support: you want also to support f(x)=b and the non-function case of a vertical line. The thing is, functions of 1 variable to 1 variable are all that they teach people in high-school, but if you want to compute things in which y and x are considered of equal importance and not hierarchised, you have to stop considering one as the function of the other. You could, for example, use plain equations (not functions) for things that don't move, and consider y,x to be functions of t for things that move.
However, I don't remember anything about MSD, so I can't help you with that.
_ _ __ ___ _____ ________ _____________ _____________________ ... | Mathieu Bouchard - tél:+1.514.383.3801, Montréal QC Canada
On Sat, 13 Oct 2007, marius schebella wrote:
how would you call the angle/gradient that the equation has.
a direction... and i would probably express it as a pair of numbers, cos(angle) and sin(angle), because that scales better to 3-D later on, and also it's better to keep everything as cartesian than work with actual angles. (it's less trouble, even though polar forms might look easier at first)
_ _ __ ___ _____ ________ _____________ _____________________ ... | Mathieu Bouchard - tél:+1.514.383.3801, Montréal QC Canada
Hallo, marius schebella hat gesagt: // marius schebella wrote:
I need to bounce objects against a border that is not running parallel to x or y, but in a gradient angle. actually I need to bounce the objects within a pentagon. iSeg2D allows object to cross the border when they bounce, there is no x/y-max for gradients. I am also looking into frank's pyode script. Is there something in it, that can do that?
Yes, everything is there. Just create some plane-like geoms without bodies for the pentagon, then use a sphere as the moving object. This is not restricted to 2D, it's full 3D, but as long as you're not generating any forces in Z-direction, you should be fine. (Restriciting movement to 2D with ODE is possible, but a bit tricky.)
Frank Barknecht _ ______footils.org__
thanks frank, I will look into it. do you have any benchmark test data about the speed of pyode compared to pmpd or msd? I basically need only 2d at the moment. with pmpd I think I can draw at least 100-150 objects, maybe more(?). but that depends on the framerate, and many other factors (like how many of the objects are linked to each other...) marius.
Frank Barknecht wrote:
Hallo, marius schebella hat gesagt: // marius schebella wrote:
I need to bounce objects against a border that is not running parallel to x or y, but in a gradient angle. actually I need to bounce the objects within a pentagon. iSeg2D allows object to cross the border when they bounce, there is no x/y-max for gradients. I am also looking into frank's pyode script. Is there something in it, that can do that?
Yes, everything is there. Just create some plane-like geoms without bodies for the pentagon, then use a sphere as the moving object. This is not restricted to 2D, it's full 3D, but as long as you're not generating any forces in Z-direction, you should be fine. (Restriciting movement to 2D with ODE is possible, but a bit tricky.)
Ciao
Hallo, marius schebella hat gesagt: // marius schebella wrote:
thanks frank, I will look into it. do you have any benchmark test data about the speed of pyode compared to pmpd or msd? I basically need only 2d at the moment. with pmpd I think I can draw at least 100-150 objects, maybe more(?). but that depends on the framerate, and many other factors (like how many of the objects are linked to each other...)
If you only need point masses, msd is much faster, because ODE always does rigid body simulatons. If you need rigid bodies, then msd doesn't cut it and you need ODE (or something like that).
100-150 bodies in ODE are not that much of a problem, but you need a fast machine already.
I don't really use pmpd anymore, so I cannot comment on that, but msd is faster than pmpd as well, collision detection is trickier, though.
Frank Barknecht _ ______footils.org__
# I read the first mail and find an algorithm for the special case of "moving point particles in a 2D pentagon boundary". The answer is given as using pyode script but I am excited about my solution and want to share it with you :-) # The easy part of using a rectangular boundary (of which sides are parallel to the axes) is that, one should only check if x position of a particle is greater than x_max (coordinate of the right side of the rectangle), if x<x_min, y<y_min and y>y_max. And if it exceeds the boundary in the next step of the simulation according to ODE (or any kind of calculation) of the simulation, then reverse the velocity in that direction (and mirror the coordinate using the boundary line as the axis of symmetry). # So, We can try to use this simple idea in pentagon case. # We can divide the pentagon in five triangles: Put a point in the center and draw lines to vertexes. http://www.math.union.edu/~dpvc/courses/1999-00/MTH012-02-WI00/notes/Divided...http://www.math.union.edu/%7Edpvc/courses/1999-00/MTH012-02-WI00/notes/DividedPentagon.jpg # Call the bottom triangle 0th triangle, turn in counter clockwise direction and call other triangles as 1st, 2nd... # The algorithm is as following: # First determine in which triangle the particle is. One can get this using an atan2(x,y) like function. atan2 returns the angle between the position of the particle and the x-axis. We can beforehand calculate the angles between the sides of triangles and the x-axis. And using this information we can find in which triangle the particle is. (or maybe y/x is just enough for determination) # If it is in the zeroth triangle, all we have to do is to look for the y position. If it is less than minus of the height of the bottom triangle then it exceeds the boundary. Apply the reflection like in a rectangular boundary. # One can not do this in other triangles (1st, 2nd...). Because their boundaries are not parallel to axes but they have slopes. So, if we rotate the coordinate system, until the bottom side of the triangle becomes parallel to y-axis, e.g. rotate 72 degrees clock wise for 1st triangle, 2*72 degrees for the 2nd..., (360/5=72) we can apply this reflection law. (this is the trick) # After applying the reflection one must rotate the coordinate system counter clock wise. # Here is the formula of rotating a coordinate system (taken from Arfken, Mathematical Methods for Physicists). (x,y) is the coordinate in the old system and (x', y') is the coordinate in the new (rotated) system, a is the angle of rotation.
x' = x*cos(a) + y*sin(a) y' = -x*sin(a) + y*cos(a)
# But one don't have to make trigonometric calculations for every rotation, because a is constant. It is 72 or integer multiples of 72 and one can calculate sines and cosines beforehand e.g. sin(72) = 0.9511, cos(72)=0.3090, for CCW rotations, and sin(-72)=-0.9511, cos(-72)=0.3090 for CW rotations. # Here is the pseudo code:
take_the_simulation_one_step_further() for_each_particle: n = the_number_of_triangle_which_includes_the_particle(x,y) (x',y',vx',vy')=rotate_the_velocity_and_coordinate_of_the_particle(-n*72,x,y,vx,vy) (x',ynew',vx',vynew')=reflect_the_particle_(if_necessary)_as_if_it_reflects_from_the_bottom_of_a_rectangle(x',y',vx',vy')
(x,y,vx,vy)=rotate_the_velocity_and_coordinate_of_the_particle(n*72,x',ynew',vx',vynew')
# I didn't try this of course, but seems plausible. Thanks for reading :-) -uğur-
On 10/13/07, marius schebella marius.schebella@gmail.com wrote:
hi, I need to bounce objects against a border that is not running parallel to x or y, but in a gradient angle. actually I need to bounce the objects within a pentagon. iSeg2D allows object to cross the border when they bounce, there is no x/y-max for gradients. I am also looking into frank's pyode script. Is there something in it, that can do that? marius.
PD-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
thanks, Uğur, I like your diving into math, but actually I have more calculations than just the bouncing, so there will be also interaction with the objects and I will not write maths for those too. so I will stick with pyode, I think it makes life a little easier... marius.
Uğur Güney wrote:
# I read the first mail and find an algorithm for the special case of "moving point particles in a 2D pentagon boundary". The answer is given as using pyode script but I am excited about my solution and want to share it with you :-) # The easy part of using a rectangular boundary (of which sides are parallel to the axes) is that, one should only check if x position of a particle is greater than x_max (coordinate of the right side of the rectangle), if x<x_min, y<y_min and y>y_max. And if it exceeds the boundary in the next step of the simulation according to ODE (or any kind of calculation) of the simulation, then reverse the velocity in that direction (and mirror the coordinate using the boundary line as the axis of symmetry). # So, We can try to use this simple idea in pentagon case. # We can divide the pentagon in five triangles: Put a point in the center and draw lines to vertexes. http://www.math.union.edu/~dpvc/courses/1999-00/MTH012-02-WI00/notes/Divided...http://www.math.union.edu/%7Edpvc/courses/1999-00/MTH012-02-WI00/notes/DividedPentagon.jpg # Call the bottom triangle 0th triangle, turn in counter clockwise direction and call other triangles as 1st, 2nd... # The algorithm is as following: # First determine in which triangle the particle is. One can get this using an atan2(x,y) like function. atan2 returns the angle between the position of the particle and the x-axis. We can beforehand calculate the angles between the sides of triangles and the x-axis. And using this information we can find in which triangle the particle is. (or maybe y/x is just enough for determination) # If it is in the zeroth triangle, all we have to do is to look for the y position. If it is less than minus of the height of the bottom triangle then it exceeds the boundary. Apply the reflection like in a rectangular boundary. # One can not do this in other triangles (1st, 2nd...). Because their boundaries are not parallel to axes but they have slopes. So, if we rotate the coordinate system, until the bottom side of the triangle becomes parallel to y-axis, e.g. rotate 72 degrees clock wise for 1st triangle, 2*72 degrees for the 2nd..., (360/5=72) we can apply this reflection law. (this is the trick) # After applying the reflection one must rotate the coordinate system counter clock wise. # Here is the formula of rotating a coordinate system (taken from Arfken, Mathematical Methods for Physicists). (x,y) is the coordinate in the old system and (x', y') is the coordinate in the new (rotated) system, a is the angle of rotation.
x' = x*cos(a) + y*sin(a) y' = -x*sin(a) + y*cos(a)
# But one don't have to make trigonometric calculations for every rotation, because a is constant. It is 72 or integer multiples of 72 and one can calculate sines and cosines beforehand e.g. sin(72) = 0.9511, cos(72)=0.3090, for CCW rotations, and sin(-72)=-0.9511, cos(-72)=0.3090 for CW rotations. # Here is the pseudo code:
take_the_simulation_one_step_further() for_each_particle: n = the_number_of_triangle_which_includes_the_particle(x,y) (x',y',vx',vy')=rotate_the_velocity_and_coordinate_of_the_particle(-n*72,x,y,vx,vy) (x',ynew',vx',vynew')=reflect_the_particle_(if_necessary)_as_if_it_reflects_from_the_bottom_of_a_rectangle(x',y',vx',vy')
(x,y,vx,vy)=rotate_the_velocity_and_coordinate_of_the_particle(n*72,x',ynew',vx',vynew')
# I didn't try this of course, but seems plausible. Thanks for reading :-) -uğur-
On 10/13/07, marius schebella marius.schebella@gmail.com wrote:
hi, I need to bounce objects against a border that is not running parallel to x or y, but in a gradient angle. actually I need to bounce the objects within a pentagon. iSeg2D allows object to cross the border when they bounce, there is no x/y-max for gradients. I am also looking into frank's pyode script. Is there something in it, that can do that? marius.
PD-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
PD-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list