1. ## 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. 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

3. 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?

4. What is it you are trying to get the tan OF?!

Flawless

5. 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:

where opposite is the opposite side from the angle and adjacent is the adjacent side from the angle.

6. well just post the relative section then:

Code:
```function test(x){
var tester=1/tan(x)*....
}```

7. 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++;
}

8. 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

9. 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.

10. 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

11. 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.

12. 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

13. 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.

14. 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

15. 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.

16. 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

17. 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;
}
}```

18. wait, my bad, I dont want the vertices. I want to change the way the line is drawn.

19. 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

20. 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.

21. previous explanation simplified:

don't put a funciton inside a function - Donkey!

22. I see why I shouldnt do that, but it works fine for this code so I am not going to worry about it.

#### Posting Permissions

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