Howto sample a curve?

10 messages Options
Embed this post
Permalink
Tim Knip-2

Howto sample a curve?

Reply Threaded More More options
Print post
Permalink
Hi list,

I have a curved line (curveTo)...

How to get straight line-segments following this curve?
Where start- and endpoints of the segments lie on the curve .

Say I have a circle created from 4 curveTo's. How do I create like 16
straight line segments?

Thanks!
Tim

_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Paul deCoursey

Re: Howto sample a curve?

Reply Threaded More More options
Print post
Permalink
I had written this function a long time ago to calculate points on a  
curve.  t is like the percentage of the curve, so 0.5 would give you  
the midpoint of the curve.

function calculateQuadraticBezierPoint(t:Number, sp:Point, cp:Point,  
ep:Point):Point {
        var result:Point = new Point(10, 10);
       
     var ax:Number = sp.x + ((cp.x - sp.x) * t);
     var ay:Number = sp.y + ((cp.y - sp.y) * t);
        var bx:Number = cp.x + ((ep.x - cp.x) * t);
     var by:Number = cp.y + ((ep.y - cp.y) * t);
        var cx:Number = ax + ((bx - ax) * t);
     var cy:Number = ay + ((by - ay) * t);
       
        result.x = cx;
        result.y = cy;
       
        return result;
}


Hope that helps.


On May 22, 2008, at 2:48 PM, Tim Knip wrote:

> Hi list,
>
> I have a curved line (curveTo)...
>
> How to get straight line-segments following this curve?
> Where start- and endpoints of the segments lie on the curve .
>
> Say I have a circle created from 4 curveTo's. How do I create like 16
> straight line segments?
>
> Thanks!
> Tim
>
> _______________________________________________
> Papervision3D mailing list
> [hidden email]
> http://osflash.org/mailman/listinfo/papervision3d_osflash.org


_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
makc

Re: Howto sample a curve?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Tim Knip-2
http://caffeineowl.com/graphics/2d/vectorial/bezierintro.html#paraQuad

On Thu, May 22, 2008 at 10:48 PM, Tim Knip <[hidden email]> wrote:

> Hi list,
>
> I have a curved line (curveTo)...
>
> How to get straight line-segments following this curve?
> Where start- and endpoints of the segments lie on the curve .
>
> Say I have a circle created from 4 curveTo's. How do I create like 16
> straight line segments?
>
> Thanks!
> Tim
>
> _______________________________________________
> Papervision3D mailing list
> [hidden email]
> http://osflash.org/mailman/listinfo/papervision3d_osflash.org
>

_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Tim Knip-2

Re: Howto sample a curve?

Reply Threaded More More options
Print post
Permalink
Gracias chicos!
T

2008/5/22 Makc <[hidden email]>:

> http://caffeineowl.com/graphics/2d/vectorial/bezierintro.html#paraQuad
>
> On Thu, May 22, 2008 at 10:48 PM, Tim Knip <[hidden email]> wrote:
>> Hi list,
>>
>> I have a curved line (curveTo)...
>>
>> How to get straight line-segments following this curve?
>> Where start- and endpoints of the segments lie on the curve .
>>
>> Say I have a circle created from 4 curveTo's. How do I create like 16
>> straight line segments?
>>
>> Thanks!
>> Tim
>>
>> _______________________________________________
>> Papervision3D mailing list
>> [hidden email]
>> http://osflash.org/mailman/listinfo/papervision3d_osflash.org
>>
>

_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Aleksandar Mancic

Re: Howto sample a curve?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Tim Knip-2
If you need a PV3D curve, you can use the attached Bezier3D class. It
uses multiple Line3D instances (default segmentation is 10) to simulate
a quadric bezier curve, giving you pretty much the drawing API's
curveTo() functionality in 3D. Usage is, i hope, quite self-explanatory :D

It will also explain you how segmentation is done - just look at the
build() method. If you want to change the shape of Bezier3D run-time
(changing properties than calling rebuild() method), you should also
edit Lines3D class from PV3D and replace it's removeLine() method
because it doesn't remove vertices when removing a line. Replace the
removeLine() method with something like:

        public function removeLine(line:Line3D):void
        {
            var lineindex : int = lines.indexOf(line);
            if(lineindex>-1)
            {
                var vertices:Array = geometry.vertices;
                var c_v0:int = vertices.indexOf(line.v0);
                if(c_v0 != -1) vertices.splice(c_v0, 1);
                var c_v1:int = vertices.indexOf(line.v1);
                if(c_v1 != -1) vertices.splice(c_v1, 1);

                lines.splice(lineindex,1);  
            }
            else if(Papervision3D.VERBOSE)
            {
                trace("Papervision3D Lines3D.removeLine : WARNING
removal of non-existant line attempted. ");

            }
        }

That should do the trick... Until I finish my Graphics3D extension for
PV3D :)

