Author Topic: Math Question With Autocad Drawing Included  (Read 2401 times)

0 Members and 1 Guest are viewing this topic.

Offline lomalena

  • Newbie
  • Posts: 6
    • View Profile
Math Question With Autocad Drawing Included
« on: April 11, 2020, 09:11:42 am »
So, I have R = 3 - Cos (t)  equation.
I want this equation use as a base of a conic
How can I write this?


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Math Question With Autocad Drawing Included
« Reply #1 on: April 11, 2020, 10:06:29 am »
Here are routines for drawing Ellipsii:
https://www.qb64.org/forum/index.php?topic=1069.0


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Math Question With Autocad Drawing Included
« Reply #2 on: April 11, 2020, 11:42:14 am »
Well crap there is no simple ellipsii (though could use CIRCLE with aspect but it sucks) so here is TiltedEllipse simplified to Ellipse with a conic demo:

Code: QB64: [Select]
  1. _TITLE "Ellipsii No Fill" 'b+ 2020-04-11
  2. CONST xmax = 700, ymax = 700
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. _DELAY .25
  5. DIM cx, cy, a, xRad, yRad, p, c~&, mx, my, dist, d
  6.  
  7. cx = xmax / 2: cy = ymax / 2
  8. xRad = 350: yRad = 50: c~& = &HFF0000FF
  9.     CLS
  10.     mx = _MOUSEX: my = _MOUSEY
  11.     dist = ((mx - cx) ^ 2 + (my - cy) ^ 2) ^ .5
  12.     FOR d = 0 TO dist STEP 15
  13.         p = 1 - d / dist
  14.         a = _ATAN2(my - cy, mx - cx)
  15.         Ellipse cx + d * COS(a), cy + d * SIN(a), p * xRad, p * yRad, c~&
  16.         Ellipse cx + d * COS(a), cy + d * SIN(a), p * yRad, p * xRad, &HFFFF0000
  17.     NEXT
  18.     _DISPLAY
  19.     _LIMIT 100
  20.  
  21. 'use this for regular ellipse  
  22. SUB Ellipse (CX, CY, xRadius, yRadius, C AS _UNSIGNED LONG)
  23.     '  CX = center x coordinate
  24.     '  CY = center y coordinate
  25.     '  xRadius = x axis radius
  26.     '  yRadius = y axis radius
  27.     '   C = fill color
  28.     DIM a, x, y, stepper
  29.     stepper = .001 '.025 ain't enough
  30.     FOR a = 0 TO 6.283185307179586 + stepper STEP stepper
  31.         x = CX + xRadius * COS(a)
  32.         y = CY + yRadius * SIN(a)
  33.         IF a <> 0 THEN LINE -(x, y), C ELSE PSET (x, y), C
  34.     NEXT
  35.  
  36.  

   [ You are not allowed to view this attachment ]  
« Last Edit: April 11, 2020, 12:33:53 pm by bplus »

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Math Question With Autocad Drawing Included
« Reply #3 on: April 11, 2020, 11:49:38 am »
Quote
' major and minor axis is misleading as I already told Mr STx as major implies the bigger

say what?
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Math Question With Autocad Drawing Included
« Reply #4 on: April 11, 2020, 11:56:24 am »
say what?

Referring to: https://www.qb64.org/forum/index.php?topic=1069.0

Code: QB64: [Select]
  1. SUB EllipseTilt (CX, CY, a, b, ang, C AS _UNSIGNED LONG)
  2.     '  CX = center x coordinate
  3.     '  CY = center y coordinate
  4.     '   a = semimajor axis  ' <<<<<<<<<<<<<<<<<< I said this is mislabeled
  5.     '   b = semiminor axis  ' <<<<<<<<<<<<<<<<<< I said this is mislabeled
  6.     ' ang = clockwise orientation of semimajor axis in radians (0 default)
  7.     '   C = fill color
  8.     FOR k = 0 TO 6.283185307179586 + .025 STEP .025
  9.         i = a * COS(k) * COS(ang) + b * SIN(k) * SIN(ang)
  10.         j = -a * COS(k) * SIN(ang) + b * SIN(k) * COS(ang)
  11.         i = i + CX
  12.         j = -j + CY
  13.         IF k <> 0 THEN
  14.             LINE -(i, j), C
  15.         ELSE
  16.             PSET (i, j), C
  17.         END IF
  18.     NEXT
  19.  
  20.  

