Results 1 to 7 of 7
  1. #1
    nadz is offline Member
    Join Date
    Sep 2013
    Posts
    4
    Rep Power
    0

    Default Transformation & Enum Confusion

    Hi guys,

    I need your help in solving this error. When I enter the code below, there are plenty of errors came out. I am still new in programming field. I will be much appreciated if someone could figure out this for me. Thank you so much. This is the code:

    Java Code:
     package gener;
    
     import model.*;
     import util.*;
     import fea.*;
    
     // Make transformations for a specified model.
     // Input: modelName - name of the finite element model;
     // [translate axis value] - translate axis coordinates;
    // [scale axis value] - scale axis coordinates;
     // [rotate axis value] - rotate around axis by angle (degrees);
     // [mirror axis value] - mirror along axis around axis value
     public class transform {
    
     private FeModel m;
     enum vars {
     translate, scale, rotate, mirror, end
     }
    
     enum elementMirror {
     quad8 {int permutation(int i) {
     int[] p = {1,8,7,6,5,4,3,2};
     return p[i]-1;}
     },
     hex20 {int permutation(int i) {
     int[] p = {1,8,7,6,5,4,3,2, 9,12,11,10,
     13,20,19,18,17,16,15,14};
     return p[i]-1;}
     };
     abstract int permutation(int i);
     }
    
     private vars opName;
     private char axis;
     private double value;
    
     public transform() {
    
     String modelName = Jmgen.RD.next();
     Jmgen.PR.printf("Transform: %s\n", modelName);
    
     if (Jmgen.blocks.containsKey(modelName))
     m = (FeModel) Jmgen.blocks.get(modelName);
     else UTIL.errorMsg("No such mesh block: " + modelName);
    
     while (Jmgen.RD.hasNext()) {
     String name = Jmgen.RD.next().toLowerCase();
     if (name.equals("#")) {
     Jmgen.RD.nextLine(); continue;
     }
     if (name.equals("end")) break;
    
     try {
     opName = vars.valueOf(name);
     }catch (Exception e) {
     UTIL.errorMsg("Operation name is not found: "
     + name);
     }
    
     String Axis = Jmgen.RD.next().toLowerCase();
     axis = Axis.charAt(0);
     if (axis!=’x’ && axis!=’y’ && axis!=’z’)
     UTIL.errorMsg("Incorrect axis: " + axis);
     value = Jmgen.RD.readDouble();
     Jmgen.PR.printf("%10s %s %10.4f\n",
     opName, Axis, value);
    
     switch (opName) {
     case translate: doTranslate();
     break;
     case scale: doScale();
     break;
     case rotate: doRotate();
     break;
     case mirror: doMirror();
     break;
     }
     }
     Jmgen.PR.printf("Mesh " + modelName +
     ": nEl = %d nNod = %d\n", m.nEl, m.nNod);
     }
     private static int getIntAxis(char axis) {
     int iAxis = 0;
     if (axis==’y’) iAxis = 1;
     else if (axis==’z’) iAxis = 2;
     return iAxis;
     }
    
     private void doTranslate() {
    
     if (m.nDim == 2 && axis == ’z’)return;
     int iax = getIntAxis(axis);
    
     for (int i=0; i<m.nNod; i++)
     m.setNodeCoord(i, iax,
     m.getNodeCoord(i, iax) + value);
     }
    
     private void doScale() {
    
     if (m.nDim == 2 && axis == ’z’)return;
     int iax = getIntAxis(axis);
    
     for (int i=0; i<m.nNod; i++)
     m.setNodeCoord(i, iax,
     m.getNodeCoord(i,iax)* value);
     }
    
     private void doRotate() {
    
     if (m.nDim == 2 && (axis==’x’ || axis==’y’))return;
    
     double sina = Math.sin(Math.toRadians(value));
     double cosa = Math.cos(Math.toRadians(value));
     double a[][] = new double[3][3];
     double x[] = new double[3];
    
     if (axis==’x’) {
     a[0][0]= 1; a[0][1]= 0; a[0][2]=0;
     a[1][0]= 0; a[1][1]= cosa; a[1][2]=-sina;
     a[2][0]= 0; a[2][1]= sina; a[2][2]= cosa;
     }
     else if (axis==’y’) {
     a[0][0]= cosa; a[0][1]= 0; a[0][2]= sina;
     a[1][0]= 0; a[1][1]= 1; a[1][2]= 0;
     a[2][0]=-sina; a[2][1]= 0; a[2][2]= cosa;
     }
     else { // around z
     a[0][0]= cosa; a[0][1]=-sina; a[0][2]= 0;
     a[1][0]= sina; a[1][1]= cosa; a[1][2]= 0;
     a[2][0]= 0; a[2][1]= 0; a[2][2]= 1;
     }
    
     for (int inod=0; inod<m.nNod; inod++) {
     for (int j=0; j<m.nDim; j++)
     x[j] = m.getNodeCoord(inod,j);
     for (int i=0; i<m.nDim; i++) {
     double s=0;
     for (int j=0; j<m.nDim; j++) s += a[i][j]*x[j];
     m.setNodeCoord(inod, i, s);
     }
     }
     }
     private void doMirror() {
    
     if (m.nDim == 2 && axis == ’z’)return;
     int iax = getIntAxis(axis);
    
     // Mirror nodal coordinates
     for (int i=0; i<m.nNod; i++)
     m.setNodeCoord(
     i, iax, -m.getNodeCoord(i,iax)+2*value);
    
     // Change order of element connectivities
     for (int e=0; e<m.nEl; e++) {
     elementMirror em =null;
     try {
     em = elementMirror.valueOf(m.elems[e].name);
     }catch (Exception el) {
     UTIL.errorMsg("Mirror: element not supported "
     + m.elems[e].name);
     }
    
     int nind = m.elems[e].ind.length;
     int[] ind = new int[nind];
     for (int i=0; i<nind; i++)
     ind[em.permutation(i)] = m.elems[e].ind[i];
     m.elems[e].setElemConnectivities(ind);
     }
     }
    
     }
    Last edited by JosAH; 09-24-2013 at 09:42 AM. Reason: added [code] ... [/code] tags

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,876
    Rep Power
    5

    Default Re: Transformation & Enum Confusion

    repost with code tags please. There is a button in the advanced post editor.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,436
    Blog Entries
    7
    Rep Power
    20

    Default Re: Transformation & Enum Confusion

    Quote Originally Posted by gimbal2 View Post
    repost with code tags please. There is a button in the advanced post editor.
    I did it for the OP, but it didn't help much ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,876
    Rep Power
    5

    Default Re: Transformation & Enum Confusion

    No, syntax colored unformatted code is even worse.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    nadz is offline Member
    Join Date
    Sep 2013
    Posts
    4
    Rep Power
    0

    Default Re: Transformation & Enum Confusion

    Thank you very much guys.

    I have fixed some of the errors but still having trouble with this code:

    62 "if (axis!=x && axis!=y && axis!=z)" - the error is illegal character: \8217 not a statement


    do you have any idea what is wrong?

  6. #6
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Transformation & Enum Confusion

    You're using something other than ' as your single quote character. What are you using to edit your code?
    Get in the habit of using standard Java naming conventions!

  7. #7
    nadz is offline Member
    Join Date
    Sep 2013
    Posts
    4
    Rep Power
    0

    Default Re: Transformation & Enum Confusion

    Thank you kjkrum, you have solved my problem.

    Thank you very much.

Similar Threads

  1. enum confusion
    By gbritton in forum New To Java
    Replies: 8
    Last Post: 08-13-2013, 07:11 PM
  2. How do you get the inverse of this transformation?
    By EscSequenceAlpha in forum New To Java
    Replies: 1
    Last Post: 05-03-2012, 12:18 AM
  3. public static enum vs enum class
    By Dipke in forum New To Java
    Replies: 3
    Last Post: 08-30-2011, 10:45 AM
  4. Enum confusion
    By castiel in forum New To Java
    Replies: 2
    Last Post: 04-29-2011, 06:58 AM
  5. Transformation
    By rosh72851 in forum New To Java
    Replies: 1
    Last Post: 11-19-2008, 04:11 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •