 # 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…

`````` ```ruby
code here
then close with ``` on new line
``````

john

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 = Geom::Vector3d.new(1,0,0)
nv = Geom::Vector3d.new(0,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 = Geom::Point3d.new(0,0,0)

pt2 = Geom::Point3d.new(0,0,-15.cm)

pt3 = Geom::Point3d.new(G.m,0,0)

pt4 = Geom::Point3d.new(G.m,0,-15.cm)

pt5 = Geom::Point3d.new(0,0,R.m)

pt6 = Geom::Point3d.new(-Y.m, 0, H.m)

pt7 = Geom::Point3d.new(-(Y+0.05).m, 0, H.m)

pt8 = Geom::Point3d.new(-(Y+0.05).m, 0, -15.cm)

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

``````

``````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:

2 Likes

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.