Rotation (math ignorance?) problem

Hi all.
I am not new to Java or Java3D but I am not very good with 3D math. I have a problem that has been a thorn in my side longer than I can remember and I am hoping someone here can help.
I have created a simple program (dozens of times) that just puts a colorCube on the screen. I use a Transform3D to rotate the viewPlatform (or the whole world scene graph) and I can do this with no problem. All things move as one would expect, but here is the problem;
If I rotate with the mouse (or keyboard, same effect) in a circle, the entire scene will eventually turn upside down. I realize this is an expected side effect of the rotation matrix but how do I correct for this?
Do I need to negate the Z axis rotation by brute force?
something like:
rotateCamera()
    old_z = getCurrentZ();
    camera.rotate();
    camera.setZ(old_z);
}TIA,
RT

Thanks for the quickly answer.
Let me make sure we are speaking about the same thing for my benefit. With the Y axis being vertical, X axis being horizontal, and the Z axis directly in front of the "camera".
Only spinning on the Z axis can produce a picture of the colorCube that is "upside-down" and still in the frame if I spin 180deg.
The problem is if I move the mouse (which moves the camera) in small circles, say clockwise, if the colorCube never leaves the frame, I end up with an inverted view of the world.
I know this is hard to visualize so I made an HTML page to help anyone who is interested at http://radzyn.mine.nu/3dprob/
Thanks again for the help.
RT