Cheers...


Tim Knip wrote:

> Hi list,
>
> I have a curved line (curveTo)...
>
> How to get straight line-segments following this curve?
> Where start- and endpoints of the segments lie on the curve .
>
> Say I have a circle created from 4 curveTo's. How do I create like 16
> straight line segments?
>
> Thanks!
> Tim
>
> _______________________________________________
> Papervision3D mailing list
> [hidden email]
> http://osflash.org/mailman/listinfo/papervision3d_osflash.org
>
>  


_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Aleksandar Mancic

Re: Howto sample a curve?

Reply Threaded More More options
Print post
Permalink
Ooops, forgot to attach the Bezier3D class :blush:

There you go...

Aleksandar Mancic wrote:

> If you need a PV3D curve, you can use the attached Bezier3D class. It
> uses multiple Line3D instances (default segmentation is 10) to
> simulate a quadric bezier curve, giving you pretty much the drawing
> API's curveTo() functionality in 3D. Usage is, i hope, quite
> self-explanatory :D
>
> It will also explain you how segmentation is done - just look at the
> build() method. If you want to change the shape of Bezier3D run-time
> (changing properties than calling rebuild() method), you should also
> edit Lines3D class from PV3D and replace it's removeLine() method
> because it doesn't remove vertices when removing a line. Replace the
> removeLine() method with something like:
>
>        public function removeLine(line:Line3D):void
>        {
>            var lineindex : int = lines.indexOf(line);
>            if(lineindex>-1)
>            {
>                var vertices:Array = geometry.vertices;
>                var c_v0:int = vertices.indexOf(line.v0);
>                if(c_v0 != -1) vertices.splice(c_v0, 1);
>                var c_v1:int = vertices.indexOf(line.v1);
>                if(c_v1 != -1) vertices.splice(c_v1, 1);
>
>                lines.splice(lineindex,1);              }
>            else if(Papervision3D.VERBOSE)
>            {
>                trace("Papervision3D Lines3D.removeLine : WARNING
> removal of non-existant line attempted. ");
>
>            }
>        }
>
> That should do the trick... Until I finish my Graphics3D extension for
> PV3D :)
>
> Cheers...
>
>
> Tim Knip wrote:
>> Hi list,
>>
>> I have a curved line (curveTo)...
>>
>> How to get straight line-segments following this curve?
>> Where start- and endpoints of the segments lie on the curve .
>>
>> Say I have a circle created from 4 curveTo's. How do I create like 16
>> straight line segments?
>>
>> Thanks!
>> Tim
>>
>> _______________________________________________
>> Papervision3D mailing list
>> [hidden email]
>> http://osflash.org/mailman/listinfo/papervision3d_osflash.org
>>
>>  
>
>

/*
 * Copyright 2008 (c) Aleksandar Mancic, [hidden email]
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

/**
 * Bezier3D
 * Bezier3D for Papervision3D Public Alpha 2.0 - Great White
 *
 * @author Aleksandar Mancic
 * @version 0.0.2
 */