You are using the lousy named "a" variable as x axis radius when angle is 0 and calling it the "major axis" and calling b the y axis radius when ang = 0 the "minor axis", neither one is an axis of the ellipse and Major and Minor axis imply the size and in fact b can be larger than a with the code above.
« Last Edit: April 11, 2020, 12:30:02 pm by bplus »

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Math Question With Autocad Drawing Included
« Reply #5 on: April 11, 2020, 11:57:51 am »
Oh right, this is because I'm one only one here who uses a sensible coordinate system, my mistake.
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Math Question With Autocad Drawing Included
« Reply #6 on: April 11, 2020, 12:02:07 pm »
Oh right, this is because I'm one only one here who uses a sensible coordinate system, my mistake.

No it's not about coordinate system, the major axis of ellipse is the LONGER ONE and the minor axis of an ellipse is the shorter one and the variables a, b as you use them are neither.

https://www.google.com/search?client=opera&q=major+axis+of+an+ellipse&sourceid=opera&ie=UTF-8&oe=UTF-8
« Last Edit: April 11, 2020, 12:03:33 pm by bplus »

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Math Question With Autocad Drawing Included
« Reply #7 on: April 11, 2020, 12:03:51 pm »
I'd say the smarter mathematician wouldn't lock himself in. Variables a and b have complete symmetry in the ellipse. I'm not sure what your complaint is now but honestly I'm not worried about it either. Let me know if you have any other questions about conic sections.

But seriously are you accusing me of calling "b" the semimajor axis? I haven't done that since 2003 and not publicly either.
« Last Edit: April 11, 2020, 12:09:49 pm by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Math Question With Autocad Drawing Included
« Reply #8 on: April 11, 2020, 12:17:25 pm »
I'd say the smarter mathematician wouldn't lock himself in. Variables a and b have complete symmetry in the ellipse. I'm not sure what your complaint is now but honestly I'm not worried about it either. Let me know if you have any other questions about conic sections.

But seriously are you accusing me of calling "b" the semimajor axis? I haven't done that since 2003 and not publicly either.

The a variable effects the spread along the x axis.

The b variable effects the spread along the y axis.

They have no association with Major or Minor axis of Ellipse, not the way they are used in the SUB for drawing the eliipse.
« Last Edit: April 11, 2020, 12:21:04 pm by bplus »

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Math Question With Autocad Drawing Included
« Reply #9 on: April 11, 2020, 12:19:48 pm »
Quote
The a variable effects the spread along the x axis.

The b variable effects the spread along the y axis.

They have no association with Major or Minor axis of Ellipse, not the way they are used in the SUB.

That is pure horse shit, sorry man. If you know you're right and I'm not reading you correctly then just carry on, its all good. All my math works on this end so idk man.
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Math Question With Autocad Drawing Included
« Reply #10 on: April 11, 2020, 12:25:05 pm »
That is pure horse shit, sorry man. If you know you're right and I'm not reading you correctly then just carry on, its all good. All my math works on this end so idk man.

I am talking about how this particular ellipse sub will draw the ellipse not math convention of calling a the major axis and b the minor.

If you want a tall skinny ellipse you better put the bigger length under the b variable.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Math Question With Autocad Drawing Included
« Reply #11 on: April 11, 2020, 01:57:47 pm »
If you want a tall skinny ellipse you better put the bigger length under the b variable.

Oooooooooooooh I get you.

Nah man, that's a feature and nowhere near a bug or anything else. The parameter theta is locked with the "a" variable, even if its smaller. So to modify your statement above, if you want a tall skinny ellipse let a be the bigger side (as usual) and let theta=90 degrees. Good?
« Last Edit: April 11, 2020, 02:07:04 pm by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Math Question With Autocad Drawing Included
« Reply #12 on: April 11, 2020, 02:08:34 pm »
Oooooooooooooh I get you.

Nah man, that's a feature and nowhere near a bug or anything else. The parameter theta is locked with the "a" variable, even if its smaller. So to modify your statement above, if you want a tall skinny ellipse let a be the bigger side (as usual) and let theta=90 degrees. Good?