Similar Messages

  • Java rotate, drag RoundRectangle2D problem please help me!!!

    Hi,
    i have 2 program, the first program can rotate a RoundRectangle2D, and the secend program can create new RoundRectangle2D and drag them around.
    The problem is that i want the rotate and the drag functions in one file, could any wone plese help me with this??
    The code has been orginally written by phillips75. i have modified it.
    The first program that rotates a Rectangle2D
    package appli;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.util.*;
    import java.util.List;
    import javax.swing.*;
    import javax.swing.event.MouseInputAdapter;
    public class minappli extends JApplet
    Vector shape = new Vector();
    class axel extends JPanel
    axel selectedRect;
    //RoundRectangle2D r;
    RectangularShape r;
    RectangularShape rsss;
    AffineTransform xform;
    int theta;
    public axel()
    shape.addElement(new axel(40, 50, 50, 60));
    shape.addElement(new axel(150, 100, 50, 60));
    shape.addElement(new axel(40, 150, 50, 60));
    setBackground(Color.white);
    addMouseListener(new RectSelector(this));
    public axel (int x, int y, int w, int h)
    r = new RoundRectangle2D.Double(x, y, w, h, 20, 20);
    xform = new AffineTransform();
    theta = 0;
    public void drawdd (Graphics2D g2)
    AffineTransform orig = g2.getTransform();
    if (!xform.isIdentity())
    g2.setTransform(xform);
    g2.draw(r);
    g2.setTransform(orig);
    public void rotateRect()
    double cx = r.getCenterX();
    double cy = r.getCenterY();
    theta = theta + 5;
    xform.setToRotation(Math.toRadians(theta), cx, cy);
    public void paintComponent(Graphics g)
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D)g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    RenderingHints.VALUE_ANTIALIAS_ON);
    //int w = getWidth();
    //int h = getHeight();
    axel rs;
    for(int i = 0; i < shape.size(); i++)
    rs = (axel) shape.get(i);
    // System.out.println(" rs " + rs + " rsss " + konam);
    if (rs == selectedRect)
    g2.setPaint(Color.yellow);
    else
    g2.setPaint(Color.black);
    rs.drawdd(g2);
    class RectSelector extends MouseInputAdapter
    axel rotationPanel;
    RectangularShape selectedShape;
    axel rs;
    Point start, offset;
    boolean addCircle, addSquare, dragging;
    final int size = 50;
    public RectSelector(axel fp)
    rotationPanel = fp;
    offset = new Point();
    addCircle = false;
    addSquare = false;
    dragging = false;
    public void mousePressed(MouseEvent e)
    RectangularShape rssss = null;
    Point p = e.getPoint();
    rssss = new RoundRectangle2D.Double(p.x - size / 2, p.y - size / 2, size, size, 20, 20);
    for (int i = 0; i < shape.size(); i++)
    rs = (axel) shape.get(i);
    //System.out.println("rs" + rs);
    if (rs.r.contains(p))
    selectedRect = rs;
    repaint();
    break;
    public void mouseReleased(MouseEvent e)
    selectedShape = null;
    dragging = false;
    public void mouseDragged(MouseEvent e)
    if (dragging)
    Point p = e.getPoint();
    if (selectedShape != null)
    // dragging a shape
    Rectangle r = selectedShape.getBounds();
    r.x = p.x - offset.x;
    r.y = p.y - offset.y;
    selectedShape.setFrame(r);
    rotationPanel.repaint();
    public JPanel getUIpanelg()
    final JButton rotateButton = new JButton("Rotate");
    final JButton box = new JButton("Box");
    rotateButton.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
    if (e.getSource() == rotateButton)
    selectedRect.rotateRect();
    repaint();
    JPanel panel = new JPanel();
    panel.add(rotateButton);
    panel.add(box);
    return panel;
    public void init()
    axel rp = new axel();
    Container cp = getContentPane();
    cp.setLayout(new BorderLayout());
    cp.add(rp.getUIpanelg(), "South");
    cp.add(rp);
    public static void main(String[] args)
    JApplet applet = new minappli();
    JFrame f = new JFrame("Test");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(applet);
    f.setSize(400,300);
    f.setLocation(200,200);
    applet.init();
    f.setVisible(true);
    The second program that creates new Rectangle2D and drags it around
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.util.*;
    import java.util.List;
    import javax.swing.*;
    import javax.swing.event.*;
    public class axel extends JApplet
    Vector shape = new Vector();
    int theta;
    RoundRectangle2D r;
    AffineTransform xform;
    class axel1 extends JPanel
    axel1 selectedRect;
    RectSelector action;
    public axel1()
    //shape.addElement(new axel1(40, 50, 50, 60));
    //shapeList.addElement(new FlowPanel(150, 100, 50, 60));
    //shapeList.addElement(new FlowPanel(40, 150, 50, 60));
    setBackground(Color.white);
    action = new RectSelector(this);
    addMouseListener(action);
    addMouseMotionListener(action);
    public void drawdd (Graphics2D g2)
    AffineTransform orig = g2.getTransform();
    if (!xform.isIdentity())
    g2.setTransform(xform);
    g2.draw(r);
    g2.setTransform(orig);
    public axel1 (int x, int y, int w, int h)
    r = new RoundRectangle2D.Double(x, y, w, h, 20, 20);
    xform = new AffineTransform();
    theta = 0;
    public void rotateRect()
    double cx = r.getCenterX();
    double cy = r.getCenterY();
    System.out.println("fffffffffffff");
    theta = theta + 5;
    xform.setToRotation(Math.toRadians(theta), cx, cy);
    public void paintComponent(Graphics g)
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    RenderingHints.VALUE_ANTIALIAS_ON);
    RoundRectangle2D rs;
    for (int i = 0; i < shape.size(); i++)
    //rs = (RectangularShape) shape.get(i);
    g2.draw((RectangularShape) shape.get(i));
    //rs = (axel1) shape.get(i);
    //System.out.println("skapar " + i + "hahaaha " + rs);
    //if (rs == selectedRect)
    // g2.setPaint(Color.red);
    //else
    // g2.setPaint(Color.black);
    public void clear()
    shape.clear();
    repaint();
    class RectSelector extends MouseInputAdapter
    axel1 rotationPanel;
    RectangularShape selectedShape;
    final int size = 50;
    Point start, offset;
    boolean addCircle, addSquare, dragging;
    axel1 rs;
    public RectSelector(axel1 fp)
    // lista = (Vector) flowPanel.getShapeList();
    shape.addElement(new RoundRectangle2D.Double(40, 50, 50, 60, 20, 20));
    rotationPanel = fp;
    offset = new Point();
    addCircle = false;
    addSquare = false;
    dragging = false;
    public void mousePressed(MouseEvent e)
    RectangularShape rssss = null;
    Point p = e.getPoint();
    if (addCircle)
    rssss = new Ellipse2D.Double(p.x - size / 2, p.y - size / 2, size, size);
    if (addSquare)
    rssss = new RoundRectangle2D.Double(p.x - size / 2, p.y - size / 2, size, size, 20, 20);
    if (rssss != null)
    shape.addElement(rssss);
    rotationPanel.repaint();
    addCircle = addSquare = false;
    return;
    // or are we selecting an existing shape to drag
    for (int i = 0; i < shape.size(); i++)
    rssss = (RectangularShape) shape.get(i);
    if (rssss.contains(p))
    System.out.println("nu " + i + " " + rssss);
    selectedShape = rssss;
    Rectangle r = rssss.getBounds();
    offset.x = p.x - r.x;
    offset.y = p.y - r.y;
    dragging = true;
    break;
    public void mouseReleased(MouseEvent e)
    selectedShape = null;
    dragging = false;
    public void mouseDragged(MouseEvent e)
    if (dragging)
    Point p = e.getPoint();
    if (selectedShape != null)
    // dragging a shape
    Rectangle r = selectedShape.getBounds();
    r.x = p.x - offset.x;
    r.y = p.y - offset.y;
    selectedShape.setFrame(r);
    rotationPanel.repaint();
    public JToolBar getToolBar()
    JToolBar toolBar = new JToolBar();
    ActionListener l = new ActionListener()
    public void actionPerformed(ActionEvent e)
    JButton button = (JButton) e.getSource();
    String ac = button.getActionCommand();
    if (ac.equals("Single arrow"))
    addCircle = true;
    if (ac.equals("Box"))
    addSquare = true;
    if (ac.equals("Clear"))
    rotationPanel.clear();
    if (ac.equals("Rotate"))
    //double cx = r.getCenterX();
    //double cy = r.getCenterY();
    System.out.println("fffffffffffff");
    //theta = theta + 5;
    //xform.setToRotation(Math.toRadians(theta), cx, cy);
    // repaint();
    JButton button = makeButton("Single arrow", "Add a arrow", l);
    toolBar.add(button);
    button = makeButton("Box", "Add a box", l);
    toolBar.add(button);
    button = makeButton("Clear", "Clears everything", l);
    toolBar.add(button);
    button = makeButton("Rotate", "Rotate a shape", l);
    toolBar.add(button);
    return toolBar;
    private JButton makeButton(String actionCommand, String toolTipText, ActionListener l)
    JButton button = new JButton(actionCommand);
    button.setActionCommand(actionCommand);
    button.setToolTipText(toolTipText);
    button.addActionListener(l);
    return button;
    public void init()
    axel1 flowPanel = new axel1();
    RectSelector action = flowPanel.action;
    Container cp = getContentPane();
    cp.setLayout(new BorderLayout());
    cp.add(action.getToolBar(), "South");
    cp.add(flowPanel);
    public static void main(String[] args)
    JApplet applet = new axel();
    JFrame f = new JFrame("test");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(applet);
    f.setSize(500, 400);
    f.setLocation(200, 200);
    applet.init();
    f.setVisible(true);
    The

    New code:
    Class Arrow
    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class GraphicArrow  extends JComponent
        GeneralPath arrow   =  new GeneralPath();
        Stroke dashStroke   =  new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 10f, new float[] {4f, 4f}, 0f);
        Paint gradientPaint =  new GradientPaint(-30, 0, Color.red, 10, 0, Color.yellow);
        GraphicArrow selectedArrow;
        public void paintComponent(Graphics _g)
            super.paintComponent(_g);
            Graphics2D g2 = (Graphics2D) _g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                               RenderingHints.VALUE_ANTIALIAS_ON);
            AffineTransform graphicsDefaultTransform = g2.getTransform();
            AffineTransform xform = new AffineTransform();
            Rectangle bounds = arrow.getBounds();
            Point startPoint = new Point();
            xform.translate(startPoint.x - bounds.x, startPoint.y - bounds.y);
            //g2.transform(xform);
            //g2.setStroke(dashStroke);
            //g2.draw(arrow);
             //g2.setTransform(graphicsDefaultTransform);
            //g2.transform(xform);
            //g2.setPaint(gradientPaint);
            //g2.fill(arrow);
            xform.translate(bounds.width + 20, 0);
            xform.translate(bounds.width + 20, 0);
            //g2.setTransform(graphicsDefaultTransform);
            g2.setPaint(gradientPaint);
            g2.transform(xform);
            g2.rotate(Math.PI / 1);
            g2.fill(arrow);
        public GraphicArrow (int x, int y)
            //Value before -20, -10
            arrow.moveTo(x, y);
            arrow.lineTo(0, -10);
            arrow.lineTo(0, -20);
            arrow.lineTo(20, 0);
            arrow.lineTo(0, 20);
            arrow.lineTo(0, 10);
            arrow.lineTo(-20, 10);
            arrow.lineTo(-20, -10);
            addMouseListener(new MouseAdapter()
                Rectangle hitRect = new Rectangle(0, 0, 5, 5);
                public void mouseClicked(MouseEvent e)
                    Graphics2D g = (Graphics2D) getGraphics();
                    AffineTransform xform = new AffineTransform();
                    hitRect.x = e.getX();
                    hitRect.y = e.getY();
                    Rectangle bounds = arrow.getBounds();
                    Point startPoint = new Point();
                    //System.out.println("hh " + (bounds.x  ) );
                    xform.setToTranslation(startPoint.x - bounds.x + 2 * bounds.width + 2 * 20, startPoint.y - bounds.y);
                    xform.rotate(Math.PI / 1);
                    g.setTransform(xform);
                    if (g.hit(hitRect, arrow, false))
                        System.out.println("Traff " + xform);
        public static void main(String args[])
            Frame frame = new Frame("Arrow");
            frame.add(new GraphicArrow(0, 0));
            frame.setBackground(Color.white);
            frame.setSize(new Dimension(400, 350));
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
    }The shape class:
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.util.*;
    import java.util.List;
    import javax.swing.*;
    import javax.swing.event.MouseInputAdapter;
    import java.awt.*;
    public class Box extends JApplet
        Vector shape      = new Vector();
        Vector arrowArray = new Vector();
        int theta;
        class axel extends JPanel implements KeyListener
            GeneralPath arrow   = new GeneralPath();
            Stroke dashStroke   = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 10f, new float[] {10f, 10f}, 5f);
            Paint gradientPaint = new GradientPaint( -30, 0, Color.red, 10, 0, Color.yellow);
            boolean delete_box, addSquare, addArrow, dragging;
            axel selectedRect;
            RectangularShape boxen;
            AffineTransform xform;
            RectSelector action;
            String texten;
            public axel()
                shape.addElement(new axel("Text1", 40, 50, 50, 60));
                shape.addElement(new axel("Text2", 150, 100, 50, 60));
                shape.addElement(new axel("Text3", 40, 150, 50, 60));
                setBackground(Color.white);
                action = new RectSelector(this);
                addMouseListener(action);
                addMouseMotionListener(action);
                addKeyListener(this);
            public axel(String text, int x, int y, int w, int h)
                texten = text;
                boxen  = new RoundRectangle2D.Double(x, y, w, h, 20, 20);
                xform  = new AffineTransform();
                theta  = 5;
            public void rita(Graphics2D g2)
                double cx = boxen.getCenterX();
                double cy = boxen.getCenterY();
                int mus_x =(int) cx;
                int mus_y =(int) cy;
                AffineTransform orig = g2.getTransform();
                if (!xform.isIdentity())
                    g2.setTransform(xform);
                g2.fill(boxen);
                g2.setColor(Color.black);
                g2.setFont(new Font("Helvetica", Font.BOLD, 12));
                g2.drawString(texten, mus_x + -11, mus_y + 5);
                g2.draw(boxen);
                g2.setTransform(orig);
            public void paintComponent(Graphics g)
               super.paintComponent(g);
               Graphics2D g2 = (Graphics2D) g;
               Image bild = getImage(getDocumentBase(), "images.jpg");
               g2.drawImage(bild, 0, 0, this);
               g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                   RenderingHints.VALUE_ANTIALIAS_ON);
               //Draw the Shapes
               for (int i = 0; i < shape.size(); i++)
                   axel rsh = (axel) shape.get(i);
                   if (rsh == selectedRect)
                       g2.setStroke(dashStroke);
                       g2.setPaint(Color.green);
                   else
                       g2.setStroke(new BasicStroke(0));
                       g2.setPaint(Color.yellow);
                   rsh.rita(g2);
               //Draw the Arrows
               for (int i = 0; i < arrowArray.size(); i++)
                   GraphicArrow selectedArrow;
                   GraphicArrow arrowen = (GraphicArrow) arrowArray.get(i);
                   arrowen.paintComponent(g);
            public void resizen()
                Rectangle r      = boxen.getBounds();
                double    width  = boxen.getWidth()+2;
                double    height = boxen.getHeight()+2;
                boxen.setFrame(r.x, r.y, width, height);
            public void rotateRect()
                double cx = boxen.getCenterX();
                double cy = boxen.getCenterY();
                theta = theta - 5;
                xform.setToRotation(Math.toRadians(theta), cx, cy);
            public void rotateRect_right()
                double cx = boxen.getCenterX();
                double cy = boxen.getCenterY();
                theta = theta + 5;
                xform.setToRotation(Math.toRadians(theta), cx, cy);
            public void keyPressed(KeyEvent e) {
                System.out.println("Test1");
                if (e.isShiftDown()) {
                    System.out.println("Test3");
                if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                    System.out.println("Test2");
            public void keyReleased(KeyEvent e) {
            public void keyTyped(KeyEvent e) {
            class RectSelector extends MouseInputAdapter {
                axel rotationPanel;
                RectangularShape selectedShape;
                axel rs;
                Point offset;
                final int size = 50;
                public RectSelector(axel fp)
                    rotationPanel  = fp;
                    offset         = new Point();
                    delete_box     = false;
                    addSquare      = false;
                    addArrow       = false;
                    dragging       = false;
                public void mousePressed(MouseEvent e) {
                    Point p = e.getPoint();
                    //New Box skapas
                    if (addSquare)
                      shape.addElement(new axel("text5", p.x, p.y, 50, 60));
                      rotationPanel.repaint();
                      addSquare = false;
                      return;
                    //New Arrow skapas
                    if (addArrow)
                      arrowArray.addElement(new GraphicArrow(p.x, p.y));
                      rotationPanel.repaint();
                      addArrow = false;
                      return;
                    for (int i = 0; i < shape.size(); i++)
                        rs = (axel) shape.get(i);
                        if (rs.boxen.contains(p))
                            if (delete_box) {
                                shape.removeElementAt(i);
                                delete_box = false;
                                repaint();
                            Rectangle r = rs.boxen.getBounds();
                            offset.x = p.x - r.x;
                            offset.y = p.y - r.y;
                            selectedRect = rs;
                            selectedShape = rs.boxen;
                            dragging = true;
                            repaint();
                        //else
                        //    System.out.println("press does not work " + delete_box + i + rs.boxen.contains(p));
                public void mouseReleased(MouseEvent e)
                    int x = e.getX();
                    int y = e.getY();
                    selectedShape = null;
                    dragging = false;
                    setCursor(new Cursor(Cursor.DEFAULT_CURSOR) );
                    //Graphics2D g3  = (Graphics2D) getGraphics();
                    //g3.setStroke(new BasicStroke(0));
                    //g3.setPaint(Color.yellow);
                public void mouseDragged(MouseEvent e)
                    if (dragging) {
                        Point p = e.getPoint();
                        if (selectedShape != null) {
                            setCursor(new Cursor(Cursor.MOVE_CURSOR) );
                            Rectangle r = selectedShape.getBounds();
                            System.out.println("dragging " + p + p.x + " " + p.y);
                            r.x = p.x - offset.x;
                            r.y = p.y - offset.y;
                            selectedShape.setFrame(r);
                            repaint();
                public void mouseMoved(MouseEvent e)
            public JPanel panelen()
                final JButton rotate_left  = new JButton("Rotate left");
                final JButton rotate_right = new JButton("Rotate right");
                final JButton arrow        = new JButton("New Arrow");
                final JButton box          = new JButton("New Box");
                final JButton delete       = new JButton("Delete");
                final JButton resize       = new JButton("Resize");
                rotate_left.setCursor(new Cursor(Cursor.HAND_CURSOR) );
                rotate_right.setCursor(new Cursor(Cursor.HAND_CURSOR) );
                arrow.setCursor(new Cursor(Cursor.HAND_CURSOR) );
                box.setCursor(new Cursor(Cursor.HAND_CURSOR) );
                delete.setCursor(new Cursor(Cursor.HAND_CURSOR) );
                resize.setCursor(new Cursor(Cursor.HAND_CURSOR) );
                rotate_left.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
                      if (e.getSource() == rotate_left && selectedRect != null)
                         selectedRect.rotateRect();
                         repaint();
                rotate_right.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e)
                      if (e.getSource() == rotate_right && selectedRect != null)
                         selectedRect.rotateRect_right();
                         repaint();
                arrow.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
                      addArrow = (e.getSource() == arrow);
                box.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
                      addSquare = (e.getSource() == box && selectedRect != null);
                delete.addActionListener(new ActionListener()
                    public void actionPerformed(ActionEvent e)
                       delete_box = (e.getSource() == delete);
                resize.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
                      if (e.getSource() == resize && selectedRect != null)
                         selectedRect.resizen();
                         repaint();
                JPanel panel = new JPanel();
                panel.setBackground( Color.orange );
                panel.add(rotate_left);
                panel.add(rotate_right);
                panel.add(arrow);
                panel.add(box);
                panel.add(delete);
                panel.add(resize);
                return panel;
        public void init() {
            axel rp = new axel();
            Container cp = getContentPane();
            cp.setLayout(new BorderLayout());
            cp.add(rp.panelen(), "South");
            cp.add(rp);
        public static void main(String[] args)
            JApplet applet = new Box();
            JFrame f = new JFrame("Test");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(applet);
            f.setSize(600, 400);
            f.setLocationRelativeTo(null);
            applet.init();
            f.setVisible(true);

  • Acrobat Pro 6 Average Daily Production and Math.round problem

    Acrobat Pro 6 Average Daily Production and Math.round problem
    (Production.0) (154) (whole units) . (Production.1) (90) (fractional) / (divided by) 31 (days) results in (Average.0) (4)(whole units) . (Average.1) (10) (fractional) using :Math.round.� Noticed that 154 (whole units) . 85 through 99 (fractional) also show 4.10. (without Math.round : 5.00)
    Method:
    �Production.0� (whole units) . �Production .1� (fractional) / Days = (Average Daily Production) (�Average.0� (whole units) . (Average.1) (fractional)
    � Production.0 (value not calculated)�, � Production 1 (calculated) (event.value = util.printx("0099", (event.value)).substr(-2,2); � �Average.0 (value not calculate)�, and �Average.1 has following calculation:
    var punits = this.getField("Production.0");
    var pfrac = this.getField("Production.1");
    var average = 0.0;
    average = (punits.value + pfrac.value / 100) / this.getField("Days").value;
    this.getField("Average.0").value = average - average % 1;
    this.getField("Average.1").value = util.printx("0099", Math.round((average % 1 * 100))).substr(-2,2);
    �Math.round� appears to be a problem. Also, could you explain the purpose of �0099� . Anyway, why would 154.85 through 154.90 divided by 31 give 4,10. Also, their must be a better way, to find the average daily production. All you have to do is divided the production (whole. fractional) by the days, and display the average daily production as (whole. fractional). Any suggestions??

    There are a many loose ends in your question.
    First, I have never seen before a variable type called 'var'. Is it a java primitive or a class?
    Next, I cannot seem to find any class that has the printx method.
    When it comes to substr(-2,2), I get confused. First, I thought that it was a method of the String class, but I only got as far as substring(beginIndex, endIndex).
    If you really must break the production and average into pieces, try this:
    float average = (punits + pfrac/100) / days;
    int avg_units = (int)average;
    int avg_frac = (int)( (average - avg_units) * 100 );My guess is that util.printx("0099", x) formats x having two optional digits and two mandatory digits, showing 0-99 as 00-99, but allows to show numbers with three and four digits.
    154.85/31 = 4,9951612903225806451612903225806
    154.99/31= 4,9996774193548387096774193548387
    If you round the fraction of theese numbers multiplied by 100 ( = 99.51.. and 99.968...) you get 100, and this will be the output of printx. My guess for "4.10" is that substr(-2,2) returns the two first characters of the string, because the start index should not be zero. (According to java docs, substring throws an exception on a negative index, so what kind of class are you really using ??????)

  • Selectively ignore Problem Tags Dialog  while importing Tagged Text in CS5.5

    Hi
    My script imports tagged text and places it in selected frames. Due to the tag creation process used, I occasionally get a "Ignoring character level attribute termination tag "<cTracking:>" found without the corresponding character level attribute application tag "<cTracking:value>"
    Since it's not a problem I can ignore this specific error -- but I don't want to turn off ALL problem tag error checking because occasionally there are serious errors that I DO want to see.
    Is there a way to tell ID to ignore this specific error?
    Thanks
    Akiva

    UNfortunately the original ascii files uses a <D> code to return to the default settings -- and since that occasionally includes resetting the tracking to 0 I need to include the "<cTracking:>" tag.
    I could obviously fix it by adding a "<cTracking:0>" to all the codes -- but that seems like it could cause more problems.
    I can preprocess the ascii code to eliminate the excess codes -- but that increases processing time for something which happens only occasionally and is non-problematis in practice.
    Akiva

  • HELP!!!  math.random() problem

    Hello,
    I was wondering if anyone can help me with a problem I'm
    running into using the math.random(). I'm using Flash CS3 and
    created a very simple script to select random frames in a simple
    movie. It works as expected in the CS3 environment and in Safari
    but it doesn't work correctly in Firefox or in the DotNetNuke
    module I am using. Here is the code:
    i = Math.ceil(Math.random() * 3);
    gotoAndPlay("Image"+i);
    I would appreciate any help you can provide.

    Remember that Math.random() function returns a positive double value between 0.0 and 1.0. For a better definition you can refer to the Math class in the API.
    Since this is an assignment, I am not going to give you the code but I'll just tell you how you should be going about solving this.
    Now you have two limits right? What you can do is, multiply the smaller of the two numbers (I guess in your case its going to be the top) with the random number generated by the Math.random() function. Just add a check to see if this result is lesser than the maximum limit. If yes, then go ahead and add that number to the array. If not, just repeat the same thing.
    I hope you got the idea. If you still have problems, please let me know.
    Plutaurian

  • DrawOval( ) and Math.tan( ) problem

    Hello,
    I want to make a very simple animation: a circle moves with a 30 degree angle over the screen.
    Now my problem:
    When I calculate the new x and y coordinates for the circle I use the "Math.tan( )" method. But when I want to use those coordinates in the drawOval( ) method they should be INTEGERS. But then they will be rounded numbers and nothing will happen. (A horizontal animation will follow, because of the rounding of the numbers...). Can DOUBLES be used in a way in those draw methods? (So there won't be any loss of precision.)
    Thanks in advance...

    This is my source:
    import java.awt.*;
    import java.applet.*;
    public class Demo extends Applet
    public void paint(Graphics g)
    double x=10,y=300;
    for (int xadjust = 1;xadjust < 300;xadjust++)
    // a 45 degree angle
    x = x + xadjust;
    y = y - ((Math.tan((1/4)*Math.PI)) * x); // calculate new y coordinate
    g.drawOval( (int)x,(int)y,15,15);
    }

  • Rotating pic delay problem

    Hi,
    I have a picture that rotates with a fade into another
    picture. It works fine.
    I want to keep the picture alpha=100 just sitting there for a
    few minutes then perform the fadeInterval to change next picture.
    If I set a longer delay in setInterval the it just fades the
    picture slowly and you see a bad picture for while.
    tdelay=100;
    fadespeed=1;
    tum=setInterval(fade,tdelay,0,1);
    function fade(i:Number,j:Number):Void
    _root["mc"+i]._alpha -=fadespeed;
    _root["mc"+j]._alpha+=fadespeed;
    if (_root["mc"+j]._alpha >100)
    _root["mc"+j]._alpha =100;
    _root["mc"+i]._alpha =0;
    i++;
    j++;
    if (j==3) j=0;
    if (i==3) i=0;
    clearInterval(tum);
    tum=setInterval(fade,tdelay,i,j);
    //i added this
    I just want a pivture to show for a few minutes and then
    change.
    If I set dummy delay like this it fails to work.
    uu=0;
    tum2=setInterval(wait,200);
    if (tum2==NULL)
    tum=setInterval(fade,tdelay,0,1);
    function wait():Void
    i=1;j=1;
    if (_root.uu==2)
    clearInterval(tum2);
    trace(tum2);
    _root.uu=2;
    }

    i can't really find a quick answer to this common problem i
    have.

  • Rotating pictures creates problem

    Hi,
    The issue is the following.
    I asked my photo shop to put my négatives on CD's. I have a specific iLibrary, with pictures imported from the CD's with the files coming from my negatives. Most of these files are actually upside down in iPhoto. When I rotate them either individually, with one picture upfront and the others in banner, or simply when they are all on screen (selecting several pictures and rotating all of them at once), two strange things happen: first, scrolling through the pictures after having selected one brings back to the screen with the one selected, and, after having selected a certain number of pictures, iPhoto quits.
    I have rebuild the database, with some result. Some because all of the rotated pictures are not put correctly. More: there is regression after several rebuild: pictures that were shown correctly are again upside down after the next rebuild.
    I have two questions:
    1, Is what seems to be some kind of problem linked to 1Photo 6 with imported CD's solved in the next version (iLife 8)?
    2, Is there a way to tackle this in iPhoto 6?
    Thanks,
    F

    Hi Terence,
    As what you proposed didn't work, do you think it's due from the fact that I didn't take the pictures from the disk instead of exporting them from a library? Could that make the difference?
    In the meantime, I tried another way: I export the upside-down picture to a separate library, and rotate them. The two bugs are still there: moving back to the last selected picture after scrolling, and quitting iPhoto after rotating a large quantity of picture (above 50 according to my empiric approach). Then I quit iPhoto and rebuild the library (size around 60 pictures). When I open the rebuilt library, some pictures are OK, but not all of them. I rotate the pictures again, to have them correctly presented, quit & rebuild again. And so on. It takes me between 7 and 15 rebuild to have all the pictures OK.
    As you can imagine, it takes quite a lot of time... If there is anyone with a better way to address this, I would really appreciate.
    Thanks,
    Fred

  • Math type problem in ms office (mac edition)

    Dear Apple Solver,
    The above mentioned are typed in math type in ms office ( windows edition).
    But after it has been opened in ms office ( mac edition ) in iMac ,
    the arrows are showing  like letter r
    and caps as dollars.( vector symbols)
    the symbol since as Q
    I need help from concerned developers.
    Regards
    SRINIVASAN N

    Hi,
    Yes, I'm having the same difficulty when installing FM Web
    Studio by FMWebSchool.com. I get the [empty] "Document type could
    not be added" error 33 times on application launch. I see no
    templates, no dynamic page creation options.
    PS. Edited to note I'm on MacOS 10.4.10, PowerPC, DW MX2004
    quote:
    Originally posted by:
    mpjx
    Hi all,
    I run DW MX2004 under OS X 10.4.10 on a Mac. I'm having
    trouble installing the Rubyweaver 2.0 extension (available from
    http://rubyweaver.gilluminate.com/)
    which should add ruby and rails functionality to DW. According to
    Extension Manager it is installed fine but when I try to use DW I
    get the following problems:
    1. On startup DW throws up a warning message:
    quote:
    The Document Type "" will not be added because it uses a file
    extension that is already associated with a prior document type.
    This message appears three times, I assume for
    three different document types.
    2. Rails, YML and SQL options are not present in the New
    Document window options (they should be).
    3. Preferences > Code Format > Tag Library Editor
    displays an option called 'Rails' - even when the checkbox is
    ticked, HTML colouring is not present in .rhtml files.
    I contacted the developer about these issues, he assured me
    that the extension was developed for and tested on both Windows and
    OS X platforms, and that nobody else had reported any problems. He
    suggested it must be a problem specific to my system.
    So, here's my question: has any one else experienced problems
    installing either this or another extension in DW MX2004 on a Mac
    and does anyone have a solution/work around.
    Thanks in advance for any help.

  • Firefox in Windows. When I click on a link, Firefox will hang up with a rotating cursor. Problem goes away by moving mouse. This does not happen with IE.

    Using Firefox 27.0, when I click on any link, a rotating cursor appears and continues to rotate. Moving the cursor will solve the problem. I have had this problem for several versions of Firefox, and I use auto updates.

    Hello,
    '''Try Firefox Safe Mode''' to see if the problem goes away. Safe Mode is a troubleshooting mode, which disables most add-ons.
    ''(If you're not using it, switch to the Default theme.)''
    * On Windows you can open Firefox 4.0+ in Safe Mode by holding the '''Shift''' key when you open the Firefox desktop or Start menu shortcut.
    * On Mac you can open Firefox 4.0+ in Safe Mode by holding the '''option''' key while starting Firefox.
    * On Linux you can open Firefox 4.0+ in Safe Mode by quitting Firefox and then going to your Terminal and running: firefox -safe-mode (you may need to specify the Firefox installation path e.g. /usr/lib/firefox)
    * Or open the Help menu and click on the '''Restart with Add-ons Disabled...''' menu item while Firefox is running.
    [[Image:FirefoxSafeMode|width=520]]
    ''Once you get the pop-up, just select "'Start in Safe Mode"''
    [[Image:Safe Mode Fx 15 - Win]]
    '''''If the issue is not present in Firefox Safe Mode''''', your problem is probably caused by an extension, and you need to figure out which one. Please follow the [[Troubleshooting extensions and themes]] article for that.
    ''To exit the Firefox Safe Mode, just close Firefox and wait a few seconds before opening Firefox for normal use again.''
    ''When you figure out what's causing your issues, please let us know. It might help other users who have the same problem.''
    Thank you.

  • Math.sin() problem

    Hi!
    I need calculating sin in java but i need it in degrees and java doing it in rads. Anybody knows what can i do?
    Thanx!!!
    Max

    Maybe you should look through the API at that Math class. You're already using Math.sin() ... how could you have missed Math.toDegrees() and Math.toRadians() ???

  • Help - Rotating text/picture problem in Motion 4!

    Hi, Can anyone help me out? When trying to make text face the camera and rotate like a merry-go-round, the 'face camera' option makes all the characters face the camera as they go around - like this..
    http://i83.photobucket.com/albums/j293/tekiesha/motion4.png
    This is what I'm trying to achieve:
    http://www.5min.com/Video/Motion-3-Cool-Text-Trick-18629411
    Thanks in advance!

    The text engine was rewritten in M4 and works differently.
    Uncheck the Face Camera checkbox. Go to the Format pane of the Text tab. Change the Rotation X value to 90 degrees.

  • Interactive, rotating globe - button problems

    I made an interactive rotating globe that shows all the continents (using CS3 and AS3). The globe rotates automatically. When the user mouses over the globe is stops rotating and they can use left/right arrows to rotate it manually to get to a continent. When the mouse rolls over a continent (Australia for instance) it changes color and should be clickable and go to a website but it's not working. It doesn't return any errors.
    The basic structure of it is this:
    One big continent map (basically a flat world map) with a motion tween applied to it so it looks like it's moving across the planet in the background. That's in "globe_mc" on the main timeline. Then I did the same thing in a different movie clip with the buttons (moving across the planet in sync with their respective continent), that's in "buttons_mc" on the main timeline.
    The button worked until I applied the mouse controls to "buttons_mc" in the main timeline AS (to make them stop moving with the continents with the mouse is over the planet). After I did that it stopped working (I'm just working with "test_btn" right now until it works).
    The code for the button, inside "buttons_mc" is the following:
    //test btn
    function testBtn(event:MouseEvent):void
              navigateToURL(new URLRequest("http://www.pmirope.com"));
    test_btn.addEventListener(MouseEvent.CLICK, testBtn;
    //end test btn
    This is the code I have on the main timeline to control the rotation based on the mouse position:
    addEventListener(Event.ENTER_FRAME, scroll_function);
    function scroll_function(event:Event):void
    //Both Nav Arrow's Y Position
          if(root.mouseY>470 && root.mouseY<530)
    //Right Arrow's X Position
          if (root.mouseX>50 && root.mouseX<75)
                     globe_mc.land_mc.gotoAndStop(globe_mc.land_mc.currentFrame-1);
                     buttons_mc.gotoAndStop(buttons_mc.currentFrame-1);
          else
                     globe_mc.land_mc.play();
                     buttons_mc.play();
    //Left Arrow's X Position
          if (root.mouseX>925 && root.mouseX<950)
                     globe_mc.land_mc.gotoAndStop(globe_mc.land_mc.currentFrame+1);
                     buttons_mc.gotoAndStop(buttons_mc.currentFrame+1);
          else
                     globe_mc.land_mc.play();
                     buttons_mc.play();
    //Globe's Position
          if(root.mouseY<950 && root.mouseY>50)
          if(root.mouseX<950 && root.mouseX>50)
                     globe_mc.land_mc.stop();
                     buttons_mc.stop();
          else
                     globe_mc.land_mc.play();
                     buttons_mc.play();
    I'm guessing that the button's code is being canceled out by the "position" code but I don't know how to fix it.
    Please help!!!

    First, to answer your question, they do change color and it's done with the up, over and down states inside the button. So when you rollover the button it changes color and the mouse changes to the hand to show it's clickable but when it's clicked nothing happens.
    I did figure out a way to do it, but I'm not sure why it works. As I said before, I had the buttons_mc and the globe_mc on the main timeline. I put the buttons_mc inside two other MovieClips and then put the actual buttons on the stage - like this:
    Main Timeline
         globe_mc
         buttonsMain_mc
              buttonsInside_mc
                   buttons_mc
                        US_btn
                        Canada_btn
                        Australia_btn
                       and so on....
    I tried putting buttons_mc inside only 1 MovieClip (buttonsMain_mc) but it still didn't work. I had to add buttonsInside_mc for it to work. Why is that?
    Thanks for the help!

  • Java 3d rotating text snapshot problem

    Hi guys !
    I have searched for a method which captured a 3d rotating text and print it on the screen ,but i didn`t found it.
    I have to this exercise :
    Write a Java 3D program showing two panels and a button. The first panel displays a scene of a rotating 3D text string. When the button is clicked, the image of the 3D scene is captured and the still image is displayed in the second panel.
    Can anybody help me or write me the source code???
    thank you

    Only a fool will do your homework for you.
    But I can't help noticing that the assignment specifically mentions Java3d, and you're asking on an applet forum. It seems unlikely that you're supposed to implement your assignment as an applet.
    Most likely, the assignment tells you how to obtain Java3d. Either that or an earlier hand-out in your class says how to.
    You should re-read your assignment and other class notes, get the Java3D library, and then read the Java3D documentation. Write a simple "hello world" type program using Java3d. At that point, this assignment will probably be pretty simple for you.

  • Math calculation problems

    My Timeline of the Universe needs fixing. I have hobbled together something that works so-so, but the attached swf shows the flaws.
    Assistance much appreciated.

    If you explain the issue in more detail and provide the calculations that are not working you might get better results.  Most people are not going to spend time searching thru a file to try to see what is wrong.  I looked thru it briefly and the problem isn't obvious to me.

Maybe you are looking for