package com.topflashers.ext.pv3d.core.geom.renderables {
        import org.papervision3d.core.geom.Lines3D;
        import org.papervision3d.core.geom.renderables.Line3D;
        import org.papervision3d.core.geom.renderables.Vertex3D;
        import org.papervision3d.materials.special.LineMaterial;

        public class Bezier3D {

                private var _lines:Array;

                private var _instance:Lines3D;
                private var _material:LineMaterial;

                public function Bezier3D(instance:Lines3D, material:LineMaterial, size:Number, segments:int, start:Vertex3D, end:Vertex3D, control:Vertex3D) {

                        this._instance = instance;
                        this._material = material;
                        this.size = size;
                        this.segments = segments;
                        this.start = start;
                        this.end = end;
                        this.control = control;
                       
                        rebuild();
                }
               
                private var _size:Number = 1;
                public function get size():Number {
                        return _size;
                }
                public function set size(value:Number):void {
                        if(value == _size) return;
                        _size = value;
                }
               
                private var _segments:int = 10;
                public function get segments():int {
                        return _segments;
                }
                public function set segments(value:int):void {
                        if(value == _segments) return;
                        _segments = Math.max(1, value);
                }
               
                private var _start:Vertex3D;
                public function get start():Vertex3D {
                        return _start;
                }
                public function set start(value:Vertex3D):void {
                        if(value === _start) return;
                        _start = value;
                }
               
                private var _end:Vertex3D;
                public function get end():Vertex3D {
                        return _end;
                }
                public function set end(value:Vertex3D):void {
                        if(value === _end) return;
                        _end = value;
                }
               
                private var _control:Vertex3D;
                public function get control():Vertex3D {
                        return _control;
                }
                public function set control(value:Vertex3D):void {
                        if(value === _control) return;
                        _control = value;
                }
               
                public function rebuild():void {
                        clear();
                        build();
                }
               
                public function clear():void {
                        if(_lines && _lines.length) {
                                var c_len:int = _lines.length;
                                for(var i:int=0; i<c_len; i++) _instance.removeLine(_lines[i]);
                        }
                        _lines = [];
                }
               
                private function build():void {
                        var c_seg:Number, c_dseg:Number, c_sqdseg:Number, c_dbseg:Number, c_pseg:Number;
                        for(var i:int=0; i<_segments; i++) {
                                c_seg = i / _segments;
                                c_dseg = 1 - c_seg;
                                c_sqdseg = c_dseg * c_dseg;
                                c_dbseg = 2 * c_seg * c_dseg;
                                c_pseg = c_seg * c_seg;
                               
                                var c_p1:Vertex3D = new Vertex3D();
                                c_p1.x = c_sqdseg * _start.x + c_dbseg * _control.x + c_pseg * _end.x;
                                c_p1.y = c_sqdseg * _start.y + c_dbseg * _control.y + c_pseg * _end.y;
                                c_p1.z = c_sqdseg * _start.z + c_dbseg * _control.z + c_pseg * _end.z;
                               
                                c_seg = (i+1) / _segments;
                                c_dseg = 1 - c_seg;
                                c_sqdseg = c_dseg * c_dseg;
                                c_dbseg = 2 * c_seg * c_dseg;
                                c_pseg = c_seg * c_seg;
                               
                                var c_p2:Vertex3D = new Vertex3D();
                                c_p2.x = c_sqdseg * _start.x + c_dbseg * _control.x + c_pseg * _end.x;
                                c_p2.y = c_sqdseg * _start.y + c_dbseg * _control.y + c_pseg * _end.y;
                                c_p2.z = c_sqdseg * _start.z + c_dbseg * _control.z + c_pseg * _end.z;

                                var c_line:Line3D = new Line3D(_instance, _material, _size, c_p1, c_p2);
                                _lines.push(c_line);
                                _instance.addLine(c_line);
                        }
                }
        }
}
_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
James Hay

Re: Howto sample a curve?

Reply Threaded More More options
Print post
Permalink
I actually built a curve3D class that works in exactly the same way as the lines3D class but uses the curveTo() method of the flash drawing api so that you can get smooth curves instead of creating curves from seperate straight lines. Worked a treat!

Jimmy.

On Thu, May 22, 2008 at 9:38 PM, Aleksandar Mancic <[hidden email]> wrote:
Ooops, forgot to attach the Bezier3D class :blush:

There you go...


Aleksandar Mancic wrote:
If you need a PV3D curve, you can use the attached Bezier3D class. It uses multiple Line3D instances (default segmentation is 10) to simulate a quadric bezier curve, giving you pretty much the drawing API's curveTo() functionality in 3D. Usage is, i hope, quite self-explanatory :D

It will also explain you how segmentation is done - just look at the build() method. If you want to change the shape of Bezier3D run-time (changing properties than calling rebuild() method), you should also edit Lines3D class from PV3D and replace it's removeLine() method because it doesn't remove vertices when removing a line. Replace the removeLine() method with something like:

      public function removeLine(line:Line3D):void
      {
          var lineindex : int = lines.indexOf(line);
          if(lineindex>-1)
          {
              var vertices:Array = geometry.vertices;
              var c_v0:int = vertices.indexOf(line.v0);
              if(c_v0 != -1) vertices.splice(c_v0, 1);
              var c_v1:int = vertices.indexOf(line.v1);
              if(c_v1 != -1) vertices.splice(c_v1, 1);

              lines.splice(lineindex,1);              }
          else if(Papervision3D.VERBOSE)
          {
              trace("Papervision3D Lines3D.removeLine : WARNING removal of non-existant line attempted. ");

          }
      }

That should do the trick... Until I finish my Graphics3D extension for PV3D :)

Cheers...


Tim Knip wrote:
Hi list,

I have a curved line (curveTo)...

How to get straight line-segments following this curve?
Where start- and endpoints of the segments lie on the curve .

Say I have a circle created from 4 curveTo's. How do I create like 16
straight line segments?

Thanks!
Tim

_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org

 




/*
 * Copyright 2008 (c) Aleksandar Mancic, [hidden email]
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

/**
 * Bezier3D
 * Bezier3D for Papervision3D Public Alpha 2.0 - Great White
 *
 * @author              Aleksandar Mancic
 * @version             0.0.2
 */

