SitePoint Sponsor

User Tag List

Results 1 to 22 of 22

Thread: I need help!

  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I need help!

    I have a question on using the tangent. I want to invert the tanget, such as to make it 1/Math.tan(), except that it also inverts whatever you pass to the function, which I dont want. Please help me with this, I would appreciate it. thx.

  2. #2
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't just do 1/Math.tan() because that's the tangent of 0 (unless you want that).
    Feed it the right number: 1/Math.tan(x).
    If it still inverts you input, then possibly safe-keep it in a spare variable, though this is wasteful.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I already tried inverting it using 1/Math.tan(x), and it didnt work. What do you mean by safe keep it in a spare variable?
    What is so common about common sense?
    -joekarbakuitz

  4. #4
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is it you are trying to get the tan OF?!
    Show me your function.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am creating a script that draws lines, and I want to be able to have when the line object is called you enter in the starting point and the ending point, but the problem I have is when I draw the line it uses an angle, so I want to find the angle from what is passed to the line object. The script it is used in is a bit long, but if you want to see it, go to:

    http://www.html4me.com/ryant/shapes.js

    The only way I know to find the angle from that is to use this formula:

    (1/tan)*(opposite/adjacent)

    where opposite is the opposite side from the angle and adjacent is the adjacent side from the angle.
    What is so common about common sense?
    -joekarbakuitz

  6. #6
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well just post the relative section then:

    Code:
    function test(x){
         var tester=1/tan(x)*....
         }
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What I have works fine, except its not what I want. This is what I have so far:

    function Line(clr, width) {
    this.clr=(clr)? clr: false;
    this.width=(width)? width: false;
    this.length=false;
    this.draw=drawIt;

    function drawIt(sx, sy, length, angle) {
    this.length=length;
    for (i=0; i<length; i++) {
    var point=new Point(this.clr, this.width, i);
    var px=(i*Math.cos(angle*Math.PI/180)+sx);
    var py=(i*Math.sin(angle*Math.PI/180)+sy);
    point.draw(px, py);
    }
    }

    shpcnt++;
    }
    What is so common about common sense?
    -joekarbakuitz

  8. #8
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, so now we're getting somewhere.

    Edit your post and put [ C O D E ] - [ / C O D E ]
    around your script so i can see the indents easily.

    Now what is that function doing that you don't want it to?

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  9. #9
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    function Line(clr, width) { 
    this.clr=(clr)? clr: false; 
    this.width=(width)? width: false; 
    this.length=false; 
    this.draw=drawIt; 
    
    function drawIt(sx, sy, length, angle) { 
    this.length=length; 
    for (i=0; i<length; i++) { 
    var point=new Point(this.clr, this.width, i); 
    var px=(i*Math.cos(angle*Math.PI/180)+sx); 
    var py=(i*Math.sin(angle*Math.PI/180)+sy); 
    point.draw(px, py); 
    } 
    } 
    
    shpcnt++; 
    }

    This draws a line from a starting point, then specifies a length and an angle. What I want is a starting point, and an ending point. If I wanted to create a line using what I currently have, I would create it like this:

    var line=new Line('black', 1);
    line.draw(50, 50, 100, 0);

    That will create a horizontal line that is 100 long and starts from 50, 50. But how I want it to draw a line like that one is like this:

    var line=new Line('black', 1);
    line.draw(50, 50, 150, 50);

    Where the first 2 numbers are the starting x,y coordinates and the last 2 are the ending x, y coordinates.
    What is so common about common sense?
    -joekarbakuitz

  10. #10
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, i see what you're doing.

    1) DirectDraw (direct X) supports what you're doing
    without the calculations, do you think this is a
    viable option for you, if so i'll explain further.

    2) you only seem to be passing 2 variables (px, py)
    to point.draw(). draw takes 4 variables, so without
    me having to go through the code, could you explain
    how you expect this to work?

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  11. #11
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know almost nothing about direct x, but I know they support what I am trying to do. My goal is to do this in javascript though.

    The point object has a different draw method that the line object. The point objects method takes the x and y coordinates for the point.
    What is so common about common sense?
    -joekarbakuitz

  12. #12
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right, well i'm not quite sure how it's going wrong.

    btw: You'd have to use Javascript as your interface
    to the direct draw system anyway?

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  13. #13
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, its not going wrong anywhere. What I have works great. I could use this script if I needed to, but it is not what I want to use exactly.
    What is so common about common sense?
    -joekarbakuitz

  14. #14
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, NOW you've lost me.

    Let me check if i've got this right:

    This script works fine and does what you want... BUT ...
    You don't want to use this script.

    Tell me what you want to do that it doesn't or what it does that you don't want it to.

    this is confuzing....


    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  15. #15
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I dont want it to use an angle when using the draw() method, I want it to use just to point for the start and end of the line.
    What is so common about common sense?
    -joekarbakuitz

  16. #16
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok... you don't want the actual LINE, you just want the vertices of that line?

    Hmm, then why not just use the point function
    you posted earlier?

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  17. #17
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes I do want the vertices.

    The point object just creates a dot at a certain point, and the line object creates a line using the point object.

    To clear up any confusion on the point object, here is the code for it:

    Code:
    function Point(clr, width, id) {
    	this.id="pnt_"+shpcnt+"-"+id;
    	this.clr=(clr)? clr: '#000000';
    	this.width=(width)? width: 1;
    	this.draw=drawIt;
    
    	function drawIt(x, y) {
    		this.e=document.createElement("div");
    		document.body.appendChild(this.e);
    		this.e.setAttribute("id", this.id);
    		var obj=document.getElementById(this.id);
    		obj.style.fontSize=0;
    		obj.style.position="absolute";
    		obj.style.left=x;
    		obj.style.top=y;
    		obj.style.backgroundColor=this.clr;
    		obj.style.width=this.width;
    		obj.style.height=this.width;
    	}
    }
    What is so common about common sense?
    -joekarbakuitz

  18. #18
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wait, my bad, I dont want the vertices. I want to change the way the line is drawn.
    What is so common about common sense?
    -joekarbakuitz

  19. #19
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    WHAT the hell are you trying to use a localised
    function with individual variable references for?

    This is EXTERMELY under-used for a very good reason -
    it doesn't work!

    Try using global function references and external
    global lifetlime variables with clear methods rather
    than lexically scoped variables with durable lifetimes
    in order for the namespace to not get over-ridden by
    the same function running a second time.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  20. #20
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im sorry, but either because I am not familiar with javascript enough, or it is too late/early, but I did not get what you meant with the individual variable reference thing.

    This thing isnt really a big enough problem to go into this big discussion about. I would like to have a line made by a starting point and an ending point, but not that much so as to go to all this lengths to figure it out. Besides, all I wanted to know is how to invert the tangent, which would handle all the problems I have so far.
    What is so common about common sense?
    -joekarbakuitz

  21. #21
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    previous explanation simplified:

    don't put a funciton inside a function - Donkey!
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  22. #22
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see why I shouldnt do that, but it works fine for this code so I am not going to worry about it.
    What is so common about common sense?
    -joekarbakuitz


Bookmarks

Posting Permissions

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