We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Index › 3d arc - static/physics suggestions please
 Pages: 1 2
 jeffg 3d arc - static/physics? suggestions please Jan 26th, 2010, 8:07am   I'm trying to create some arcs (in 3d space) that would link geographical areas on the earth.  See NYTE as an example.  Point A might be linked to New York, point C would be linked to Paris, and B would be some object linked to both A & C (floating in space).  So A->B<-C (A and C linked to points on earth).  D (Beijing) could also be linked to B.So, does anyone have a suggestion on how best to achieve creating the arc and point for B.  A,C,D would be set points in space.Toxi's verlet physics, Traer's Physics, or some other static method  I might have thousands of points connected.  Though I don't think I need a constant update of positions.  All the points should be static after position calculation.Thanks for any suggestions!  This is an awesome community.
 gll Re: 3d arc - static/physics? suggestions please Reply #1 - Jan 26th, 2010, 8:27am   Triplets are defining one Circle. (Pt1, Pt2, Pt3) is enough to define a circle in space. This doesn't mean that this circle is embedded on the globe's surface. The circle may be inside or outside or on the surface.With 2 points, you have different circles possibilities.With 4 points, if all the points are aligned, then, you have a circle, otherwise, you have no possible solution. In fact, with 4 points, you define a sphere. If you have a set of four points, you then have only one corresponding sphere.Three points circles in 3D:http://www.gamedev.net/community/forums/topic.asp?topic_id=489058http://mathforum.org/library/drmath/view/54323.htmlThat may not be exactly what you are looking for... LaBelle / ANAR.ch / LaBelle.spaceKIT.ca
 splat Re: 3d arc - static/physics? suggestions please Reply #2 - Jan 31st, 2010, 10:02am   Hey Jeff,  I'm responsible for those NYTE arcs, but was actually just digging around on these forums in search of a better way to do this. I did that with a pretty ghetto hack. Basically I converted the latitude/longitudes to xyz coords with a janky function that mflux (Michael Chang) helped me make. It basically just rotates around the origin and supplies a vector that you can push out to any distance (specifically the radius of your globe -- and then the distance out that you want). Here's the secret sauce (where p is your PApplet): public PVector latLonToXYZ(PVector xy, float distance)        {              p.pushMatrix();            p.rotateY( p.radians(90f +  xy.y) );                  p.rotateX( p.radians(xy.x) );                p.translate(0,0,distance);            p.scale(0f);            PVector a = new PVector ( p.modelX(0f,0f,0f), p.modelY(0f,0f,0f), p.modelZ(0f,0f,0f));            p.popMatrix();            return a;        }This works ok for linking all your locations to a variety of points ... now I'm trying to figure out how to make nice semi-circles -- ironically more difficult for a math-hater like myself. Hope this helps -- Good luck!
 splat Re: 3d arc - static/physics? suggestions please Reply #3 - Jan 31st, 2010, 10:04am   Oh, and if it wasn't clear xy is a PVector where .x is lat and .y is lon. the PVector that gets returned is world x,y,z
 jeffg Re: 3d arc - static/physics? suggestions please Reply #4 - Jan 31st, 2010, 11:42am   Thanks, I'll give that a try.  I plan to start working on it again this week.
 V Re: 3d arc - static/physics? suggestions please Reply #5 - Jan 31st, 2010, 1:10pm   ive done this by using the 2 end points to define a line, finding 2 control points along that line, rotate them, then using a bezier/spline get a list of points for the final curve and save it into a common list. after this process, render it all on a single call. this would be an improvement over the method you use in case you wanna render large sets of connections and do not need to process the connections on a per frame basis. Victor Martins | www.pixelnerve.com/v
 jeffg Re: 3d arc - static/physics? suggestions please Reply #6 - Jan 31st, 2010, 3:17pm   V, could you elaborate.  I'm not sure I understand.   I was thinking of using bezierPoint() to identify placement on a bezier.
 V Re: 3d arc - static/physics? suggestions please Reply #7 - Feb 1st, 2010, 7:13am   if bezierPoint gives you a point along a bezier curve, its fine.still you need to find some points for the curve right? So the rest still applies. Victor Martins | www.pixelnerve.com/v
 rafael.messias Re: 3d arc - static/physics? suggestions please Reply #8 - Jun 13th, 2010, 10:46am   Hi everyone, I've been trying to do something similar, but my bezier curves look horrible on my sphere. My setup is similar to NYTE: a bunch of points on the surface and curves/edges connecting some of them.I've been using the "bezier()" function to draw my curves, but I can't seem to find a good expression to find the control points for an edge between any two points. The catch is: when the distance between the points is small, the control points must be close to the surface to generate a small curve; when they are far away, the control points must be far away too so that the curve will not enter the globe itself.So far I've used a similar method: a straight line between the two points, find two "initial" control points in that line (equidistant from the center) and throw two vectors from the sphere center to the two initial points. These two vectors are then multiplied to some extent to find the two real control points outside the sphere.Problem is: how much should I multiply the vectors to get a "beautiful" bezier? it seems to me it depends directly on the distance between the points, but I don't know exactly how.Anyway, what I'd really like to know is: how the hell did you draw such beautiful curves on the NYTE?Edit: Also, the original thing that brought me to this topic: is there an easy way to draw 3D arcs between the points on the sphere surface? What I mean is, I also want to connect the points not with beziers like NYTE but with arcs on the surface.
 V Re: 3d arc - static/physics? suggestions please Reply #9 - Jun 13th, 2010, 12:00pm   I'll start with the later question. 3D arcs could be made of a list of points from you curve. As long as you know points on that curve, use that to create a 3d mesh around the path:http://www.google.com/search?hl=en&q=3d+arcs+site%3Aprocessing.org&aq=f&aqi=&aql...As for the other question:The greatest distance between 2 points would be diameter = radius*2 of the sphere.So use that idea to offset the control points. That would make points with great distance between them to have control points further away from the sphere and closer ones would have them closer and smoother. Play with it and see what best values fits you =)have fun Victor Martins | www.pixelnerve.com/v
 rafael.messias Re: 3d arc - static/physics? suggestions please Reply #10 - Jun 13th, 2010, 12:39pm   Thanks for the reply! Yeah, I'm playing around with the control points, but so far nothing looks very good. It'd be nice to know the parameters they used on NYTE. About the 3D arc, I don't know how I could set the curve to get the points... I've been thinking and, basically, what I'd need is to put (rotate) both points to the XY plane and then use the "arc()" function to draw the arc between them. That'd to the trick but I'm still working on how to rotate them both to the XY plane; seems kinda hard.
 V Re: 3d arc - static/physics? suggestions please Reply #11 - Jun 13th, 2010, 1:45pm   forget the parameters, make your own, reward is much better.using things like distance and diameter, think also of powers, e.g. distance^2.As for the arcs, arc should be building a path by using a list of points along a curve. Maybe you will have to run your own arc implementation, unless you can get the list of points from processing ??As for the rotations a few words for you.. Quaternions, Latitude/ Longitude and spherical coordinates.If you need help with that later let me know.. Victor Martins | www.pixelnerve.com/v
 toxi Re: 3d arc - static/physics? suggestions please Reply #12 - Jun 13th, 2010, 5:26pm   I don't quite understand why you'd use a physics engine for this Were you thinking of using the physics to create a catenary That'd would only work if your map is flat, but not on a globe, since that catenary shape would be determined by the global gravity vector...Anyhow, I've mocked up a super simple example below which also uses a spline approach. Click the mouse to create a new arc... Code:```/** * Arc3D demo: connect random points with arcs * @author toxi * * Dependencies: toxiclibscore-0018, toxiclibs_p5-0001 * (or newer, available from: http://toxiclibs.org/ ) */import processing.opengl.*;import toxi.geom.*;import toxi.processing.*;ToxiclibsSupport gfx;Plane ground;List arcPoints;void setup() {  size(800,600,OPENGL);  gfx=new ToxiclibsSupport(this);  ground=new Plane(new Vec3D(),Vec3D.Y_AXIS);  arcPoints=createNewArc();}void draw() {  background(255);  translate(width/2,height/2,0);  rotateX(mouseY*0.01);  rotateY(mouseX*0.01);  gfx.plane(ground,600);  gfx.lineStrip3D(arcPoints);}List createNewArc() {  // create random points in 2D then scale & place on XZ plane  Vec3D a=Vec2D.randomVector().scale(300).to3DXZ();  Vec3D b=Vec2D.randomVector().scale(300).to3DXZ();  // place zenith at mid point in XZ plane  Vec3D zenith=a.interpolateTo(b,0.5);  // set Y axis to half distance  zenith.y=a.distanceTo(b)/2;  // put points into spline  Spline3D s=new Spline3D();  s.add(a);  s.add(zenith);  s.add(b);  // sample curve  return s.computeVertices(20);}void mousePressed() {  arcPoints=createNewArc();} ```
 toxi Re: 3d arc - static/physics? suggestions please Reply #13 - Jun 13th, 2010, 6:37pm   And just found & updated the spherical version too again (done for a workshop last year). The arc shape isn't perfect by any means, but shows the principle... Code:```/** * Arc3DSphere demo: connect random points on sphere with arcs * @author toxi * * Dependencies: toxiclibscore-0018, toxiclibs_p5-0001 * (or newer, available from: http://toxiclibs.org/ ) */import processing.opengl.*;import toxi.geom.*;import toxi.processing.*;float GLOBE_RAD=200;ToxiclibsSupport gfx;Sphere globe;List arcPoints;void setup() {  size(800,600,OPENGL);  gfx=new ToxiclibsSupport(this);  globe=new Sphere(new Vec3D(),200);  // London > Auckland  arcPoints=createNewArc(new Vec3D(GLOBE_RAD,radians(-0.15),radians(51.58)),new Vec3D(GLOBE_RAD,radians(174.77),radians(-36.84)));  // arc from London > Porto  // arcPoints=createNewArc(new Vec3D(GLOBE_RAD,radians(-0.15),radians(51.58)),new Vec3D(GLOBE_RAD,radians(-8.63),radians(41.17)));}void draw() {  background(255);  translate(width/2,height/2,0);  rotateX(mouseY*0.01);  rotateY(mouseX*0.01);  origin(new Vec3D(),400);  stroke(0,50);  gfx.sphere(globe);  stroke(0);  gfx.lineStrip3D(arcPoints);}List createNewArc(Vec3D a, Vec3D b) {  Vec3D ac=a.copy().toCartesian();  Vec3D bc=b.copy().toCartesian();  // place zenith at mid point in cartesian space  // and then transfer back into spherical to  // manipulate radius  Vec3D zenith=ac.interpolateTo(bc,0.5).toSpherical();  // add half distance to radius  // (X coord of spherical vectors = radius)  zenith.x=GLOBE_RAD+ac.distanceTo(bc)*0.5;  // define 2 further helper points @ 25%, 75%  Vec3D t1=ac.interpolateTo(bc,0.25).toSpherical();  t1.x=GLOBE_RAD+ac.distanceTo(bc)*0.15;  Vec3D t2=ac.interpolateTo(bc,0.75).toSpherical();  t2.x=GLOBE_RAD+ac.distanceTo(bc)*0.15;  // put points into spline  Spline3D s=new Spline3D();  s.add(ac);  s.add(t1.toCartesian());  s.add(zenith.toCartesian());  s.add(t2.toCartesian());  s.add(bc);  // sample curve  return s.computeVertices(20);}void mousePressed() {  Vec3D a=new Vec3D(globe.radius,random(-PI,PI),random(-PI,PI));  Vec3D b=new Vec3D(globe.radius,random(-PI,PI),random(-PI,PI));  arcPoints=createNewArc(a,b);}void origin(Vec3D o, float len) {  stroke(255, 0, 0);  line(o.x, o.y, o.z, o.x + len, o.y, o.z);  stroke(0, 255, 0);  line(o.x, o.y, o.z, o.x, o.y + len, o.z);  stroke(0, 0, 255);  line(o.x, o.y, o.z, o.x, o.y, o.z + len);} ```
 jeffg Re: 3d arc - static/physics? suggestions please Reply #14 - Jun 13th, 2010, 6:47pm   Excellent examples Toxi, Thanks!
 Pages: 1 2