package com.topflashers.ext.pv3d.core.geom.renderables {
       import org.papervision3d.core.geom.Lines3D;
       import org.papervision3d.core.geom.renderables.Line3D;
       import org.papervision3d.core.geom.renderables.Vertex3D;
       import org.papervision3d.materials.special.LineMaterial;

       public class Bezier3D {

               private var _lines:Array;

               private var _instance:Lines3D;
               private var _material:LineMaterial;

               public function Bezier3D(instance:Lines3D, material:LineMaterial, size:Number, segments:int, start:Vertex3D, end:Vertex3D, control:Vertex3D) {

                       this._instance = instance;
                       this._material = material;
                       this.size = size;
                       this.segments = segments;
                       this.start = start;
                       this.end = end;
                       this.control = control;

                       rebuild();
               }

               private var _size:Number = 1;
               public function get size():Number {
                       return _size;
               }
               public function set size(value:Number):void {
                       if(value == _size) return;
                       _size = value;
               }

               private var _segments:int = 10;
               public function get segments():int {
                       return _segments;
               }
               public function set segments(value:int):void {
                       if(value == _segments) return;
                       _segments = Math.max(1, value);
               }

               private var _start:Vertex3D;
               public function get start():Vertex3D {
                       return _start;
               }
               public function set start(value:Vertex3D):void {
                       if(value === _start) return;
                       _start = value;
               }

               private var _end:Vertex3D;
               public function get end():Vertex3D {
                       return _end;
               }
               public function set end(value:Vertex3D):void {
                       if(value === _end) return;
                       _end = value;
               }

               private var _control:Vertex3D;
               public function get control():Vertex3D {
                       return _control;
               }
               public function set control(value:Vertex3D):void {
                       if(value === _control) return;
                       _control = value;
               }

               public function rebuild():void {
                       clear();
                       build();
               }

               public function clear():void {
                       if(_lines && _lines.length) {
                               var c_len:int = _lines.length;
                               for(var i:int=0; i<c_len; i++) _instance.removeLine(_lines[i]);
                       }
                       _lines = [];
               }

               private function build():void {
                       var c_seg:Number, c_dseg:Number, c_sqdseg:Number, c_dbseg:Number, c_pseg:Number;
                       for(var i:int=0; i<_segments; i++) {
                               c_seg = i / _segments;
                               c_dseg = 1 - c_seg;
                               c_sqdseg = c_dseg * c_dseg;
                               c_dbseg = 2 * c_seg * c_dseg;
                               c_pseg = c_seg * c_seg;

                               var c_p1:Vertex3D = new Vertex3D();
                               c_p1.x = c_sqdseg * _start.x + c_dbseg * _control.x + c_pseg * _end.x;
                               c_p1.y = c_sqdseg * _start.y + c_dbseg * _control.y + c_pseg * _end.y;
                               c_p1.z = c_sqdseg * _start.z + c_dbseg * _control.z + c_pseg * _end.z;

                               c_seg = (i+1) / _segments;
                               c_dseg = 1 - c_seg;
                               c_sqdseg = c_dseg * c_dseg;
                               c_dbseg = 2 * c_seg * c_dseg;
                               c_pseg = c_seg * c_seg;

                               var c_p2:Vertex3D = new Vertex3D();
                               c_p2.x = c_sqdseg * _start.x + c_dbseg * _control.x + c_pseg * _end.x;
                               c_p2.y = c_sqdseg * _start.y + c_dbseg * _control.y + c_pseg * _end.y;
                               c_p2.z = c_sqdseg * _start.z + c_dbseg * _control.z + c_pseg * _end.z;

                               var c_line:Line3D = new Line3D(_instance, _material, _size, c_p1, c_p2);
                               _lines.push(c_line);
                               _instance.addLine(c_line);
                       }
               }
       }
}
_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org



_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Aleksandar Mancic

Re: Howto sample a curve?

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
There is only one problem with such approach - you essentially get a 2D curve plotted on a 3D plane, so it's still a 2D Bezier but with, well, a twist :D  That's why I've created the Bezier3D class - to get a full 3D Bezier, however, since it uses Line3D class to plot itself segmentation cannot be avoided. So, it all depends what you need.

I'll be releasing my Graphics3D addon for PV3D in a week or two that should be able to do all the Drawing API functions in 3D, allowing you to plot your points on all 3 axes. Till then use whatever suits you best :)

Cheers...

James Hay wrote:
I actually built a curve3D class that works in exactly the same way as the lines3D class but uses the curveTo() method of the flash drawing api so that you can get smooth curves instead of creating curves from seperate straight lines. Worked a treat!

Jimmy.

On Thu, May 22, 2008 at 9:38 PM, Aleksandar Mancic <[hidden email]> wrote:
Ooops, forgot to attach the Bezier3D class :blush:

There you go...


Aleksandar Mancic wrote:
If you need a PV3D curve, you can use the attached Bezier3D class. It uses multiple Line3D instances (default segmentation is 10) to simulate a quadric bezier curve, giving you pretty much the drawing API's curveTo() functionality in 3D. Usage is, i hope, quite self-explanatory :D

