Rotating a Bitmap on its' center (II)

Hello,
I found this thread on the subject: http://forums.adobe.com/message/10208#10208
I have the exact same problem as the OP of that thread - my bitmaps rotate on their stage (x,y), not the center of the image, and seeing as that's a fairly old thread I wonder whether easier solutions has surfaced since then?
Thanks for your input.

the only cumbersome part is that you reference the parent, not the object to effectively change reg point.  so, if you have a displayobject dObj and you want to (apparently) change its reg point to x,y in the dObj coordinate space, you can specify the reference you want to use for the parent and use:
yourtransformedobject = regPointF("whateverreference",dObj,x,y);
yourtransformedobject = regPointF("whateverreference",dObj,dObj.width,0); // reg point at upper right
yourtransformedobject = regPointF("whateverreference",dObj,dObj.width,dObj.height);  // reg point at lower right
yourtransformedobject = regPointF("whateverreference",dObj,dObj.width/2,dObj.height/2);  // reg point at center
---------------------------------------------------------- this doesn't need to change -----------------------------------
var tl:MovieClip=this;
function regPointF(s:String,dObj,regX:Number,regY:Number):DisplayObjectContainer{
tl[s]=new DisplayObjectContainer();
tl[s].addChild(dObj);
dObj.x=-regX;
dObj.y=-regY;
return tl[s];

Similar Messages

  • Resizing the stage around its center

    I have done some animation work on a stage 320px X 320px. I
    find that I must present the same work on a stage 240px X 320 px.
    If I use the Property Inspector window, I can enter the new stage
    size. Unfortunately, the window is resized with the left hand side
    of the screen as its reference point, effectively cutting off a
    large part of the right side of my work. I would expect to loose a
    piece of my animation at the right and the left evenly. How can I
    resize the stage around its center?
    Thanks

    well, I'm afraid that just the thing, you really can't.
    However, you can reposition everything on the Stage at the same
    time. First, with all layers unlocked, right click the timeline
    (anywhere but the first frame) and use 'select all frames', then
    use the 'edit multiple frames' button which the little 'box' like
    symbol next to the fps indicator on the bar just below the
    timeline, select 'onion all', now you can drag or nudge the entire
    animation at one time.

  • Rotate Movieclip depending on its direction its traveling?

    hello, this is prolly a simple question..
    but i need help making my arrow object rotate in the direction its traveling, since  i have gravity on the object..
    my arrow is called ArrowMC.
    anyone?

    This is my code to move the arrow and with gravity. with array
    function UpdateArrow():void
        var TempEnemy:MovieClip;
        for (var ia:int =Arrows.length-1; ia>=0; ia--)
            TempEnemy = Arrows[ia];
         TempEnemy.x+=5;
            //start gravity + collision
            var vyT:Number = 0;
            var GravityT:Number = .5;
            vyT +=  GravityT;
            //GroundObject
            if (! GroundObject.hitTestPoint(TempEnemy.x,TempEnemy.y,true))
                TempEnemy.y +=  vyT;
            for (var i:int=0; i<10; i++)
                if (GroundObject.hitTestPoint(TempEnemy.x,TempEnemy.y,true))
                    TempEnemy.y--;
                    vyT = 0;
    i want the arrow to start rotate down when it comes down to the ground with gravity...
    i tryd TempEnemy.rotation = TempEnemy.direction..
    this dosnt seem to work...

  • Javascript function to rotate an object around its axis

    Hello,
    I wonder if it is possible to rotate an object around its axis (eg 45 ° rotation)?
    I want to make this rotation with a button and a Javascript code!
    Is it possible? if so, have a track for me to start?
    thank you

    Possible, yes - but you will need some basic knowledge of how 3D matrix transformations work if you want to do anything complex.
    The code to rotate a node in a 3D scene by 45 degrees on the X axis is
    myNode.transform.rotateAboutXInPlace(Math.PI/4)

  • Why can't I select an object from its center?  Direct selecttool will only select bounding box.

    Why can't I select an object from its center?  Direct selecttool will only select bounding box.

    You may have turned on "Object selection by path only" in the "Selection Options".

  • How do I rotate a Button for example around its center in Flex 4.1 ?

    I know that there is autoCenterTransform or some propery like that in the transform effects but I don't want to use an effect, I just want the button rotated 180 degrees around it's center (I have left and right arrow and I don't want to make separate skins for them).
    Anyone?

    Maybe use a layout that isn't BasicLayout?
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark">
        <s:controlBarContent>
            <s:HSlider id="slider" minimum="0" maximum="360" />
        </s:controlBarContent>
        <s:layout>
            <s:HorizontalLayout />
        </s:layout>
        <s:Group>
            <s:Button id="btn" label="test" rotation="{slider.value}" transformX="{btn.width / 2}" transformY="{btn.height / 2}" />
        </s:Group>
        <s:VGroup>
            <s:Button id="btn2" label="test" rotation="{slider.value}" transformX="{btn2.width / 2}" transformY="{btn2.height / 2}" />
        </s:VGroup>
    </s:Application>

  • 3D Rotating on it's own center axis problem...

    Need some help here. This is my first time using 3D in flash.
    I have a movieclip (picture 80 x 80 pix) that I am tweening to look like it is rotating like face of a cube.
    What I did:
    1. I transformed the z-axis to "raise" the picture off of the y axis.
    2. Then I rotated it around the y-axis from one end of my tween to the other.
    Looks great when I scroll through the movie clip's time line but (starts on right almost paper thing, rotates to center square, and continues to the left again paper thin) The problem is when I place it on the stage and preview the swf, it rotates around its own center point and not the offset y-axis.
    If I convert it to frame by frame animation, it works but I don't want to do that.
    Please advise someone.
    Thanks!

    Sorry if I don't' quite get it, but my other thread was about the movieclip defaulting to the stages coordinates. In this case my movieclip's animation is rotating around the symbols center point and not around the y-axis as I would like.
    I can move the transform the symbol from axis point to another and it is fine but in this case i am only rotating it but after I placed is away from the y-axies. I expect it to "orbit" around the y axis continually facing it...and it does when I move through the tweaned frames, but when I publish the swf, it no longer "orbits" around the y-axis but rather just spins around it's center point.
    I hope this is a little clearer, and thanks for your other answer. I'll plug that code in as soon as I can.

  • Mac pro monitor has a shadow in its center. Does anybody know what can cause that?

    Last day my mac pro showed a shadow in its display center. Does anybody know what can cause?
    I use to use it a litle, cause i'm new on macs and still use pc based on windows.

      Who made the monitor?  Is it even Apple?
      If you have the right connections, try swapping out the monitor with your PeeCee monitor and see if the problems stays or goes.   But does sound like a monitor issue.  But then, hard to know what you mean by shadow...

  • Rotate view tool over mouse center?

    Hello all!
    As the subject states - is there a way to use rotate view tool so that it's center of rotation is on the mouse / cursor location?
    I have tried different key command combinations and no go. If this is not possible at this point, then I would love to have that as a feature! It would be SO much more efficient and much less frustrating.
    I hate having the rotation center in the center of the window rather than where I am painting. Now, if there is an option to do this somewhere then please disregard my rant.
    Thanks
    Ray

    No, I don't mean that you wouldn't be using a mouse to do so- of course, you would be using the mouse. I am just simply saying that when you rotate the image using the rotate view tool, it doesn't spin the canvas around the point of the mouse, it spin's it as you said around the image window's center. That's all I'm saying.
    To me it would be much faster if it were to have an option to spin around the mouse's center because, as I mentioned before, try working on a zoomed in corner of your image and then when zoomed in and in that corner of the document, use the rotate view tool, because you want to get a better angle for painting in that corner area of the zoomed in image. Spin the image 45 deg and see what happens.
    The area you were just working on is now totally out of view and you either zoom out to find the area again and pan back to center that location and zoom back in to continue working on it or pan around to find and center it again. Either way, that stinks in comparison to just rotate the view based on either your last mouse click or where you mouse is at the moment.
    Do you understand?

  • How can i rotate an image by a pivot point?

    Hello,
    i have a problem, the Imaq Rotate VI only rotate an image by its center. My problem is i need to do this by a known pivot point. How can i achieve this?
    Thank you,
    Francesco.
    Solved!
    Go to Solution.

    can this post help?
    http://forums.ni.com/t5/LabVIEW/Rotate-an-Image-by-specified-pixel/td-p/2570453
    Thanks
    uday,
    Please Mark the solution as accepted if your problem is solved and help author by clicking on kudoes
    Certified LabVIEW Associate Developer (CLAD) Using LV13

  • How to rotate an ellipse

    How would I change this code (shamelessly taken from one of DrLaszloJamf's posts) to rotate the ellipse around its center, I need an image with several ellipses at several different angles.
    import java.awt.*;
    import java.awt.image.*;
    import javax.swing.*;
    import java.io.*;
    import javax.imageio.ImageIO;
    public class BW
    public static void main(String[] args) throws IOException
    byte[] two = {0, (byte)0xff};
    ColorModel cm = new IndexColorModel(1, 2, two, two, two);
    WritableRaster raster = cm.createCompatibleWritableRaster(650, 100);
    BufferedImage image = new BufferedImage(cm, raster, false, null);
    Graphics2D g = image.createGraphics();
    g.setColor(Color.WHITE);
    g.fillArc(200, 10, 60, 30, 45, 360);
    g.dispose();
    ImageIO.write(image,"png",(new File("output.png")));

    You need to use java.awt.geom.AffineTransform, either directly or through the transform that the Graphics2D
    object has.
    Here is a simple example that animates using rotation.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import javax.swing.*;
    public class RotatingShape extends JPanel {
         private Shape shape;
         private double angle;
         private Timer timer = new Timer(500, new ActionListener(){
              public void actionPerformed(ActionEvent evt) {
                   angle += Math.PI/50;
                   repaint();
         //rotates shape around its origin, which is placed in center of component
         public RotatingShape(Shape shape) {
              this.shape = shape;
              timer.start();
         protected void paintComponent(Graphics g) {
              super.paintComponent(g);
              Insets insets = getInsets();
              int w = getWidth() - insets.left - insets.right;
              int h = getHeight() -insets.top  - insets.bottom;
              Graphics2D g2 = (Graphics2D) g.create(insets.left, insets.top, w, h);
              g2.setColor(getForeground());
              g2.translate(w/2.0, h/2.0);
              g2.rotate(angle);
              g2.setStroke(new BasicStroke(3));
              g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
              g2.draw(shape);
         public static void main(String[] args) {
              Shape shape = new Ellipse2D.Float(-100, -200, 200, 400);
              JComponent comp = new RotatingShape(shape);
              comp.setBackground(Color.BLACK);
              comp.setForeground(Color.GREEN);
              comp.setPreferredSize(new Dimension(450, 450));
              JFrame f = new JFrame("RotatingShape");
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              f.getContentPane().add(comp);
              f.pack();
              f.setLocationRelativeTo(null);
              f.setVisible(true);
    }

  • Rotate an Image by specified pixel

    Imaq Rotate.vi is to rotate an image around its center point (correct?).
    I need to rotate an image by a user-specified point in the image. What I have in mind is to expand the original image so that the specified point becomes the center of the new image, rotate this new image, and trim the image back to its original size. Is this the right way to do it? Or I am making it too complicated?

    All right. First, do you want your "selected point" to have the same absolute coordinates in your new image as in the original? If yes, keep reading. If no, all that follows is irrelevant.
    In the following discussion, you need to bear in mind that I have not used NI Vision stuff, but the Vision functions seem to be very straightforward.  It seems NI has made it easy for you.
    The first thing you have to do is determine the X,Y coordinates of the point you want to rotate around ("selected point"). I'll leave that to you, since you've got to pick a point somehow.
    From the dimensions of the image, the coordinates of your point, and the angle you want to rotate your image through, calculate the X,Y vector that you will "move" your "selected point" along your coordinate system if you do a simple rotation.
    From the Image Manipulation subpalette of the Vision Utilities palette, use the IMAQ Rotate function to rotate your image hawever far you want.
    From the same subpalette, use the IMAQ Shift function to translate the entire image back along the vector you determined 2 steps ago to put the "selected point" back where it was originally.
    If that doesn't do it, it's probably impossible .
    I don't know how to break it down any better than that.
    Cameron
    To err is human, but to really foul it up requires a computer.
    The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
    Profanity is the one language all programmers know best.
    An expert is someone who has made all the possible mistakes.
    To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):
    LabVIEW Unit 1 - Getting Started
    Learn to Use LabVIEW with MyDAQ

  • Polygon2D.Float

    I created this Polygon class. I've already tested it and it works just like java.awt.Polygon. This class
    supports floating point coordinates. It does not extend Polygon in java.awt. Enjoy
    import java.awt.*;
    import java.awt.geom.*;
    * This is a polygon that supports floating point values.  It does <b> not </b> extend java.awt.Polygon.  A polygon is comprised
    * of an array of x values and an array of it's corrisponding y values.  There is also an integer value - npoints - that determine
    * the number of points you want to be valid.  The polygon starts at xpoints[0] and ypoints[0] (if it exists) and connects a line
    * to xpoints[1] and ypoints[1] and then to xpoints[2] and ypoints[2] and so on until the index equals npoints.  The path is then
    * closed back to xpoints[0] and ypoints[0].  Lets see an example:
    * <p>
    * Polygon2D.Float p = new Polygon2D.Float( new float[] {20,20,40,40}, new float[] {20,40,40,20}, npoints);  //constructs a new new rectangle that is a polygon <br>
    * graphics.fill(p);  // fills a rectangle <br>
    * p.npoints = 3;  // the polygon now ignores the fourth coordinate <br>
    * graphics.fill(p);  // fills a triangle <br>
    * p.npoints = 2; // the polygon now ignores the last two coordinates <br>
    * graphic.fill(p); // does nothing - cannot fill a line (does update the polygon) <br>
    * graphic.draw(p); // draws a line; <br>
    * p.npoints = 5; //not allowed, but no error yet. <br>
    * try{graphic.draw(p)}catch(Exception e) {}// error - IndexOutOfBoundsException <br>
    * p.npoints = 4; <br>
    * p.xpoints[0] = 10; p.ypoints[0] = 10;  // makes it a weard looking rectangle; <br>
    * Rectangle bounds = p.getBounds(); //the bounds is <b> incorrect </b>.  It is the bounds of when p.npoints was set to 2. <br>
    * boolean contains = p.contains(30, 30); //will return false.  Should return true.  The shape is still set to when the p.npoins = 2 <br>
    * p.invalidate(); //updates the the polygon <br>
    * Rectangle bounds = p.getBounds(); //returns the correct bounds <br>
    * boolean contains = p.contains(30, 30); //returns true <br>
    * <p>
    * If the polygon dosen't draw right make sure that your coordinates and npoints are right.  The polygon does not update itself
    * by virtue of changing its coordinates directly or using the translate(float deltaX, float deltaY) method.  The polygon <b> is </b>
    * updated just before every draw (when the getPathIterator(AffineTransform at) method is called).  This has several implications.
    * All the contains, intersects, and getBounds methods go off the state the polygon was after its <b> last </b> update.  So if any of
    * these methods are called after you have manipulated the polygon and before you have redrawn it, then these specific methods return innacurate
    * results, becuase the polygon has not been updated yet.  If such a case occurs, call the invalidate() method to update the polygon forcibly.
    * The documentation for the methods of Polygon2D are coppied straight out of java.awt.Shape.
    * @author Christopher Colon
    * @version 1.0
    public abstract class Polygon2D implements Shape
        protected GeneralPath path;
        public Polygon2D()
           path = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
        /**Call this method after you are done with direct manipulation of the x and y points (including translate) and if you plan
         * to use any of the contains, intersects, or get bounds methods right after the
         * manipulation.  In effect this method 'updates' the polygon to its position and shape.  The polygon is always updated
         * just before drawing, so if you use any of the contains, intersects, or get bounds method
         * right after drawing and before manipulation, then these methods return accurate results.
         * Its in the period between manipulation and drawing that this method should be called if you
         * plan to use the other methods (excluding translate) before drawing.  */
        public abstract void invalidate();
        /**Tests if the specified coordinates are inside the boundary of the Shape.
         * @param x - the specified x coordinate
         * @param y - the specified y coordinate
         * @return true if the specified coordinates are inside the Shape boundary; false otherwise.*/
        public boolean contains(double x, double y)
            {return path.contains(x, y);}
        /**Tests if the interior of the Shape entirely contains the specified rectangular area. All coordinates that lie inside the rectangular area must lie within the Shape for the entire rectanglar area to be considered contained within the Shape.
         * This method might conservatively return false when: <br>
         * <p>
         * the intersect method returns true and <br>
         * the calculations to determine whether or not the Shape entirely contains the rectangular area are prohibitively expensive. <br>
         * <p>
         * This means that this method might return false even though the Shape contains the rectangular area.
         * The Area class can be used to perform more accurate computations of geometric intersection for any Shape
         * object if a more precise answer is required.
         * @param x - the x coordinate of the specified rectangular area
         * @param y - the y coordinate of the specified rectangular area
         * @param w - the width of the specified rectangular area
         * @param h - the height of the specified rectangular area
         * @return true if the interior of the Shape entirely contains the specified rectangular area; false otherwise or, if the Shape
         *          contains the rectangular area and the intersects method returns true and the containment calculations would be too
         *          expensive to perform.*/
        public boolean contains(double x, double y, double w, double h)
            {return path.contains(x,y,w,h);}
        /**Tests if a specified Point2D is inside the boundary of the Shape.
         * @param p - a specified Point2D
         * @return true if the specified Point2D is inside the boundary of the Shape; false otherwise.*/   
        public boolean contains(Point2D p)
            {return path.contains(p);}
        /**Tests if the interior of the Shape entirely contains the specified rectangular area. All coordinates that lie inside the rectangular area must lie within the Shape for the entire rectanglar area to be considered contained within the Shape.
         * This method might conservatively return false when: <br>
         * <p>
         * the intersect method returns true and <br>
         * the calculations to determine whether or not the Shape entirely contains the rectangular area are prohibitively expensive. <br>
         * <p>
         * This means that this method might return false even though the Shape contains the rectangular area.
         * The Area class can be used to perform more accurate computations of geometric intersection for any Shape
         * object if a more precise answer is required.
         * @param r - The specified Rectangle2D
         * @return true if the interior of the Shape entirely contains the specified rectangular area; false otherwise or, if the Shape
         *          contains the rectangular area and the intersects method returns true and the containment calculations would be too
         *          expensive to perform.*/
        public boolean contains(Rectangle2D r)
            {return path.contains(r);}
        /**Returns an integer Rectangle that completely encloses the Shape. Note that there is no guarantee that the returned Rectangle is
         * the smallest bounding box that encloses the Shape, only that the Shape lies entirely within the indicated Rectangle.
         * The returned Rectangle might also fail to completely enclose the Shape if the Shape overflows the limited range of the integer
         * data type. The getBounds2D method generally returns a tighter bounding box due to its greater flexibility in representation.
         * @return an integer Rectangle that completely encloses the Shape.*/
        public Rectangle getBounds()
            {return path.getBounds();}
        /**Returns a high precision and more accurate bounding box of the Shape than the getBounds method. Note that there is no
         * guarantee that the returned Rectangle2D is the smallest bounding box that encloses the Shape, only that the Shape lies
         * entirely within the indicated Rectangle2D. The bounding box returned by this method is usually tighter than that returned by
         * the getBounds method and never fails due to overflow problems since the return value can be an instance of the Rectangle2D that
         * uses double precision values to store the dimensions.
         * @return an instance of Rectangle2D that is a high-precision bounding box of the Shape.*/
        public Rectangle2D getBounds2D()
            {return path.getBounds2D();}
        /**Returns an iterator object that iterates along the Shape boundary and provides access to the geometry of the Shape outline.
         * If an optional AffineTransform is specified, the coordinates returned in the iteration are transformed accordingly.
         * Each call to this method returns a fresh PathIterator object that traverses the geometry of the Shape object independently
         * from any other PathIterator objects in use at the same time.
         * It is recommended, but not guaranteed, that objects implementing the Shape interface
         * isolate iterations that are in process from any changes that might occur to the original object's geometry during such iterations.
         * Before using a particular implementation of the Shape interface in more than one thread simultaneously, refer
         * to its documentation to verify that it guarantees that iterations are isolated from modifications.
         * @param at - an optional AffineTransform to be applied to the coordinates as they are returned in the iteration,
         *              or null if untransformed coordinates are desired
         * @return a new PathIterator object, which independently traverses the geometry of the Shape.*/  
        public abstract PathIterator getPathIterator(AffineTransform at);
         /**Returns an iterator object that iterates along the Shape boundary and provides access to a flattened view of the Shape
          * outline geometry. Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE point types are returned by the iterator.
          * If an optional AffineTransform is specified, the coordinates returned in the iteration are transformed accordingly.
          * The amount of subdivision of the curved segments is controlled by the flatness parameter, which specifies the maximum
          * distance that any point on the unflattened transformed curve can deviate from the returned flattened path segments.
          * Note that a limit on the accuracy of the flattened path might be silently imposed, causing very small flattening parameters
          * to be treated as larger values. This limit, if there is one, is defined by the particular implementation that is used.
          * Each call to this method returns a fresh PathIterator object that traverses the Shape object geometry independently
          * from any other PathIterator objects in use at the same time. It is recommended, but not guaranteed, that objects implementing
          * the Shape interface isolate iterations that are in process from any changes that might occur to the original object's geometry
          * during such iterations. Before using a particular implementation of this interface in more than one thread simultaneously,
          * refer to its documentation to verify that it guarantees that iterations are isolated from modifications.
          * @param at - an optional AffineTransform to be applied to the coordinates as they are returned in the iteration, or
          *              null if untransformed coordinates are desired
          * @param flatness - the maximum distance that the line segments used to approximate the curved segments are
          *                      allowed to deviate from any point on the original curve
          * @return a new PathIterator that independently traverses the Shape geometry.*/
        public abstract PathIterator getPathIterator(AffineTransform at, double flatness);
        /** Tests if the interior of the Shape intersects the interior of a specified rectangular area. The rectangular area is
         * considered to intersect the Shape if any point is contained in both the interior of the Shape and the specified rectangular area.
         * This method might conservatively return true when: <br>
         * there is a high probability that the rectangular area and the Shape intersect, but  <br>
         * the calculations to accurately determine this intersection are prohibitively expensive. <br>
         * This means that this method might return true even though the rectangular area does not intersect the Shape. <br>
         * The Area class can be used to perform more accurate computations of geometric intersection for any Shape object if a more
         * precise answer is required.
         * @param x - the x coordinate of the specified rectangular area
         * @param y - the y coordinate of the specified rectangular area
         * @param w - the width of the specified rectangular area
         * @param h - the height of the specified rectangular area
         * @return true if the interior of the Shape and the interior of the rectangular area intersect, or are
         *         both highly likely to intersect and intersection calculations would be too expensive to perform; false otherwise.*/
        public boolean intersects(double x, double y, double w, double h)
            {return path.intersects(x, y, w, h);}
        /**Tests if the interior of the Shape intersects the interior of a specified Rectangle2D.
         * This method might conservatively return true when: <br>
         * there is a high probability that the Rectangle2D and the Shape intersect, but <br>
         * the calculations to accurately determine this intersection are prohibitively expensive. <br>
         * This means that this method might return true even though the Rectangle2D does not intersect the Shape.
         * @param r - the specified Rectangle2D
         * @return true if the interior of the Shape and the interior of the specified Rectangle2D intersect, or are both
         *         highly likely to intersect and intersection calculations would be too expensive to perform; false otherwise.*/
        public boolean intersects(Rectangle2D r)
            {return path.intersects(r);}
        public static class Float extends Polygon2D implements Cloneable
            public float xpoints[];
            public float ypoints[];
            public int npoints;
            /**Creates a new empty polygon. The array of xpoints and ypoints is set to a size of 4.  So long as npoints remain 0
             * then everthing is fine.  The addPoint(float x, float y) appends the coordinates to xpoints[npoints+1] and ypoints[npoints+1]
             * and then increments npoints.*/
            public Float()
                xpoints = new float[4];
                ypoints = new float[4];
                npoints = 0;
            /**Creates a new empty polygon. The array of xpoints and ypoints is set to a size of the expectedCapacity.  So long as npoints remain 0
             * then everthing is fine.  The addPoint(float x, float y) appends the coordinates to xpoints[npoints+1] and ypoints[npoints+1]
             * and then increments npoints.
             * @throws NegativeArraySizeException If expectedCapacity < 0*/
            public Float(int expectedCapacity)
                if(expectedCapacity < 0) throw new NegativeArraySizeException("negative array size");
                xpoints = new float[expectedCapacity];
                ypoints = new float[expectedCapacity];
                npoints = 0;
            /**Creates a new polygon that represent the given specifications.*/
            public Float(float[] x, float[] y, int npoints)
                if(npoints < 0) throw new NegativeArraySizeException("negative amount of sides (npoints < 0)");
                if(npoints > x.length || npoints > y.length) throw new IndexOutOfBoundsException("more sides than points");
                if(x == null || y == null) throw new NullPointerException("null array of points");
                this.xpoints = x;
                this.ypoints = y;
                this.npoints = npoints;
                constructPath();
            /**Creates a new polygon that represent the given specifications.  The integers are coppied over as float values.*/
            public Float(int[] x, int[] y, int npoints)
                if(npoints < 0) throw new NegativeArraySizeException("negative amount of sides (npoints < 0)");
                if(npoints > x.length || npoints > y.length) throw new IndexOutOfBoundsException("more sides than points");
                if(x == null || y == null) throw new NullPointerException("null array of points");
                xpoints = new float[x.length];
                for(int index = 0; index < x.length; index++) xpoints[index] = x[index];
                ypoints = new float[y.length];
                for(int index = 0; index < y.length; index++) ypoints[index] = y[index];
                this.npoints = npoints;
                constructPath();           
           /*Updates the polygon.*/    
           private synchronized void constructPath()
                if(npoints < 0) throw new NegativeArraySizeException("negative amound of sides (nPoints < 0)");
                path.reset();
                if(xpoints.length == 0 || ypoints.length == 0) return;
                path.moveTo(xpoints[0], ypoints[0]);
                for(int index = 0; index < npoints; index++)
                    path.lineTo(xpoints[index],ypoints[index]);
                path.closePath();
            /**The addPoint(float x, float y) appends the coordinates to xpoints[npoints+1] and ypoints[npoints+1]
             * and then increments npoints.*/
            public synchronized void addPoint(float x, float y)
                if(xpoints.length == npoints)
                    float[] temp = new float[xpoints.length+1];
                    for(int index = 0; index < xpoints.length; index++) temp[index] = xpoints[index];
                    xpoints = temp;
                if(ypoints.length == npoints)
                    float[] temp = new float[ypoints.length+1];
                    for(int index = 0; index < ypoints.length; index++) temp[index] = ypoints[index];
                    ypoints = temp;
                xpoints[npoints+1] = x;
                ypoints[npoints+1] = y;
                npoints++;
            /**Rotate the polygon by the specified amount of degrees around the specified pivot point. It is entirly possible
             * that the polygon could shrink a little or grow a little, after repeated calls to this method.  This is due to
             * rounding errors (double to float).  If the polygon shrinks a little, it will expand a little the next time and vise versa. 
             * The net result is that the polygon is always within 5 (just an estimate) pixels of the intended polygon rotation. So
             * the polygon will never expand too much or shrink too much.  In general the greatest shrinkage or expansion occurs
             * when the polygon is rotated about its center.*/
            public void rotate(double deltaTheta, double pivotX, double pivotY)
                while(deltaTheta >= 360) deltaTheta -= 360;
                while(deltaTheta < 0) deltaTheta += 360;
                for(int index = 0; index < npoints; index++)
                    if(xpoints[index] == pivotX && ypoints[index] == pivotY) continue;
                    double distance = Point.distance(xpoints[index], ypoints[index], pivotX, pivotY);
                    double angle = Math.atan( -(ypoints[index] - pivotY) / (xpoints[index] - pivotX) );
                    if((xpoints[index] - pivotX) < 0) angle += Math.PI;
                    angle += Math.toRadians(deltaTheta);
                    xpoints[index] = (float) (Math.cos(angle) * distance + pivotX);
                    ypoints[index] = (float) (-Math.sin(angle) * distance + pivotY);
            /**Rotate the polygon about its center by the specified amount of degrees.  This is the equivalent of calling
             * rotate(deltaTheta, (float) getXMid(), (float) getYMid()).*/
            public void rotate(double deltaTheta)
                rotate(deltaTheta, getXMid(), getYMid());
            /**Resize the polygon by the specified factor.  A factor of 1 will not change the polygon.
             * A factor greater than 1 will make the polygon grow.  A factor between 0 and 1 will make the polygon shrink.
             * The polygon shrinks towards its center or grows away from its center.
             * @throws IllegalArgumentException if the factor is less than 0.*/
            public void resize(double factor)
                if(factor < 0) throw new IllegalArgumentException("illegal factor");
                if(factor == 1) return;
                double xMid = getXMid();
                double yMid = getYMid();
                for(int index = 0; index < npoints; index++)
                    xpoints[index] = (float) (((xpoints[index] - xMid) * factor) + xMid);
                    ypoints[index] = (float) (((ypoints[index] - yMid) * factor) + yMid);
            /**Returns the x coordinate of the mid point (center) of this polygon.*/
            public double getXMid()
                double sum = 0;
                for(int index = 0; index < npoints; index++) sum += xpoints[index];
                return sum / npoints;
            /**Returns the y coordinate of the mid point (center) of this polygon.*/
            public double getYMid()
                double sum = 0;
                for(int index = 0; index < npoints; index++) sum += ypoints[index];
                return sum / npoints;
            /**Resets this polygon to an empty polygon.*/
            public synchronized void reset()
                xpoints = new float[xpoints.length];
                ypoints = new float[ypoints.length];
                npoints = 0;
             /**Translates the polygon by the specified x and y amounts.  The polygon is not updated
              * after the transformation.*/
            public void translate(float deltaX, float deltaY)
                for(int index = 0; index < xpoints.length; index++) xpoints[index] += deltaX;
                for(int index = 0; index < ypoints.length; index++) ypoints[index] += deltaY;
            public void invalidate()
                 {constructPath();}
            public PathIterator getPathIterator(AffineTransform at)
            {   constructPath();
                return path.getPathIterator(at);}
            public PathIterator getPathIterator(AffineTransform at, double flatness)
            {   constructPath();
                return path.getPathIterator(at, flatness);}
            /**Returns a polygon with the same shape and points.*/
            public Object clone()
                return new Polygon2D.Float(xpoints, ypoints, npoints);
    }

    I assume the reason you posted your code is because you want feedback. The GeneralPath class does not allow the points to be changed (or even looked at) once an operation has been performed. If that is the problem you were facing, then I probably would recommend using the GeneralPath class as a guideline to implement your new class on. I don't see the need to wrap the "Float" class inside the Polygon2D class. The fact that Polygon2D.Float is a container of points is not very clear by the name. Lastly, it looks like everytime you add a point, you will have to call invalidate() to update the internal storage. That is somewhat inefficient, and probably more confusing than anything. For your clone method, I would recommend doing a deep copy.

  • Best way to transform a jigsaw puzzle to landscape

    Hello,
    I am trying to puppet warp a big square that looks like a complete jigsaw puzzle and warp it to a rolling hill landscape. What befuddles me is how to rotate the plane around its center? Another words, if I put a skewer into the middle of the plane or puzzle, and take the corner and rotate it around that axis or the in 3D talk it would be the y axis. Every place I put the axis poin and rotate the plane, it rotates in the z axis, or around like a clock. So, to clarify, if I could put my palm down onto teh center of this plane, and with the other hand, take the corner of this plane and spin it around a bit, how could I do this move in Photoshop?
    Do I just continue to warp it so it has that appearance, or can I rotate it as shown in my image?? I just want the perspective to be more like the puzzle is coming out of the lower right corner and extending out to the top left corner perspective. instead of cming from the bottom and out to background as it is here. Thank you.
    Laurie

    Why don't you use info objects? For example your table is having col1(number),col2(text/varchar),col3(text/varchar), create an info object like this,
    class MytableInfo implements java.io.Serializable {
    private int col1;
    private String col2;
    private String col3;
    public MytableInfo(int col1,String col2,String col3) {
    this.col1=col1;
    this.col2=col2;
    this.col3=col3;
    public int getCol1() {
    return col1;
    //Getter for other two properties too.
    and in your ResultSet class,
    Vector v = new Vector();
    while(rs.next()) v.add(new MytableInfo(rs.getInt(1),rs.getString(2),rs.getString(3));
    return v;
    So, it will be easier for retrieving the values later and it is a clean way of doing it.
    Sudha

  • Bitmap Rotation According to Mouse Position?

    Hi,
    I am working on a 2d computer graphics project, and I need a good function to rotate a Bitmap 360 degree according to my mouse position.
    for example: 

    Hi,
    I am working on a 2d computer graphics project, and I need a good function to rotate a Bitmap 360 degree according to my mouse position.
    for example: 
    Hello,
    To rotate that image, we need to deal with the following tips.
    1. The image size.
    If the area for that image rotated is not big enough, it will just lose some parts of that image.
    Here is a nice code shared in this thread
    http://stackoverflow.com/questions/5199205/how-do-i-rotate-image-then-move-to-the-top-left-0-0-without-cutting-off-the-imag/5200280#5200280.
    private Bitmap RotateImage(Bitmap b, float Angle)
    // The original bitmap needs to be drawn onto a new bitmap which will probably be bigger
    // because the corners of the original will move outside the original rectangle.
    // An easy way (OK slightly 'brute force') is to calculate the new bounding box is to calculate the positions of the
    // corners after rotation and get the difference between the maximum and minimum x and y coordinates.
    float wOver2 = b.Width / 2.0f;
    float hOver2 = b.Height / 2.0f;
    float radians = -(float)(Angle / 180.0 * Math.PI);
    // Get the coordinates of the corners, taking the origin to be the centre of the bitmap.
    PointF[] corners = new PointF[]{
    new PointF(-wOver2, -hOver2),
    new PointF(+wOver2, -hOver2),
    new PointF(+wOver2, +hOver2),
    new PointF(-wOver2, +hOver2)
    for (int i = 0; i < 4; i++)
    PointF p = corners[i];
    PointF newP = new PointF((float)(p.X * Math.Cos(radians) - p.Y * Math.Sin(radians)), (float)(p.X * Math.Sin(radians) + p.Y * Math.Cos(radians)));
    corners[i] = newP;
    // Find the min and max x and y coordinates.
    float minX = corners[0].X;
    float maxX = minX;
    float minY = corners[0].Y;
    float maxY = minY;
    for (int i = 1; i < 4; i++)
    PointF p = corners[i];
    minX = Math.Min(minX, p.X);
    maxX = Math.Max(maxX, p.X);
    minY = Math.Min(minY, p.Y);
    maxY = Math.Max(maxY, p.Y);
    // Get the size of the new bitmap.
    SizeF newSize = new SizeF(maxX - minX, maxY - minY);
    // ...and create it.
    Bitmap returnBitmap = new Bitmap((int)Math.Ceiling(newSize.Width), (int)Math.Ceiling(newSize.Height));
    // Now draw the old bitmap on it.
    using (Graphics g = Graphics.FromImage(returnBitmap))
    g.TranslateTransform(newSize.Width / 2.0f, newSize.Height / 2.0f);
    g.RotateTransform(Angle);
    g.TranslateTransform(-b.Width / 2.0f, -b.Height / 2.0f);
    g.DrawImage(b, 0, 0);
    return returnBitmap;
    2. The location of that control which displays that image.
    If we use a picturebox, and set its sizemode to autosize like the following line, then if you just want to rotate that image to show, and you don't want to that affects the original image, then we need to keep its center point.
    this.pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
    We could add resize event handler after we set image for that picturebox.
            Point pOrign;
            Size sOrign;private void Form1_Load(object sender, EventArgs e)
    this.pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
    Image img = Image.FromFile(@"D:\Documents\New folder\New folder\TestImage.PNG");
    this.pictureBox1.Image = img;
    this.pictureBox1.InitialImage = img;
    pOrign = new Point(this.pictureBox1.Left , this.pictureBox1.Top );
    sOrign = new Size(this.pictureBox1.Width, this.pictureBox1.Height);
    this.pictureBox1.BorderStyle = BorderStyle.FixedSingle;
    this.pictureBox1.Resize += pictureBox1_Resize;
    private void pictureBox1_Resize(object sender, EventArgs e)
    this.pictureBox1.Left = this.pOrign.X + (this.sOrign.Width - this.pictureBox1.Width) / 2;
    this.pictureBox1.Top = this.pOrign.Y + (this.sOrign.Height - this.pictureBox1.Height) / 2;
    3. The angle between that center point and your mouse postion.
    We could get that value inside the picturebox's container's mouse_move event.
    Double angleNew ; private void pictureBoxContainer_MouseMove(object sender, MouseEventArgs e)
    angleNew = Math.Atan2(this.pOrign.Y + this.sOrign.Height / 2 - e.Y, this.pOrign.X + this.sOrign.Width/2 - e.X) * 180.0 / Math.PI;
    But when to start rotate that image, it should be your chooice, and you could decide when rotate that image with the following line.
    this.pictureBox1.Image = (Image)RotateImage(new Bitmap(this.pictureBox1.InitialImage), (float)angleNew);
    If you just want to save that change to that image, then you could save that bitmap to file directly.
    Happy new year.
    Regards.
    Carl
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

Maybe you are looking for

  • Session Timeout - Process as a webservice

    Hi , I am using ALBPM v5.7. In this we are exposing our process as webservice. We are Invoking these webservice methods from portal deployed in BEA Weblogic Server, The procedure we are following is , starting the session and then invoking our method

  • Apple ID for app purchases

    My iPad used to ask for an ID before purchasing apps or in app purchases. Now after I buy one thing other apps can be added without my ID. Young kids play on this iPad and I have to make it Impossible for them to make purchases.  I don't know how to

  • Which oracle forms and reports should be installed on oracle 9i on redhat9

    i have installed oracle 9i database on red hat 9 kernel 2.4.20 now i want to use oracle forms and reports. so these are my questions 1) which version of forms and reports to use where to get those 2) how to install and get working 3) i already tried

  • Payments against plant maintenance order

    hello guys, I need to derive payments (to vendors) against plant maintenace order. Which ds should I select?

  • Idoc CRMXIF_CMSCON_SAVE_M01

    Hi everyone, Has someone used the idoc CRMXIF_CMSCON_SAVE_M01 to create a business transaction in CRM ? Or any other idoc to created a business transaction in CRM ? Or how do you create transaction in CRM with data coming for an non R/3 system ? Any