Qbasicnews.com

Full Version: Pivot Point
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
[Image: DIAGRAM.gif]

How would i ahev line 'A' pivot on point 'B' to touch semicircle 'C'?
for loop use cirlce with radians. or draw part of a circle with cos and sin
Quote:for loop use cirlce with radians. or draw part of a circle with cos and sin
huh?
Code:
pi! = atn(1) * 4
cx! = 160 ' Center X
cy! = 100 ' Center Y
r! = 20 ' Radius
angle! = 180
theta! = angle! * pi! / 180

LINE (cx, cy)-(cos(theta!) * r! + cx!, sin(theta!) * r! + cy!)
in general:

when you have a radian (angle from 0 to the circumferance of a unit circle, a unit circle having a radius of one, 2 * pi), a cosine (cos) returns the x length of a line in that direction with a lenght of 1. the sine (sin) returns the y height of that line. So if you multiply that figure by the radius, you will get the x and y components for a line of r length (r being the radius).

oh yeah, and for pivoting, just thange angle!, which goes from 0 to 359 (starting from the right and going counter clockwise). Making this value higher will make the line move counter clockwise.
thanks Smile
if you dint get that this may help
Code:
SCREEN 13
CONST rad = (3.141592654# / 180)
FOR i = 0 TO 360
x = (COS(i * rad) * 10) + 100
y = (SIN(i * rad) * 10) + 100
LINE (100, 100)-(x, y), 15
NEXT
That example will draw a large amount of lines from (100,100) to a point on the circle.

Let's see:
Code:
'$DYNAMIC
DEFINT A-Z

SCREEN 13

' this draws:
'- Line B
'- Semicircle C
' r^2=x^2 + y^2
' r=50
' y = SQR(r^2-x^2)
oldY = 0
height = 0
FOR x = -50 TO 50
   y = -INT(SQR(r^2-x^2))
   IF x = 0 THEN height = y
   IF x > -50 THEN LINE (x - 1 + 160, oldY + 100) - (x + 160, y + 100), 1
   oldY = y
NEXT x
LINE (110,100)-(210,100), 2

' this draws:
'- Line A pivot on Line B and touching C
LINE (160,100)-(160,100+height), 3

Done by heart, hope there aren't any bugs in it. And I hope you can do something with it! Wink