It will also explain you how segmentation is done - just look at the build() method. If you want to change the shape of Bezier3D run-time (changing properties than calling rebuild() method), you should also edit Lines3D class from PV3D and replace it's removeLine() method because it doesn't remove vertices when removing a line. Replace the removeLine() method with something like:

      public function removeLine(line:Line3D):void
      {
          var lineindex : int = lines.indexOf(line);
          if(lineindex>-1)
          {
              var vertices:Array = geometry.vertices;
              var c_v0:int = vertices.indexOf(line.v0);
              if(c_v0 != -1) vertices.splice(c_v0, 1);
              var c_v1:int = vertices.indexOf(line.v1);
              if(c_v1 != -1) vertices.splice(c_v1, 1);

              lines.splice(lineindex,1);              }
          else if(Papervision3D.VERBOSE)
          {
              trace("Papervision3D Lines3D.removeLine : WARNING removal of non-existant line attempted. ");

          }
      }

That should do the trick... Until I finish my Graphics3D extension for PV3D :)

Cheers...


Tim Knip wrote:
Hi list,

I have a curved line (curveTo)...

How to get straight line-segments following this curve?
Where start- and endpoints of the segments lie on the curve .

Say I have a circle created from 4 curveTo's. How do I create like 16
straight line segments?

Thanks!
Tim

_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org

 




/*
 * Copyright 2008 (c) Aleksandar Mancic, [hidden email]
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

/**
 * Bezier3D
 * Bezier3D for Papervision3D Public Alpha 2.0 - Great White
 *
 * @author              Aleksandar Mancic
 * @version             0.0.2
 */

package com.topflashers.ext.pv3d.core.geom.renderables {
       import org.papervision3d.core.geom.Lines3D;
       import org.papervision3d.core.geom.renderables.Line3D;
       import org.papervision3d.core.geom.renderables.Vertex3D;
       import org.papervision3d.materials.special.LineMaterial;

       public class Bezier3D {

               private var _lines:Array;

               private var _instance:Lines3D;
               private var _material:LineMaterial;

               public function Bezier3D(instance:Lines3D, material:LineMaterial, size:Number, segments:int, start:Vertex3D, end:Vertex3D, control:Vertex3D) {

                       this._instance = instance;
                       this._material = material;
                       this.size = size;
                       this.segments = segments;
                       this.start = start;
                       this.end = end;
                       this.control = control;

                       rebuild();
               }

               private var _size:Number = 1;
               public function get size():Number {
                       return _size;
               }
               public function set size(value:Number):void {
                       if(value == _size) return;
                       _size = value;
               }

               private var _segments:int = 10;
               public function get segments():int {
                       return _segments;
               }
               public function set segments(value:int):void {
                       if(value == _segments) return;
                       _segments = Math.max(1, value);
               }

               private var _start:Vertex3D;
               public function get start():Vertex3D {
                       return _start;
               }
               public function set start(value:Vertex3D):void {
                       if(value === _start) return;
                       _start = value;
               }

               private var _end:Vertex3D;
               public function get end():Vertex3D {
                       return _end;
               }
               public function set end(value:Vertex3D):void {
                       if(value === _end) return;
                       _end = value;
               }

               private var _control:Vertex3D;
               public function get control():Vertex3D {
                       return _control;
               }
               public function set control(value:Vertex3D):void {
                       if(value === _control) return;
                       _control = value;
               }

               public function rebuild():void {
                       clear();
                       build();
               }

               public function clear():void {
                       if(_lines && _lines.length) {
                               var c_len:int = _lines.length;
                               for(var i:int=0; i<c_len; i++) _instance.removeLine(_lines[i]);
                       }
                       _lines = [];
               }

               private function build():void {
                       var c_seg:Number, c_dseg:Number, c_sqdseg:Number, c_dbseg:Number, c_pseg:Number;
                       for(var i:int=0; i<_segments; i++) {
                               c_seg = i / _segments;
                               c_dseg = 1 - c_seg;
                               c_sqdseg = c_dseg * c_dseg;
                               c_dbseg = 2 * c_seg * c_dseg;
                               c_pseg = c_seg * c_seg;

                               var c_p1:Vertex3D = new Vertex3D();
                               c_p1.x = c_sqdseg * _start.x + c_dbseg * _control.x + c_pseg * _end.x;
                               c_p1.y = c_sqdseg * _start.y + c_dbseg * _control.y + c_pseg * _end.y;
                               c_p1.z = c_sqdseg * _start.z + c_dbseg * _control.z + c_pseg * _end.z;

                               c_seg = (i+1) / _segments;
                               c_dseg = 1 - c_seg;
                               c_sqdseg = c_dseg * c_dseg;
                               c_dbseg = 2 * c_seg * c_dseg;
                               c_pseg = c_seg * c_seg;

                               var c_p2:Vertex3D = new Vertex3D();
                               c_p2.x = c_sqdseg * _start.x + c_dbseg * _control.x + c_pseg * _end.x;
                               c_p2.y = c_sqdseg * _start.y + c_dbseg * _control.y + c_pseg * _end.y;
                               c_p2.z = c_sqdseg * _start.z + c_dbseg * _control.z + c_pseg * _end.z;

                               var c_line:Line3D = new Line3D(_instance, _material, _size, c_p1, c_p2);
                               _lines.push(c_line);
                               _instance.addLine(c_line);
                       }
               }
       }
}
_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org