Yes that will work too.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Math Question With Autocad Drawing Included
« Reply #13 on: April 11, 2020, 03:56:07 pm »
This might be faster ellipse because the loop is much shorter and there is no guessing as to increment steps:
( ie try the EllipseTilt with 400)
Code: QB64: [Select]
  1. _TITLE "Ellipse No Fill" 'b+ 2020-04-11
  2. CONST xmax = 700, ymax = 700
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. _DELAY .25
  5. DIM cx, cy, a, xRad, yRad, p, c~&, mx, my, dist, d
  6.  
  7. cx = xmax / 2: cy = ymax / 2
  8. xRad = 10: yRad = 300: c~& = &HFF0000FF
  9.     CLS
  10.     mx = _MOUSEX: my = _MOUSEY
  11.     dist = ((mx - cx) ^ 2 + (my - cy) ^ 2) ^ .5
  12.     FOR d = 0 TO dist STEP 20
  13.         p = 1 - d / dist
  14.         a = _ATAN2(my - cy, mx - cx)
  15.         Ellipse cx + d * COS(a), cy + d * SIN(a), p * xRad, p * yRad, c~&
  16.         'Ellipse cx + d * COS(a), cy + d * SIN(a), p * yRad, p * xRad, &HFFFF0000
  17.     NEXT
  18.     _DISPLAY
  19.     _LIMIT 100
  20.  
  21.  
  22. 'there is a better way so there is no guessing the stepper size
  23. SUB Ellipse (CX, CY, xRadius AS INTEGER, yRadius AS INTEGER, C AS _UNSIGNED LONG)
  24.     '  CX = center x coordinate
  25.     '  CY = center y coordinate
  26.     '  xRadius = x axis radius
  27.     '  yRadius = y axis radius
  28.     '   C = fill color
  29.     DIM a, x, y, sq, delta, lastDelta
  30.     IF xRadius = 0 AND yRadius = 0 THEN EXIT SUB
  31.     IF xRadius = 0 THEN
  32.         LINE (CX, CY + yRadius)-(CX, CY - yRadius), C
  33.     ELSEIF yRadius = 0 THEN
  34.         LINE (CX + xRadius, CY)-(CX - xRadius, CY), C
  35.     ELSE
  36.         IF xRadius >= yRadius THEN
  37.             a = yRadius / xRadius: sq = xRadius * xRadius
  38.             FOR x = 0 TO xRadius
  39.                 IF x = 0 THEN
  40.                     lastDelta = SQR(sq - x * x) * a
  41.                     PSET (CX + x, CY + lastDelta), C
  42.                     PSET (CX + x, CY - lastDelta), C
  43.                     PSET (CX - x, CY + lastDelta), C
  44.                     PSET (CX - x, CY - lastDelta), C
  45.                 ELSE
  46.                     delta = SQR(sq - x * x) * a
  47.                     LINE (CX + (x - 1), CY + lastDelta)-(CX + x, CY + delta), C
  48.                     LINE (CX + (x - 1), CY - lastDelta)-(CX + x, CY - delta), C
  49.                     LINE (CX - (x - 1), CY + lastDelta)-(CX - x, CY + delta), C
  50.                     LINE (CX - (x - 1), CY - lastDelta)-(CX - x, CY - delta), C
  51.                     lastDelta = delta
  52.                 END IF
  53.             NEXT
  54.         ELSE
  55.             a = xRadius / yRadius: sq = yRadius * yRadius
  56.             FOR y = 0 TO yRadius
  57.                 IF y = 0 THEN
  58.                     lastDelta = SQR(sq - y * y) * a
  59.                     PSET (CX + lastDelta, CY + y), C
  60.                     PSET (CX - lastDelta, CY + y), C
  61.                     PSET (CX + lastDelta, CY - y), C
  62.                     PSET (CX - lastDelta, CY - y), C
  63.                 ELSE
  64.                     delta = SQR(sq - y * y) * a
  65.                     LINE (CX + lastDelta, CY + (y - 1))-(CX + delta, CY + y), C
  66.                     LINE (CX - lastDelta, CY + (y - 1))-(CX - delta, CY + y), C
  67.                     LINE (CX + lastDelta, CY - (y - 1))-(CX + delta, CY - y), C
  68.                     LINE (CX - lastDelta, CY - (y - 1))-(CX - delta, CY - y), C
  69.                     lastDelta = delta
  70.                 END IF
  71.  
  72.             NEXT
  73.         END IF
  74.     END IF
  75.  
  76.  
  77.