Using java.lang.Math.sin/tan/cos  to make an arc - very simple

hi all,
i'm trying to dynamically create an set of numbers in an arch pattern -- going left to right (counter clockwise) --- from 0 degrees to 180 degrees. -- similar to an upside down U
Any ideas on how i would do a simple loop to put the number 1 in a semicircle.
I'm guessing that it might look like this
while(x < 181)
g.drawString(Integer.toString(x) , java.lang.Math.sin(..), java.lang.Math.cos(...) )
how may I ask does that work again ?
s

The coordinates of the unit circle are given by
x = cos(t)
y = sin(t)
where 0 < t <= 2pi
You'll want to scale and translate that... Here's a code fragment; play with it a little:for (double t=Math.PI/2; t < 2*Math.PI, t += .05) {
    double x = 100*Math.cos(t) + 100;
    double y = 100*Math.sin(t) + 100;
    g.drawLine((int) x, (int) y, (int) x, (int) y);
}

Similar Messages

  • How to use Java.lang.Math to calculate; Advice programming

    Hi, all!
    I am trying to teach myself Java, and am using the MindQ CDs to do it. I'm dreadfully stuck on this one exercise, and I could use some help figuring out how to properly call a Math method, store the variables, and print the results. I've programmed other methods successfully before; for some reason I just can't figure this one out. I've tried about fifty different configurations; maybe I can get some good advice here? Thanks!
    import java.io.*;
    import java.util.Random;
    import java.lang.Math;
    public class JavaCalcs {
        public static void main(String args[]) {
            System.out.println("Starting JavaComputations...");
            //main method variable declarations
            int z, y, x, w;
            int A = -12;
            int B = 2;
            z = A & B;
            y = A | B;
            x = A >> B;
            w = A >>> B;
            System.out.println(z + ";" + y + ";" + x + ";" + w + ";");
            Random kickassRNG = new Random();
            double rDOne = kickassRNG.nextDouble() * 90.0;
            double rDTwo = kickassRNG.nextDouble() * 90.0;
            System.out.println("rDOne= " + rDOne);
            System.out.println("rDTwo= " + rDTwo);
    //NOTE-EVERYTHING WORKS FINE UNTIL THIS POINT...
            if (rDOne > rDTwo)
            System.out.println("The larger of the 2 degs. is rDOne");
            //compute ceiling.
            double a=rDOne; //Store the value of rDOne.
            public static double ceil(double a);
            return a;
            System.out.println( "the ceiling of rDOne is " + a );
            //convert degree measurement to radians.     
            public static double toRadians(double b);
            double b = a;
            System.out.println("rDOne in radians is " + b );
            //compute tangent of that result.
            public static double tan(double c);
            double c = b;
            System.out.println("The tangent of rDOne is " + c );
            else
            System.out.println("The larger of the 2 degs. is rDTwo");
            //compute ceiling.
            double a=rDTwo; //Store the value of rDOne.
            public static double ceil(double a);
            return a;
            System.out.println( "the ceiling of rDTwo is " + a );
            //convert degree measurement to radians.     
            public static double toRadians(double b);
            double b = a;
            System.out.println("rDTwo in radians is " + b );
            //compute tangent of that result.
            public static double tan(double c);
            double c = b;
            System.out.println("The tangent of rDTwo is " + c );
        } //end main method.
    }

    VERY useful link..thxYou're welcome. Here are some more:
    Sun's basic Java tutorial
    Sun's New To Java Center. Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
    http://javaalmanac.com. A couple dozen code examples that supplement The Java Developers Almanac.
    jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
    JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
    Bruce Eckel's Thinking in Java (Available online.)
    Joshua Bloch's Effective Java
    Bert Bates and Kathy Sierra's Head First Java.
    James Gosling's The Java Programming Language. Gosling is
    the creator of Java. It doesn't get much more authoratative than this.

  • How can I called java.lang.Math.sqr function from PL/SQL?

    JVM is loaded and I've queried the system table showing there are more than 9000 JAVA class objects.
    When I try something like:
    select java.lang.Math.sqrt(9) from dual;
    I get ORA-00904 (invalid column name) error. How can I invoke standard java.lang.Math methods in PL/SQL?
    tia

    You need to write a PL/SQL wrapper for the java call.
    Then you just call the PL/SQL function..
    -------PL/SQL wrapper
    FUNCTION GetFullName( code varchar2) RETURN NUMBER
    AS LANGUAGE JAVA
    NAME 'ResponseXml.GetPersonFullName(java.lang.String) return java.lang.String';
    Now you can do
    Select GetFullName( 'mycous' ) from dual;

  • Invoke exe through java code(using java.lang.Runtime)

    Iam trying to invoke an exe from java code.If i give the complete path for that exe it is running fine .But if i set the environment variable and directly execute the exe through command prompt it iss running fine , but it fails to run when i do the same using java code i.e. java.lang.Runtime.exec function

    Give "//" for directory seperator.
    E.g. r.exec("c://test//test.exe",null);
    Why? That doesn't look correct.It is correct. It will work fine. Try it out.But it doesn't add or solve anything. A forward slash
    does not need to be escaped.'
    It's not even escaping. It's just doubling up. If that works, I'd bet "C://///test///////test.exe" does also.

  • Using java.lang.Float.class causing Cannot format given Object as a Number

    hi,
    I have table and its model is default table model.
    model = new javax.swing.table.DefaultTableModel(data,col) {Class[] types = new Class [] {
                    java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Float.class,  java.lang.Integer.class
                }; public Class getColumnClass(int columnIndex) {
                    return types [columnIndex];
                }};I want to force the user to enter float number to fourth column and integer number to fifth column. but I am gettin an error "Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Cannot format given Object as a Number" like this. cause of this error is "java.lang.Float.class". and when I use Integer instead of Float the is no problem. Could you please help ?

    It depends on model data.

  • How to use java.lang.Class.getMethod() and java.lang.reflect.Method.invoke(

    I want to call a specified method of one class dynamically. I use the method
    "getMethod()" in package "java.lang.Class" to get method and "invoke()" in
    " java.lang.reflect.Method " to invoke method.
    The problem is as following :
    1. There are two argument in this method "getMethod(String MethodName , Class[] paremterTypes)" in package "Class". I have no idea about the second parameter " Class[] parameterTypes ".what does the argument exactly mean ?
    2. There are two argument in the method "invoke(object obj, object[] obj)" in package "Method".
    I have no idea about the second parameter "object[] obj ".what is mean ?
    I pass " null " value to it and it works.But i pass anothers ,jvm will throw exception.

    I have a generic Method Executer that has a method like
    public Object execute(String className, String methodName, Object args)
        String fullClassName = packageName + className ;
        Class delegateClass = Class.forName(fullClassName);
        BaseDelegate delegate = (BaseDelegate)delegateClass.newInstance();
        Method method = null;
        if (args == null)
            method = delegateClass.getMethod(methodName, new Class[] {});
            obj = method.invoke(delegate,new Object[] {});
        else
            method = delegateClass.getMethod(methodName, new Class[] {args.getClass()});
            obj = method.invoke(delegate, new Object[]{args});
       }This seems to have problems when I call the method from a class like:
    execute("CategoryDelegate", "getCategoryById", new Integer(4144));(I get a NoSuchMethodException)
    The method I am trying to execute in CategoryDelegate looks like:
    public Category getCategoryById(int categoryId) throws DelegateExceptionI think it has to deal with the difference in the way we handle Primitive Wrappers and Objects. Wrapper we have to use Interger.TYPE and with the rest of the Objects we have to use obj.class.
    Am I doing something wrong here? Any suggestions to make it work for primitive wrappers as well as Objects?

  • Advantages,Dis-advantages,when and where -use java.lang.Void Wrapper  class

    Hi All,
    I like to know when and where to use the wrapper class java.lang.Void and when it is particulary needed.if anyone could give me some examples it will be better.
    Thanks in advance,
    Kathir

    I like to know when and where to use the wrapper class java.lang.VoidWhy? If you don't need it, you don't have to use it.
    and when it is particulary needed.It is needed when you want to represent the concept of a void return value.
    if anyone could give me some examples it will be better.
    Method wait = Object.class.getMethod("wait",null);
    if (wait.getReturnType() == Void.TYPE) {
      System.out.println("Object.wait() returns null");
    }

  • Using java.lang.reflect.Method.invoke on a static method?

    This is probably a FAQ, but I am finding it impossible to construct a search which answers this question for me.
    How do I call java.lang.reflect.Method.invoke on a static (e.g. class) method? Is it even possible?
    Thanks,
    dwh

    Is this of any help?
    http://www.esus.com/javaindex/j2se/jdk1.2/javalang/reflection/reflection.html
    Cheers,
    Joris

  • Would any one tell me how to use java.lang.ref.*

    Hello!
    I am a recruit. I need to write something with java.lang.ref.
    I can't understand the description in API of J2SE very well. Would any one tell me where could I get some more detail or tutorial or example?
    Thanks!
    wooing

    check it out
    http://developer.java.sun.com/developer/technicalArticles/ALT/RefObj/

  • Using java.lang.reflect.Proxy class

    I am investigating the uses of the new Proxy object introduced in jdk1.3.
    One of the first things I noticed was how slow it was to generate a class via Proxy. The system can spend over 100 millliseconds to generate one. If you create many of those this can suck up alot of time. Is there a way to speed this up? I noticed when I try to cache the Object sent back into one of the java.util Collection I get errors when trying to retrieve them. Usually class cast errors when I call the 'isEmpty' method on the Collection.
    I noticed that I could cache them into an array of Objects, I have also been able to store the Class that is generated, and the Constructor, so when new ones were needed I could just call the constructor using the Class that was pre generated.
    In my performance tests it took in the order of 2 minutes to generate 100,000 without any cacheing.
    When I cached the objects in an [] of Objects that time went down to around 15 seconds. When I cached the Class and Constructor the time went to around 30 seconds.
    Has anyone out there attempted to cache Proxy's?
    I would appreciate any experience you have had with this.
    thanks in advance
    chris

    Cris,
    I am very interested in the caching approach you took. I have an application that uses a lot of proxies, any kind of optimization on proxies would result in a big performance boost.
    Thanks,
    David

  • Forums - How to use java.lang.Class.getMethod() and java.lang.reflect.Metho

    I have similar question. I am trying to invoke a method with no parameters. I don't know how to do that. Can someone please help.
    for example.
    I have 2 methods.
    public void setMethod(String strPut){
    this.strPut = strPut;
    public String getMethod(){
    return strPut;
    Method method = objRef.class.getMethod("setMethod", new Class[]{String.class});
    Object objReturn = method.invoke(sqlWhere, new Object[] {"any String"});
    I can invoke setMethod but I don't know how to invoke getMethod().

    Hi
    Try using something like this...
    CustomClass objCustomClass = new CustomClass ();
    Class customClass = objCustomClass.getClass ();
    Method m = customClass.getMethod ("getMethodName", (Class[])null);
    String strContent = (String) m.invoke (objCustomClass, null);
    Thanks and regards,
    Pazhanikanthan. P

  • JTextField Double java.lang.Math

    Hi,
    I need to be able to input a double into a JTextField eg. 13.5
    do some calculations on it and output its answer as a Double/String to a JLabel
    Firstly I know that the following calculation works
    double d, e, f g;
    d = 10;
    e = 14;
    f = 13.5;
    g = Math.pow(d, -(e - f));
    System.out.println(g);
    //Outputs 0.31622776601683794 Correct AnswerThe following works if I input of 13, but I get a NumberFormatException if I input 13.5.
    double dInput, calc;
    String str_calc;
    JTextField input = new JTextField();
    dInput = Double.parseDouble(input.getText());
    calc = Math.pow(d, -(e - dInput));
    str_calc = Double.toString(calc);
    JLabel label = new JLabel();
    label.setText(str_calc);Can anyone tell me where I am going wrong? How can I fix it?
    Any help would be grately appreciated

    Problem solved.
    The issue I was having was not related to changing from printf to GUI, it was elsewhere in my code.
    Thanks anyway

  • Using java.math

    Hey guys,
    I've got yet another question !
    I want to the math.floor to round my double numbers down.
    I've declared "import java.math.*;" at the very start
    but how do you use math.floot actually?
    I've put
    double number = 1.25
    double roundednumber = math.floor(number);
    but it cannot find symbol math...I did something wrrong...

    Hey guys,
    I've got yet another question !
    I want to the math.floor to round my double numbers down.
    I've declared "import java.math.*;" at the very start
    but how do you use math.floot actually?
    I've put
    double number = 1.25
    double roundednumber = math.floor(number);
    but it cannot find symbol math...I did something
    wrrong...As Jos already pointed out: it's with a capital M.
    Note that the Math class is not in the java.math package but in the java.lang package which is automatically imported.
    This is the java.math package:
    http://java.sun.com/j2se/1.5.0/docs/api/java/math/package-summary.html
    And this is the java.lang.Math class:
    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Math.html

  • Practical use of java.lang.Error

    Hi All,
    I would like to know if we can use java.lang.Error -- the sibling of java.lang.Exception -- in our programme. If yes, how and for what practical purposes and if no, then what is the use of this class?
    Thanks,
    Abbas

    You would never normally subclass Error, nor catch
    and deal with such exceptions. I would disagree with this. If your application is
    improperly configured, use an Error. Provide very top
    level code to catch your specific Error (and perhaps
    others) so the user (and most likely the maintainers)
    can be properly notified, though note that you most
    likely will not be able to recover fully.I would say that should be an unchecked RuntimeException at best, but still not an "Error".
    >
    They are thrown by the
    VM when something "bad" happens such as runningout
    of memory.Unfortunately, they are not only thrown by the VM:
    CoderMalfunctionError
    FactoryConfigurationError
    TransformerFactoryConfigurationErrorI don't know what those Errors are (I know I could spend the time looking them up) but I bet they are standard java or javax - packaged errors, and the standard java or javax - packaged classes throw them right? If so, that is still what I mean by "throw by the VM".

  • Java.lang symbols not found when compiling package classes

    I have a set of classes that I have wrapped up in a package. The package name and
    directory structure follow the standard required for each. These classes contain many
    java.lang.Math functions and java.lang.Double calls.
    Am I correct in that the java.lang functions will be imported automatically? When I
    compile a class that is in the package, it looks for the Math.pow (for example)
    function in the package instead of java.lang. I have tried putting the following include
    at the top:
    include java.lang.*;and I still get the "cannot resolve symbol" error. Only when I use
    include java.lang.Math;
    include java.lang.Double;does it compile properly. Is this indicative of a problem with my classpath? It is
    currently set to look in whatever the current directory is, the directory with src.jar,
    and my dev directory that contains the package I am working on.
    Please advise! Thanks in advance!
    Rodman

    Thanks for the quick reply! I looked in the package directory and found the Math.java and
    Double.java files. I'm not sure why they were there. Thanks again!

Maybe you are looking for

  • Unable to open microsoft office

    I am unable to open Microsoft office at all. I restored my system yesterday and it worked. shut down and logged on today the same issue. I show that an update was done last night so I am checking here first b/f I call microsoft.

  • Does the 1st generation IPod suffle play new MP4 format

    We have an IPod shuffle  1 GB First Gen I Think not sure how to tell. Anyway unit has always worked. Little green light comes on flashes when controls are pushed on it. I just removed and replaced the music on the unit and now I do not hear anything.

  • Tree issue

    Hi, I'm trying to display methods of an ABAP class in a tree in WDA but none are being displayed. The class is CL_GUI_ALV_GRID. This is an exercise in the Getting Started with WDA book. The context in my view, as mapped from the component controller

  • Why does other storage build up so fast?

    I just did a complete restore and back up yesterday, 'cuz I had no storage space remaining.  I have no movies, no music, barely any photos or apps installed.  After the restore I freed up almost 9 GB out of 12 GB of storage space.  The only thing tha

  • Way to find which tables are being accessed

    Hi Guys I have a large database and i want to find which tables are not being accessed (even select) from a specific period of time. is there any way to find out . I am using oracke 10g release 1 Regards Khurana Edited by: Khurana on Sep 8, 2009 4:29