_______________________________________________ Papervision3D mailing list [hidden email] http://osflash.org/mailman/listinfo/papervision3d_osflash.org


_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
James Hay

Re: Howto sample a curve?

Reply Threaded More More options
Print post
Permalink
this is true, but the same is true for lineTo and all realms of dealing with 3d in Flash since Flash is 2d. You're never actually dealing with anything 3d, it's all an illusion! I'm currently working on a big project that uses this method and it seems to work pretty well, it'll be live soon so hopefully you can let me know what you think.

Jimmy.

On Wed, May 28, 2008 at 1:54 AM, Aleksandar Mancic <[hidden email]> wrote:
There is only one problem with such approach - you essentially get a 2D curve plotted on a 3D plane, so it's still a 2D Bezier but with, well, a twist :D  That's why I've created the Bezier3D class - to get a full 3D Bezier, however, since it uses Line3D class to plot itself segmentation cannot be avoided. So, it all depends what you need.

I'll be releasing my Graphics3D addon for PV3D in a week or two that should be able to do all the Drawing API functions in 3D, allowing you to plot your points on all 3 axes. Till then use whatever suits you best :)

Cheers...

James Hay wrote:
I actually built a curve3D class that works in exactly the same way as the lines3D class but uses the curveTo() method of the flash drawing api so that you can get smooth curves instead of creating curves from seperate straight lines. Worked a treat!

Jimmy.

On Thu, May 22, 2008 at 9:38 PM, Aleksandar Mancic <[hidden email]> wrote:
Ooops, forgot to attach the Bezier3D class :blush:

There you go...


Aleksandar Mancic wrote:
If you need a PV3D curve, you can use the attached Bezier3D class. It uses multiple Line3D instances (default segmentation is 10) to simulate a quadric bezier curve, giving you pretty much the drawing API's curveTo() functionality in 3D. Usage is, i hope, quite self-explanatory :D

It will also explain you how segmentation is done - just look at the build() method. If you want to change the shape of Bezier3D run-time (changing properties than calling rebuild() method), you should also edit Lines3D class from PV3D and replace it's removeLine() method because it doesn't remove vertices when removing a line. Replace the removeLine() method with something like:

      public function removeLine(line:Line3D):void
      {
          var lineindex : int = lines.indexOf(line);
          if(lineindex>-1)
          {
              var vertices:Array = geometry.vertices;
              var c_v0:int = vertices.indexOf(line.v0);
              if(c_v0 != -1) vertices.splice(c_v0, 1);
              var c_v1:int = vertices.indexOf(line.v1);
              if(c_v1 != -1) vertices.splice(c_v1, 1);

              lines.splice(lineindex,1);              }
          else if(Papervision3D.VERBOSE)
          {
              trace("Papervision3D Lines3D.removeLine : WARNING removal of non-existant line attempted. ");

          }
      }

That should do the trick... Until I finish my Graphics3D extension for PV3D :)

Cheers...


Tim Knip wrote:
Hi list,

I have a curved line (curveTo)...

How to get straight line-segments following this curve?
Where start- and endpoints of the segments lie on the curve .

Say I have a circle created from 4 curveTo's. How do I create like 16
straight line segments?

Thanks!
Tim

_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org

 




/*
 * Copyright 2008 (c) Aleksandar Mancic, [hidden email]
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

/**
 * Bezier3D
 * Bezier3D for Papervision3D Public Alpha 2.0 - Great White
 *
 * @author              Aleksandar Mancic
 * @version             0.0.2
 */

