Cuve imprecision?

Hi everyone!

I’m writing my first script to be more productive at work, and i’m facing a problem…
( i started programming 2 days ago, so please have mercy! )

Basically the script draw a curve with a given radius + height, and some aditionals line behind.
So far i got the math right, and it draw everything accordingly, except for the arc:

The arc should draw from pt1 to pt6, but it always stop just before this very point (i tried other H and R, nothing changed…)

Is my math wrong? Is this a precision problem from sketchup? Is my code completely out of sight?

thanks a lot!

add your code in a ‘code’ block so it can be viewed properly…

   code here
then close with ``` on new line


As John wrote, please show us your code in a better form than a tiny screenshot. No offense, but my suspicion is that you don’t have the math right!

Oh sorry!

here we go:

model = Sketchup.active_model
entities = model.active_entities

R = 2.2

H = 1.5

G = 0.5

xaxis =,0,0)
nv =,1,0)

X = Math.tan((R-H)/R)
Y = (Math.sqrt ((R**2)-((R-H)**2)))

start_a = Math::PI/2
end_a= -X+Math::PI

pt1 =,0,0)

pt2 =,0,

pt3 =,0,0)

pt4 =,0,

pt5 =,0,R.m)

pt6 =, 0, H.m)

pt7 =, 0, H.m)

pt8 =, 0,

entities.add_line pt1, pt2
entities.add_cline pt3, pt4
entities.add_line pt6, pt7
entities.add_line pt7, pt8
entities.add_line pt8, pt2

entities.add_arc pt5, xaxis, nv, R.m, start_a, end_a, 36 

Your math mistake is here:

X = Math.tan((R-H)/R)

It is a two-issue mistake! First of all, tan takes an angle as argument and returns a value. Second, those are the wrong sides of the triangle anyway!

It should be:

X = Math.atan((r-h)/y)

Then the arc lands just fine:


Avoid capital letters for ‘variables’ - Ruby sees these as Constants and although you can reset them, it will generate an unnecessary output: so r rather than R etc…

The swept angle between the start_point vertical radius [from the center to the start] and the end_point of the arc is something like:
ang = Math.acos( (r - h) / r )
add/subtract that from the start_angle of -90.degrees

Welp, sounds like i should get back to my math first eheh,

Slbaumbgartner 's solution work like a charm, thanks a lot!

I feel like i went too fast into the script, i’ll slow down a bit to focus more on the language itself.
Ty TIG for the advice!