package com.topflashers.ext.pv3d.core.geom.renderables {
       import org.papervision3d.core.geom.Lines3D;
       import org.papervision3d.core.geom.renderables.Line3D;
       import org.papervision3d.core.geom.renderables.Vertex3D;
       import org.papervision3d.materials.special.LineMaterial;

       public class Bezier3D {

               private var _lines:Array;

               private var _instance:Lines3D;
               private var _material:LineMaterial;

               public function Bezier3D(instance:Lines3D, material:LineMaterial, size:Number, segments:int, start:Vertex3D, end:Vertex3D, control:Vertex3D) {

                       this._instance = instance;
                       this._material = material;
                       this.size = size;
                       this.segments = segments;
                       this.start = start;
                       this.end = end;
                       this.control = control;

                       rebuild();
               }

               private var _size:Number = 1;
               public function get size():Number {
                       return _size;
               }
               public function set size(value:Number):void {
                       if(value == _size) return;
                       _size = value;
               }

               private var _segments:int = 10;
               public function get segments():int {
                       return _segments;
               }
               public function set segments(value:int):void {
                       if(value == _segments) return;
                       _segments = Math.max(1, value);
               }

               private var _start:Vertex3D;
               public function get start():Vertex3D {
                       return _start;
               }
               public function set start(value:Vertex3D):void {
                       if(value === _start) return;
                       _start = value;
               }

               private var _end:Vertex3D;
               public function get end():Vertex3D {
                       return _end;
               }
               public function set end(value:Vertex3D):void {
                       if(value === _end) return;
                       _end = value;
               }

               private var _control:Vertex3D;
               public function get control():Vertex3D {
                       return _control;
               }
               public function set control(value:Vertex3D):void {
                       if(value === _control) return;
                       _control = value;
               }

               public function rebuild():void {
                       clear();
                       build();
               }

               public function clear():void {
                       if(_lines && _lines.length) {
                               var c_len:int = _lines.length;
                               for(var i:int=0; i<c_len; i++) _instance.removeLine(_lines[i]);
                       }
                       _lines = [];
               }

               private function build():void {
                       var c_seg:Number, c_dseg:Number, c_sqdseg:Number, c_dbseg:Number, c_pseg:Number;
                       for(var i:int=0; i<_segments; i++) {
                               c_seg = i / _segments;
                               c_dseg = 1 - c_seg;
                               c_sqdseg = c_dseg * c_dseg;
                               c_dbseg = 2 * c_seg * c_dseg;
                               c_pseg = c_seg * c_seg;

                               var c_p1:Vertex3D = new Vertex3D();
                               c_p1.x = c_sqdseg * _start.x + c_dbseg * _control.x + c_pseg * _end.x;
                               c_p1.y = c_sqdseg * _start.y + c_dbseg * _control.y + c_pseg * _end.y;
                               c_p1.z = c_sqdseg * _start.z + c_dbseg * _control.z + c_pseg * _end.z;

                               c_seg = (i+1) / _segments;
                               c_dseg = 1 - c_seg;
                               c_sqdseg = c_dseg * c_dseg;
                               c_dbseg = 2 * c_seg * c_dseg;
                               c_pseg = c_seg * c_seg;

                               var c_p2:Vertex3D = new Vertex3D();
                               c_p2.x = c_sqdseg * _start.x + c_dbseg * _control.x + c_pseg * _end.x;
                               c_p2.y = c_sqdseg * _start.y + c_dbseg * _control.y + c_pseg * _end.y;
                               c_p2.z = c_sqdseg * _start.z + c_dbseg * _control.z + c_pseg * _end.z;

                               var c_line:Line3D = new Line3D(_instance, _material, _size, c_p1, c_p2);
                               _lines.push(c_line);
                               _instance.addLine(c_line);
                       }
               }
       }
}
_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org



_______________________________________________ Papervision3D mailing list [hidden email] http://osflash.org/mailman/listinfo/papervision3d_osflash.org


_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org



_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Aleksandar Dzeletovic

Re: Howto sample a curve?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Aleksandar Mancic
Aleksandar, I am using your Bezier3D class and it works like a charm. I am using it to map flight trajectories over Yahoo maps API running on Great White.

Thank you for sharing this excellent piece of work!!

Aleksandar Mancic wrote:
Ooops, forgot to attach the Bezier3D class :blush:

There you go...

Aleksandar Mancic wrote:
> If you need a PV3D curve, you can use the attached Bezier3D class. It
> uses multiple Line3D instances (default segmentation is 10) to
> simulate a quadric bezier curve, giving you pretty much the drawing
> API's curveTo() functionality in 3D. Usage is, i hope, quite
> self-explanatory :D
>
> It will also explain you how segmentation is done - just look at the
> build() method. If you want to change the shape of Bezier3D run-time
> (changing properties than calling rebuild() method), you should also
> edit Lines3D class from PV3D and replace it's removeLine() method
> because it doesn't remove vertices when removing a line. Replace the
> removeLine() method with something like:
>
>        public function removeLine(line:Line3D):void
>        {
>            var lineindex : int = lines.indexOf(line);
>            if(lineindex>-1)
>            {
>                var vertices:Array = geometry.vertices;
>                var c_v0:int = vertices.indexOf(line.v0);
>                if(c_v0 != -1) vertices.splice(c_v0, 1);
>                var c_v1:int = vertices.indexOf(line.v1);
>                if(c_v1 != -1) vertices.splice(c_v1, 1);
>
>                lines.splice(lineindex,1);              }
>            else if(Papervision3D.VERBOSE)
>            {
>                trace("Papervision3D Lines3D.removeLine : WARNING
> removal of non-existant line attempted. ");
>
>            }
>        }
>
> That should do the trick... Until I finish my Graphics3D extension for
> PV3D :)
>
> Cheers...
>
>
> Tim Knip wrote:
>> Hi list,
>>
>> I have a curved line (curveTo)...
>>
>> How to get straight line-segments following this curve?
>> Where start- and endpoints of the segments lie on the curve .
>>
>> Say I have a circle created from 4 curveTo's. How do I create like 16
>> straight line segments?
>>
>> Thanks!
>> Tim
>>
>> _______________________________________________
>> Papervision3D mailing list
>> Papervision3D@osflash.org
>> http://osflash.org/mailman/listinfo/papervision3d_osflash.org
>>
>>  
>
>


/*
 * Copyright 2008 (c) Aleksandar Mancic, sx@topflashers.com
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

/**
 * Bezier3D
 * Bezier3D for Papervision3D Public Alpha 2.0 - Great White
 *
 * @author Aleksandar Mancic
 * @version 0.0.2
 */

package com.topflashers.ext.pv3d.core.geom.renderables {
        import org.papervision3d.core.geom.Lines3D;
        import org.papervision3d.core.geom.renderables.Line3D;
        import org.papervision3d.core.geom.renderables.Vertex3D;
        import org.papervision3d.materials.special.LineMaterial;

        public class Bezier3D {

                private var _lines:Array;

                private var _instance:Lines3D;
                private var _material:LineMaterial;

                public function Bezier3D(instance:Lines3D, material:LineMaterial, size:Number, segments:int, start:Vertex3D, end:Vertex3D, control:Vertex3D) {

                        this._instance = instance;
                        this._material = material;
                        this.size = size;
                        this.segments = segments;
                        this.start = start;
                        this.end = end;
                        this.control = control;
                       
                        rebuild();
                }
               
                private var _size:Number = 1;
                public function get size():Number {
                        return _size;
                }
                public function set size(value:Number):void {
                        if(value == _size) return;
                        _size = value;
                }
               
                private var _segments:int = 10;
                public function get segments():int {
                        return _segments;
                }
                public function set segments(value:int):void {
                        if(value == _segments) return;
                        _segments = Math.max(1, value);
                }
               
                private var _start:Vertex3D;
                public function get start():Vertex3D {
                        return _start;
                }
                public function set start(value:Vertex3D):void {
                        if(value === _start) return;
                        _start = value;
                }
               
                private var _end:Vertex3D;
                public function get end():Vertex3D {
                        return _end;
                }
                public function set end(value:Vertex3D):void {
                        if(value === _end) return;
                        _end = value;
                }
               
                private var _control:Vertex3D;
                public function get control():Vertex3D {
                        return _control;
                }
                public function set control(value:Vertex3D):void {
                        if(value === _control) return;
                        _control = value;
                }
               
                public function rebuild():void {
                        clear();
                        build();
                }
               
                public function clear():void {
                        if(_lines && _lines.length) {
                                var c_len:int = _lines.length;
                                for(var i:int=0; i<c_len; i++) _instance.removeLine(_lines[i]);
                        }
                        _lines = [];
                }
               
                private function build():void {
                        var c_seg:Number, c_dseg:Number, c_sqdseg:Number, c_dbseg:Number, c_pseg:Number;
                        for(var i:int=0; i<_segments; i++) {
                                c_seg = i / _segments;
                                c_dseg = 1 - c_seg;
                                c_sqdseg = c_dseg * c_dseg;
                                c_dbseg = 2 * c_seg * c_dseg;
                                c_pseg = c_seg * c_seg;
                               
                                var c_p1:Vertex3D = new Vertex3D();
                                c_p1.x = c_sqdseg * _start.x + c_dbseg * _control.x + c_pseg * _end.x;
                                c_p1.y = c_sqdseg * _start.y + c_dbseg * _control.y + c_pseg * _end.y;
                                c_p1.z = c_sqdseg * _start.z + c_dbseg * _control.z + c_pseg * _end.z;
                               
                                c_seg = (i+1) / _segments;
                                c_dseg = 1 - c_seg;
                                c_sqdseg = c_dseg * c_dseg;
                                c_dbseg = 2 * c_seg * c_dseg;
                                c_pseg = c_seg * c_seg;
                               
                                var c_p2:Vertex3D = new Vertex3D();
                                c_p2.x = c_sqdseg * _start.x + c_dbseg * _control.x + c_pseg * _end.x;
                                c_p2.y = c_sqdseg * _start.y + c_dbseg * _control.y + c_pseg * _end.y;
                                c_p2.z = c_sqdseg * _start.z + c_dbseg * _control.z + c_pseg * _end.z;

                                var c_line:Line3D = new Line3D(_instance, _material, _size, c_p1, c_p2);
                                _lines.push(c_line);
                                _instance.addLine(c_line);
                        }
                }
        }
}
_______________________________________________
Papervision3D mailing list
Papervision3D@osflash.org
http://osflash.org/mailman/listinfo/papervision3d_osflash.org